Sha256: fb3f34615f9bb4560dcb0cb4ae86b6c42681b00fa62e7c9dc12edd623211e081

Contents?: true

Size: 496 Bytes

Versions: 396

Compression:

Stored size: 496 Bytes

Contents

class SecretHandshake
  attr_reader :digits
  def initialize(decimal)
    @digits = decimal.to_s(2).reverse.chars.collect(&:to_i)
  rescue ArgumentError
    @digits = 0
  end

  def commands
    handshake = []
    (0..3).each do |index|
      if digits[index] == 1
        handshake << signals[index]
      end
    end
    if digits[4] == 1
      handshake.reverse
    else
      handshake
    end
  end

  private

  def signals
    ['wink', 'double blink', 'close your eyes', 'jump']
  end
end

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.138 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.137 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.136 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.135 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.134 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.133 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.132 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.131 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.130 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.129 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.128 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.127 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.126 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.125 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.124 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.123 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.122 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.121 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb
trackler-2.2.1.120 tracks/ruby/exercises/secret-handshake/.meta/solutions/secret_handshake.rb