> 1
> InputAll
>> ∪2
>> #2
>> #3
>> 4÷5
>> ⌊6⌋
>> L⋅7
>> Each 8 3
>> 9ᴺ
>> 2ᴺ
>> 10=11
>> 6>1
>> 12⋅13
>> Output 14
###########################00000000000000000000000000001111111111111111111112222222222222222222222222333333333333333333333333334444444444444444444444444445555555555555555555555555555666666666666666666666666666777777777777777777777777777788888888888888888888888888889999999999999999999999999999============================AAAAAAAAAAAAAAAAAAAAAAAAAAAAEEEEEEEEEEEEEEEEEEEEEEEEEEEEIIIIIIIIIIIIIIIIIIIIIIIIIIIILLLLLLLLLLLLLLLLLLLLLLLLLLLLOOOOOOOOOOOOOOOOOOOOOOOOOOOOaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccchhhhhhhhhhhhhhhhhhhhhhhhhhhhlllllllllllllllllllllllllllnnnnnnnnnnnnnnnnnnnnnnnnnnnnpppppppppppppppppppppppppppttttttttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuuuuuu÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺ∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋
Try it online!
* Golfs made while explaining it. You can see the original here
Interesting task, fairly boring restriction.
Unfortunately, due to the fact that every line must start with either >>
or >
, this forces the number of each character to be disproportionately large. Luckily, Whispers ignores every line that doesn't match one of its regexes, all of which require the line to begin with >
. Therefore we just have a large character dump at the end of the program. In addition to this, Whispers, being designed for mathematical operations, struggles when applied to a array-manipulation question. Overall, this means that the task is interesting to attempt, but the source code requirements are a bit boring.
If we strip all the unnecessary characters from the program, we end up with
> 1
> InputAll
>> ∪2
>> #2
>> #3
>> 4÷5
>> ⌊6⌋
>> L⋅7
>> Each 8 3
>> 9ᴺ
>> 2ᴺ
>> 10=11
>> 6>1
>> 12⋅13
>> Output 14
Try it online!
which is the part of the code we're actually interested in.
How that works
Here we conduct two key tests: the count of each is the same and the counts are greater than 1. However, the code for these two tests are shared between them, so a complete walkthrough of the program is a more effective method of explaining this.
We start with the shared code:
> InputAll
>> ∪2
>> #2
>> #3
>> 4÷5
Here, we take the input and store it on line 2 (> InputAll
). We then create a ∪
nique version of that string (i.e. the input without duplicate characters). With our next two lines, we take the length of the untouched input (>> #2
) and the number of unique characters in the input (>> #3
). Finally, we divide the former by the latter.
Why? Let's have a look at the two inputs of aabbcc
and abbaabb
. With the first string, the division becomes 6÷3 = 2, and the second results in 7÷2 = 3.5. For non-discriminating strings, the result of this division is a) An integer and b) Greater than 1. Unfortunately, this also applies to some non-discriminating strings, such as abbccc
, so we have to perform one more test.
>> ⌊6⌋
>> L⋅7
>> Each 8 3
>> 9ᴺ
>> 2ᴺ
>> 10=11
Note: line 6 is the result of the division.
First, we take the floor of the division, because Python strings cannot be repeated a float number of times. Then we reach our Each
statement:
>> L⋅7
>> Each 8 3
3 is a reference to line 3, which contains our deduplicated input characters, so we map line 8 (>> L⋅7
) over this list. Line 8 multiplies the character being iterated over by the floor of our division (>> ⌊6⌋
). This creates an array of the deduplicated characters, repeated n times.
The results from our two previous strings, aabbcc
and abbaabb
, along with abcabc
, would be aabbcc
, aaabbb
and aabbcc
respectively. We can see that the first and last two are identical to their inputs, just with the letters shuffled around, whereas the middle one isn't (it has one less b
). Therefore, we simply sort both the input and this new string, before comparing for equality:
>> 9ᴺ
>> 2ᴺ
>> 10=11
Finally, we need to check that the number of characters in the string is 2 or greater. Luckily, the division we performed earlier will always result in a value greater than 1 if a character repeats more than once, meaning we just need to assert that line 6 is greater than 1:
>> 6>1
Now we have two booleans, one for each test. They both need to be true, so we perform a logical AND (boolean multiplication) with >> 12⋅13
, before finally outputting the final result.