Skip to content

Instantly share code, notes, and snippets.

@monolar
Created July 6, 2015 10:10
Show Gist options
  • Save monolar/adce7455b464fd60e293 to your computer and use it in GitHub Desktop.
Save monolar/adce7455b464fd60e293 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# http://www.spiegel.de/wissenschaft/mensch/raetsel-der-woche-wie-viele-schliessfaecher-stehen-offen-a-1041982.html
require 'tco'
NUMBER_OF_DOORS = ARGV[0].to_i || 10
INITAL_STATE = false # false is closed, true is opened
DOORS = (1..NUMBER_OF_DOORS).map { false }
def run(n)
DOORS.each_with_index do |door,index|
if ((index+1) % n) == 0
DOORS[index] = !DOORS[index]
end
end
end
def render
DOORS.each do |d|
if d
print " ".bg("#00DD00")
else
print " ".bg("#DD0000")
end
end
print "\n"
end
(1..NUMBER_OF_DOORS).each do |n|
run(n)
render()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment