Created
October 11, 2013 15:49
-
-
Save TrevMcKendrick/6937134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Binary Secret Handshake | |
# > There are 10 types of people in the world: Those who understand binary, and those who don't. | |
# You and your fellow flatirons are of those in the "know" when it comes to binary decide to come up with a secret "handshake". | |
# ``` | |
# 1 = wink | |
# 10 = double blink | |
# 100 = close your eyes | |
# 1000 = jump | |
# 10000 = Reverse the order of the operations in the secret handshake. | |
# ``` | |
# Write a program that will convert a binary number, represented as a string (i.e. "101010"), and convert it to the appropriate sequence of events for a secret handshake. | |
# ``` | |
# handshake = SecretHandshake.new "1001" | |
# handshake.commands # => ["wink","jump"] | |
# handshake = SecretHandshake.new "11001" | |
# handshake.commands # => ["jump","wink"] | |
# ``` | |
# The program should consider strings specifying an invalid binary as the value 0. | |
class SecretHandshake < String | |
attr_accessor :binary, :handshake | |
def initialize(binary) | |
@handshake = [] | |
@binary = binary.scan(/\w/).reverse | |
end | |
def commands | |
self.handshake << "wink" if self.binary[0] == "1" | |
self.handshake << "double blink" if self.binary[1] == "1" | |
self.handshake << "close your eyes" if self.binary[2] == "1" | |
self.handshake << "jump" if self.binary[3] == "1" | |
self.handshake.reverse! if self.binary[4] == "1" | |
self.handshake | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment