Feedback on my first Clash of Code submission please :)


I’ve just finished my first submission and was wondering if anyone would be kind enough to give me feedback on it? I’m concerned that it may be too complicated for a clash but if anyone could try it and see i’d appreciate it!


You are supposed to read all that and write 70 lines of code in 5 minutes?

If you count real lines in the solution there are 40 which is longer than a typical clash but still doable in 5 min if the task is straightforward enough.

What concerns me more is the wording of the problem, you want to be as precise as possible, I’m afraid that ‘continue backward’, ‘repeat’, ‘count’ can be interpreted different ways.
Would be easier if you explain these steps on an example.

Ok, thanks for the feedback, i’ll make some changes

Change each char of the input string s to unicode.

This statement in your submission is inaccurate. You may have wrongly used the word “unicode”.

Usually I should write comments in your contribution rather than in the forum. But for this case I feel it is general enough to be shared here.

If you mean changing character ‘A’ into decimal 65 or Hex 41, this procedure is more commonly referred to as “change character to ASCII code”.

In contrast with what is Unicode…

Unicode is an umbrella including many encoding methods. Two common ones are UTF-8 and UTF-16.

  • To encode ‘A’ into UTF-8, its underlying code is Hex 41 (same as ASCII).
  • Its UTF16 Little-endian value is Hex 0041.
  • Its UTF16 Big-endian value is Hex 4100

so we often have to specify the encoding standard when we refer anything as “Unicode”. Missing this info it is more likely to mean dealing with characters above the ASCII code page (e.g. CJK characters) and encoded in UTF-8.

Yeah, I didn’t really understand that before but I’ve changed it now to ASCII and rewritten the code and description so it should be simpler to complete and easier to understand

To much text for a Clash…

It seems like the problem itself is fine for a clash, its just that the description is a little off. First of all, you have a constraint that n is a non-zero int, and then you make everyone test for n==0 and print invalid. Either have the test or the constraint, I would say just the constraint and get rid of the whole invalid check. It’s only 1 extra line of code, and adds nothing to the problem.

For your decryption algorithm, you have obfuscated it so much, and it is ridiculous. Why say ‘add the difference to 31’ instead of just saying subtract 95. Same thing for the even indexes, if its less than 32, add 95.

I would change the goal to something like this:
Your goal is to decrypt an encrypted message.

For each encrypted character:
Convert it to its ASCII decimal value
If its index in s is even: subtract n from its ASCII value, then add 95 until it is above 31
If its index in s is odd: add n to its ASCII value, then subtract 95 until it is less than 127
Convert back to the character

Hopefully with the reworded goal it will be easier for people to realize it is just a Caesar shift in a different direction for each index. For those saying it takes like 40 lines, this is the python solution, and if he removes the erroneous invalid n check, would be under 10 lines

s = input()
n = int(input())
if n==0: raise IndexError
out = ‘’
for i in range(len(s)):
letter = ord(s[i]) - [n,-n][i%2]
while not 31<letter<127: letter += [95,-95][i%2]
out += chr(letter)

Bit of a derp moment but I didn’t consider the +/- 95 option. I’ve updated it now and there is no longer the encryption part of the puzzle, so hopefully it’s easier to understand (and complete) now.