Skip to content

Instantly share code, notes, and snippets.

@wb4r
Created September 26, 2015 09:14
Show Gist options
  • Save wb4r/94089b89cb8a7b9c3628 to your computer and use it in GitHub Desktop.
Save wb4r/94089b89cb8a7b9c3628 to your computer and use it in GitHub Desktop.
class SecretHandshake
def initialize(input)
@data = input
@solution = []
end
def commands
unless @data.to_i == 0
@data = @data.to_s(2)
end
@data = @data.chars.reverse!
position_of_ones = get_array_with_position_of_ones
extract_handshakes(position_of_ones)
reverse?
@solution
end
private
def extract_handshakes(position_of_ones)
position_of_ones.each do |x|
if x == 0
@solution << "wink"
end
if x == 1
@solution << "double blink"
end
if x == 2
@solution << "close your eyes"
end
if x == 3
@solution << "jump"
end
end
end
def get_array_with_position_of_ones
position_of_ones = []
@data.each_with_index do |i, x|
if i == "1"
position_of_ones << x
end
end
position_of_ones
end
def reverse?
if @data.length > 4
@solution.reverse!
end
end
end
@wb4r
Copy link
Author

wb4r commented Sep 26, 2015

Handshake Exercise for TeaLeaf Academy - Willem Toledano 26th Sept 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment