41
3
This is my first challenge on ppcg!
Input
A string consisting of two different ascii characters. For example
ABAABBAAAAAABBAAABAABBAABA
Challenge
The task is to decode this string following these rules:
- Skip the first two characters
- Split the rest of the string into groups of 8 characters
- In each group, replace each character with
0
if that character is the same as the first character of the original string, and with1
otherwise - Now each group represents a byte. Convert each group to character from byte char code
- Concatenate all characters
Example
Let's decode the above string.
AB AABBAAAA AABBAAAB AABBAABA
^^ ^ ^ ^
| | | |
| \---------|---------/
| |
Skip Convert to binary
Notice that A
is the first character in the original string and B
is the second. Therefore, replace each A
with 0
and each B
with 1
. Now we obtain:
00110000 00110001 00110010
which is [0x30, 0x31, 0x32]
in binary. These values represent characters ["0", "1", "2"]
respectively, so the final output should be 012
.
Scoring
This is, of course, code-golf, which means make your code as short as possible. Score is measured in bytes.
Constraints and IO format
Standard rules apply. Here are some additional rules:
- You can assume valid input
- Input string consists of exactly two different characters
- The first two characters are different
- The minimal length of the input string is 2 characters
- The length will always give 2 modulo 8
- You can assume the string will always consist only of printable ASCII characters
- Both in the input and in the decoded string
- Leading and trailing whitespace are allowed in the output (everything that matches
/\s*/
)
5
Gotta say man, for a first challenge, this is one of the better formatted challenges I've ever seen. As an fyi, the community sandbox is a great place for feedback before posting so you don't get randomly rep bombed for a rule you didn't know.
– Magic Octopus Urn – 2018-04-23T00:16:39.153@MagicOctopusUrn. Thank you! Didn't know about sandbox, I'll post there next time :) – None – 2018-04-23T00:18:03.687
2I mostly use it so people can call me out on duplicate questions, very simple to follow rules, rather hard to know about dupes without memorizing meta :). I'd also recommend checking out the chatrooms, we have chats for almost every language you could hope to learn and questions are encouraged. – Magic Octopus Urn – 2018-04-23T00:18:28.853
1Great first challenge! Some more test cases would be neat. – Lynn – 2018-04-23T16:33:29.620
Really nice first challenge. Had fun playing with this one. – ElPedro – 2018-04-23T19:18:23.657