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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
3🍬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πŸ‘»56

However, with your unique Ouija board you should have no problem deciphering what they left!

Objective

Your Ouija board looks like the following straddling checkerboard:

1
2
3
4
5
6
7
8
==================================
|    | 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
" 0123456\n SCARY?!\nπŸŽƒBDEFGH \nπŸ‘»IJKLMN'\n🍬OPQTUV,\nπŸ’€WXZ.\#$:".split(?\n).map(&:chars).tap{|b|<<M.chars.reduce(nil){|r,e|e==?\n?print(e): r ?print(b[r][b[0].index e]): b.index{_1[0]==e}||print(b[1][b[0].index e])}}
3🍬4πŸŽƒ04...
M

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
board = [' ', '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', '.', '#', '$', ':']
message = <<MESSAGE
3🍬4πŸŽƒ04...
MESSAGE

message.chars.reduce nil do |row, encoded_char|
	if encoded_char == ?\n # newline in the message
		print encoded_char
	elsif row # last char is an emoji, corresponding to a row in the board
		print board[row][board[0].index encoded_char]
		nil
	elsif new_row = board.index { _1[0] == encoded_char }
		new_row
	else
		print board[1][board[0].index encoded_char]
		nil
	end
end

Then, I realized that I could have used regular expressions, so I wrote a cleaner version:

1
2
3
puts <<M.gsub(/([πŸŽƒπŸ‘»πŸ¬πŸ’€])?([0-6])/){|s|{nil=>'SCARY?!',πŸŽƒ:'BDEFGH ',πŸ‘»:"IJKLMN'",🍬:'OPQTUV,',πŸ’€:'WXZ.#$:'}[$1&.to_sym][$2.to_i]}
3🍬4πŸŽƒ04...
M

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
#!/usr/bin/env ruby -p
gsub(/(\D?)(\d)/){'SCARY?!πŸŽƒBDEFGH πŸ‘»IJKLMN\'🍬OPQTUV,πŸ’€WXZ.#$:'[/#$1.{#$2}(.)/,1]}

Here are some other solutions. Check them out!

Some explanations for the code golf solution

  • The -p option basically wraps the code in a while gets loop, and you can access the current line with $_. Ruby will output the contents of $_ after each iteration.
  • The method Kernel#gsub modifies $_ (the current processing input line). It is only available when running Ruby with -p option.
  • 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_variable as 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
RUBY IS A LANGUAGE THAT WE PROGRAMMERS ADORE,
UNLEASHING MAGIC SPELLS WITHIN ITS CODE GALORE.
BENEATH THE HAUNTED MOON, ITS SYNTAX WE EXPLORE,
YET IN THE WORLD OF PROGRAMMING, IT THRIVES EVEN MORE.

IN THE CRYPTIC METHODS, WHERE EERIE BUGS MAY TREAD,
SKELETONS OF ERRORS IN THE DARK ARE WIDESPREAD.

NOT A LANGUAGE OF THE PAST, BUT ONE WE HOLD OUR HEADS,
OVER COUNTLESS PROJECTS, WHERE ITS POWER HAS SPREAD.
THE TRICKS AND TREATS OF RUBY, LIKE WITCHES' CHARMS, CONVENE,

DRAWING US INTO ITS WORLD, WHERE THE SUBLIME IS SEEN.
ENCHANTING US WITH GEMS, IT'S EVERY CODER'S DREAM,
ADVENTURES IN THE CODE, WHERE THE EERIE'S ROUTINE.
DEATH MAY SEEM TO LURK, BUT FOR RUBY IT'S HALLOWEEN!

Did you spot the hidden message?