An π easy π» but π¬ spooky π Ruby challenge
This was a challenge in the Ruby Discord server. The contents of the challenge is:Β©
Halloween Challenge
Itβs the weekend and youβve just completed a seance with friends. After communing with the dead, you realize a mysterious message was left behind.
123456789101112131415163π¬4π04π6π»00π62π6π»32π»5π4π¬42π4π2π6π¬3π52π¬3π6π0π2π6π¬13π¬0π432π»4π»4π230π62π1π¬03π2π¬6 π¬4π»5π»3π220π5π»0π»5π4π6π»42π4π»01π60π¬1π2π»3π»30π6π0π»0π¬3π5π»0π»5π6π»0π¬30π61π¬0π1π2π6π42π»3π¬03π2π3 π0π2π»5π22π¬3π5π6π¬3π5π2π6π52π¬4π»5π¬3π2π1π6π»4π¬0π¬0π»5π¬6π6π»0π¬30π604π»5π¬32π1π6π0π2π6π2π1π¬1π»3π¬03π2π¬6 4π2π¬3π6π»0π»5π6π¬3π5π2π6π0π¬03π»3π1π6π¬0π3π6π¬13π¬0π432π»4π»4π»0π»5π4π¬6π6π»0π¬3π6π¬3π53π»0π¬5π20π6π2π¬5π2π»5π6π»4π¬03π2π3 π»0π»5π6π¬3π5π2π6134π¬1π¬3π»01π6π»4π2π¬3π5π¬0π10π¬6π6π0π5π23π2π6π2π23π»0π2π6π0π¬4π40π6π»424π6π¬33π22π1π¬6 0π»2π2π»3π2π¬3π¬0π»50π6π¬0π3π6π233π¬030π6π»0π»5π6π¬3π5π2π6π123π»2π623π2π6π0π»0π1π20π¬13π22π1π3 π»5π¬0π¬3π62π6π»32π»5π4π¬42π4π2π6π¬0π3π6π¬3π5π2π6π¬120π¬3π¬6π6π0π¬4π¬3π6π¬0π»5π2π6π0π2π6π5π¬0π»3π1π6π¬0π¬43π6π5π22π10π¬6 π¬0π¬5π23π61π¬0π¬4π»5π¬3π»3π200π6π¬13π¬0π»1π21π¬30π¬6π6π0π5π23π2π6π»0π¬30π6π¬1π¬0π0π23π6π520π60π¬13π22π1π3 π¬3π5π2π6π¬33π»01π»20π62π»5π1π6π¬33π22π¬30π6π¬0π3π63π¬4π04π¬6π6π»3π»0π»2π2π6π0π»0π¬31π5π20π»6π61π523π»40π¬6π61π¬0π»5π¬5π2π»5π2π¬6 π132π0π»0π»5π4π6π¬40π6π»0π»5π¬3π¬0π6π»0π¬30π6π0π¬03π»3π1π¬6π6π0π5π23π2π6π¬3π5π2π60π¬4π0π»3π»0π»4π2π6π»00π60π2π2π»5π3 π2π»51π52π»5π¬3π»0π»5π4π6π¬40π6π0π»0π¬3π5π6π4π2π»40π¬6π6π»0π¬3π»60π6π2π¬5π234π61π¬0π1π23π»60π6π13π22π»4π¬6 2π1π¬5π2π»5π¬3π¬43π20π6π»0π»5π6π¬3π5π2π61π¬0π1π2π¬6π6π0π5π23π2π6π¬3π5π2π6π2π23π»0π2π»60π63π¬0π¬4π¬3π»0π»5π2π3 π1π22π¬3π5π6π»424π60π2π2π»4π6π¬3π¬0π6π»3π¬43π»2π¬6π6π0π¬4π¬3π6π3π¬03π63π¬4π04π6π»0π¬3π»60π6π52π»3π»3π¬0π0π2π2π»56However, with your unique Ouija board you should have no problem deciphering what they left!
Objective
Your Ouija board looks like the following straddling checkerboard:
12345678================================== | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | | | S | C | A | R | Y | ? | ! | | π | B | D | E | F | G | H | | | π» | I | J | K | L | M | N | ' | | π¬ | O | P | Q | T | U | V | , | | π | W | X | Z | . | # | $ | : | ==================================Use your Ruby skills and the board above to decrypt the message. I have attached a file to help get you started. You donβt need to use it if you donβt want to.
You may also find this link helpful too.
Requirements
- Must use Ruby
- Decrypt the message
- Determine the hidden message within the decrypted message
My solution
I am too stupid to think of regular expressions at first, so I wrote this:
1
2
3
|
|
I did not want to code golf, but I did intend to wrote a one-liner. It seems hard to understand, but it is pretty straightforward if it is expanded:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
|
Then, I realized that I could have used regular expressions, so I wrote a cleaner version:
1
2
3
|
|
Then, I suddenly become creative and realized that I can use another regular expression to implement a string-based indexing, and that I can use -p option of Ruby command line to save even more characters (here I smelled code golfing):
1
2
|
|
Here are some other solutions. Check them out!
Some explanations for the code golf solution
- The
-poption basically wraps the code in awhile getsloop, and you can access the current line with$_. Ruby will output the contents of$_after each iteration. - The method
Kernel#gsubmodifies$_(the current processing input line). It is only available when running Ruby with-poption. - The method
String#[]returns a substring. What is good about this method is that, if you use a regular expression to find the substring, you can use the second argument to specify which capture group in the regular expression you want to return. - In a string literal, you can use
#$some_global_variableas a shortcut of#{$some_global_variable}. This is also true for instance variables and class variables.
The message
The decoded message is:Β©
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
|
Did you spot the hidden message?