Skip to content

Instantly share code, notes, and snippets.

@dannguyen
Created June 11, 2012 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannguyen/2910718 to your computer and use it in GitHub Desktop.
Save dannguyen/2910718 to your computer and use it in GitHub Desktop.
My off-the-top-of-my-head solution to Bruno Miranda's light bulb switching puzzle
# http://blog.brunomiranda.com/post/5660219139/100-light-bulbs-brain-teaser
arr = Array.new(100, true)
(2..100).each do |d|
arr.each_with_index{ |a, i| arr[i] = !a if (i + 1) % d == 0 }
end
puts arr.each_with_index.map{|a, i| i + 1 if a }.compact.join(", ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment