Clash of Code short code mode

Hello everyone,

I’ve just completed a Clash of code, shortest code mode. The goal was to sum up all the alphabetical indexes from the word given as input.
I end up with the following ruby solution (34 chars).
p gets.upcase.chars.sum{_1.ord-64}

Another guy completed the challenge with only 23 characters, in ruby as well. Unfortunately, he didn’t revealed his code.
Anyone has any idea of what kind of hack did he used to have such a small code?

Thanks

Not sure how to get 23 chars, but you can squeeze code to 25 by using String#sum to get sum of bytes in string and ~/$/ for the string length.

1 Like

I don’t know Ruby, but using modulo 32 you can avoid the case conversion and the subtraction of 64.

2 Likes

Thanks for the hint. I think that’s the trick: p gets.bytes.sum{_1%32} (=> 23 chars)

1 Like