The simple part: Given an input string containing only printable ASCII-characters (space - tilde), count the number of occurrences of each character and return the result on any convenient format. The result for a string a%hda7a
should be something like: a:3, %:1, h:1, 7:1, d:1
. Sorting is unnecessary, the delimiters and formats are optional but it must be easily understood which number corresponds to which character. You shall not include characters that are not in the input string (a:3, b:0, c:0, d:1, ...
is not OK).
The real challenge:
Convert every character in your code to an 8-bit binary number (or 16-bit if you're using UTF-16 or similar), and enumerate every character starting at 0
.
For every character (i
is the enumerator), the i%7
-bit1 must be 1
. The bits are numbered from the right. All other bits can be whatever you want.
Let's use the following code as an example:
[f]-xif)#f
Converting this to binary we get the array below. The first number (representing [
has a 1
in the 0'th position, so that one is OK. The second number (representing f
has a 1
in the 1'st position, so that one is OK too. Continue like this, and you'll see that the code above is valid.
C 76543210 Bit number - -------- ---------- [ 01011011 0 - OK f 01100110 1 - OK ] 01011101 2 - OK - 00101101 3 - OK x 01111000 4 - OK i 01101001 5 - OK f 01100110 6 - OK ) 00101001 0 - OK # 00100011 1 - OK f 01100110 2 - OK
If we change the code into: ]f[-xif)#f
we'll get the following start of the sequence:
C 76543210 Bit number
- -------- ----------
] 01011101 0 <- OK
f 01100110 1 <- OK
[ 01011011 2 <- Not OK
- 00101101 3 <- OK
As we see, the third character [
doesn't have a 1
in the 2nd position (zero-indexed), and this code is therefore not valid.
Test cases:
Input:
This is a string containing some symbols: ".#!".#&/#
Output:
! " # & / : T a b c e g h i l m n o r s t y .
7 1 2 3 1 1 1 1 2 1 1 1 2 1 5 1 2 4 3 1 6 2 1 2
Any reasonable output format is OK (whatever is most convenient to you). You could for instance have: :7, !:1, ":2, #:3, &:1, /:1, T:1, a:2 ...
or [ ,7][!,1][",2][#,3][&,1]...
. The output is on any standard way (return from function, printed to STDOUT etc.)
1i
modulus 7
.
This is code-golf, so the shortest code in bytes will winref.
n%7
th spot > pastie.org/pastes/10985263/text \$\endgroup\$00001010
. It can be useful too! :) \$\endgroup\$