Skip to content

Instantly share code, notes, and snippets.

@aviflombaum
Last active December 19, 2015 00:09
Show Gist options
  • Save aviflombaum/74aa528082666c33699d to your computer and use it in GitHub Desktop.
Save aviflombaum/74aa528082666c33699d to your computer and use it in GitHub Desktop.

Binary Secret Handshake

There are 10 types of people in the world: Those who understand binary, and those who don't.

Flatiron is 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.

Tests are provided.

require 'fis/test'
test 'handshake 1 to wink' do
handshake = SecretHandshake.new("1")
assert_equal ["wink"], handshake.commands
end
test 'handshake 10 to double blink' do
handshake = SecretHandshake.new("10")
assert_equal ["double blink"], handshake.commands
end
test 'handshake 100 to close your eyes' do
handshake = SecretHandshake.new("100")
assert_equal ["close your eyes"], handshake.commands
end
test 'handshake 1000 to jump' do
handshake = SecretHandshake.new("1000")
assert_equal ["jump"], handshake.commands
end
test 'handshake 11 to wink and double blink' do
handshake = SecretHandshake.new("11")
assert_equal ["wink","double blink"], handshake.commands
end
test 'handshake 10011 to double blink and wink' do
handshake = SecretHandshake.new("10011")
assert_equal ["double blink","wink"], handshake.commands
end
test 'handshake 11111 to double blink and wink' do
handshake = SecretHandshake.new("11111")
assert_equal ["jump","close your eyes","double blink","wink"], handshake.commands
end
test 'invalid handshake' do
handshake = SecretHandshake.new("piggies")
assert_equal [], handshake.commands
end
@carlosplusplus
Copy link

As written, the test bench doesn't work. <sad_panda>
You need to wrap your tests in a class and extend the module, like this:

class HandshakeTests
  extend Fis::Test

  #Tests go here.

end

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