I hereby claim:
- I am seanhandley on github.
- I am seanhandley (https://keybase.io/seanhandley) on keybase.
- I have a public key whose fingerprint is 9685 2CA9 5B02 1A6F 9DB4 73FC 42C5 9834 59D4 0286
To claim this, I am signing this object:
nationalities = [:german, :swedish, :british, :norwegian, :danish] | |
nationalities[0] == :norwegian | |
# => false | |
drinks = [:beer, :water, :milk, :coffee, :tea] | |
drinks[2] == :milk | |
# => true |
def left_of?(set_a, val_a, set_b, val_b) | |
(0..4).any? do |i| | |
set_a[i] == val_a && | |
set_b[i+1] == val_b | |
end | |
end | |
# Instead of defining a right_of?, we can just swap the values we input to left_of? | |
def next_to?(set_a, val_a, set_b, val_b) |
def left_of?(set_a, val_a, set_b, val_b) | |
(0..4).any? do |i| | |
set_a[i] == val_a && | |
set_b[i+1] == val_b | |
end | |
end | |
colors = [:white, :yellow, :blue, :red, :green] | |
left_of?(colors, :green, colors, :white) |
implies?(nationalities, :british, colors, :red) | |
implies?(nationalities, :swedish, pets, :dogs) | |
implies?(colors, :green, drinks, :coffee) | |
implies?(nationalities, :danish, drinks, :tea) | |
implies?(cigars, :pall_mall, pets, :birds) | |
implies?(nationalities , :german, cigars, :prince) | |
implies?(colors, :yellow, cigars, :dunhill) | |
implies?(cigars, :bluemasters, drinks, :beer) |
def implies?(set_a, val_a, set_b, val_b) | |
(0..4).any? do |i| | |
set_a[i] == val_a && | |
set_b[i] == val_b | |
end | |
end | |
# The German lives in the third house (position 2) | |
nationalities = [:swedish, :british, :german, :norwegian, :danish] | |
# The third house' occupant smokes Prince (position 2) |
colors = [:white, :yellow, :blue, :red, :green] | |
# House 1 => white | |
# House 2 => yellow | |
# House 3 => blue | |
# House 4 => red | |
# House 5 => green |
[:white, :yellow, :blue, :red, :green].permutation.each do |colors| | |
[:german, :swedish, :british, :norwegian, :danish,].permutation.each do |nationalities| | |
[:birds, :cats, :horses, :fish, :dogs].permutation.each do |pets| | |
[:beer, :water, :tea, :milk, :coffee].permutation.each do |drinks| | |
[:blends, :pall_mall, :prince, :bluemasters, :dunhill].permutation.each do |cigars| | |
# ... | |
end | |
end | |
end | |
end |
colors = [:white, :yellow, :blue, :red, :green].permutation | |
# => #<Enumerator: [:white, :yellow, :blue, :red, :green]:permutation> | |
colors = [:white, :yellow, :blue, :red, :green].permutation.to_a[0] | |
# => [:white, :yellow, :blue, :red, :green] | |
colors = [:white, :yellow, :blue, :red, :green].permutation.to_a[1] | |
# => [:white, :yellow, :blue, :green, :red] | |
colors = [:white, :yellow, :blue, :red, :green].permutation.to_a[2] | |
# => [:white, :yellow, :red, :blue, :green] |
I hereby claim:
To claim this, I am signing this object:
# There are five houses in five different colors in a row. | |
# In each house lives a person with a different nationality. | |
# The five owners drink a certain type of beverage, | |
# smoke a certain brand of cigar and keep a certain pet. | |
# No owners have the same pet, smoke the same brand of cigar, | |
# or drink the same beverage. | |
# The question is: who owns the fish? | |
time_start = Time.now |