> InputAll
> 2
>> ?L
>> L⊥2
>> ∑L
>> Each 3 1
>> Each 4 6
>> Each 5 7
>> ∑8
>> Output 9
> "test"
>> 1=11
> 0
>> Output 13
>> If 12 14 10
Try it online!
Unfortunately, we are sort of bound to have a high score when using Whispers for this task, as the key character is >
, which has a score of 5. Aside from using "
instead of '
quotes, there isn't really much room for improvement without totally rewriting the method used. Using digits which score lower (01248
) rather than the higher scoring ones (35679
) doesn't allow us to improve, as no high-scoring single digit is repeated (3
occurs more than once, but restructuring doesn't allow us to change the 13
to something lower scoring)
Anyway, the way the program works is fairly understandable, especially for those familiar with Whispers. Our first thing to hold in mind is that 1 is the line reference for the input string. We begin on the last line, with the ternary statement
>> If 12 14 10
The thing to remember with Whispers is that, when a line begins with two >
symbols, the numbers act as line references, rather than literal values. That makes this statement equivalent to
If line(12) Then line(14) Else line(10)
Lines 11 and 12, our condition, is
> "test"
>> 1=11
Remembering that line 1 is the input string, this compares the input with the string "test"
and returns that boolean.
Our program then branches. First, as it's simpler, we'll take a look at the code executed if the input is the string "test"
:
> 0 ; line 13
>> Output 13 ; line 14
>> If 12 14 10
If so, we call line 14, which as you can see, outputs the value on line 13, a 0. Therfore, if the input is equal to the string "test"
, we output a 0, then quit.
However, if the input does not equal the string, we jump up to line 10. Lines 9 and 10 are as follows:
>> ∑8
>> Output 9
So, if the input isn't in test mode, we output the sum of the result from line 8, which is the final Each
statement in a series of three:
> InputAll
> 2
>> ?L
>> L⊥2
>> ∑L
>> Each 3 1
>> Each 4 6
>> Each 5 7
Our first Each
statement is >> Each 3 1
. This maps line 3 over each character in the input. Line 3, >> ?L
, takes the currently iterated character and converts it to its ordinal value. This value is then passed to line 7, which converts it to base 2, before line 8 takes the sum of that (the number of 1s in the binary expansion). This returns an array of integers, representing the number of 1s in the binary expansion of each ordinal of each character in the input. As stated above, we then take the sum of this, before outputting it and terminating.
Fun fact:
- The markdown of this post is functionally identical to the program
- This post has a score of 11125
\x7F}~_?{ow7yvu/s\x1F;=znm>k|OW[]^gc\x1Ex\x1D\eef\\'ZY+-VU.St\x173iNM5K6r\x0FG9:q<ljQ\x15\x13pC\aEF8IJL4\x0E21\x16RTh,X*)\x19\v&%\x1A#d\x1C\rab`!\"$(\x180\x05A\x14B\x12\x11DHP\x03\f\x06\n\t\x80\x10\x01@\x04\b\x02 \x00
\$\endgroup\$