Power of Thor - Codesize - Puzzle discussion

In C (and in bash, I tried some constructs and ended with a solution that I thought correct but of which the interpreter is not happy. It gives the following error:
Expected a movement (one of N, NE, E, SE, S, SW, W, NW) but found ‘W’

Is that strange or did I miss smthg ?

check for blank characters and special characters like \b \t \a etc

I’m becoming crazy, can’t go under 181 in c++. At least I learnt some tweaks :slight_smile:
Did you change the basic algo to lower the size?

C++ is hard try C

try ternary operator ? : instead of if else

any hints for the c-version to cut the size down? I’m at 191 for c++, but out of ideas without hardcoded stuff… ternary was a nice tip! currently cin take much characters, but I have no idea how to shorten that.

  • C is shorter than C++
  • put all code in 1 line
  • avoid { and use , to separate the commands
  • use the for(;:wink: and include commands inside it to save some ;
  • maybe #define

I reached down to 178 in C++, but that’s how far it goes.
Even by omiting the part for walking north, I would lose only ten additional characters.
I wonder how some got less than 100

Hard-coding.

Hardcoding, yes, but creative hard coding.

1 Like

I got down to 115 in C by omitting North, but not hard coding. Tried to hard code but still no better than 112. arrrgh!

1 Like

Did you find a solution for this? I’m struggling with the same problem

I am totally baffled as to how people are solving this with under 100 characters…is there some trick to this algo that I am missing?

The test coverage is poor, so they hardcode solutions.

1 Like

148 in c++ , no hard coding, i really don’t know how to get less :-/

I have a non-hardcoded 79 chars solution in Ruby. I had to hardcode to go below.

my code size is 153, Java

You can increment the variable in the output with ++ operator.
In my code I have only the output in the for loop, this way you can leave the curly brackets too.

Hard coded 158 in Java. But I honestly have no idea how to get it done in less characters - and the best one in Java is at only 138. Plopx, please share your wisdom! :wink:

2 Likes

Hard coded 98 in C, with some tricks like getting the getchar()%9 to avoid comparing with two digit numbers, or testing a-x instead of a!=x, but blocked now… I think puts() is not right as it requiered two ", but no ideas on how to go shorter.