Guest User

Untitled

a guest
Aug 4th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.51 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'pp'
  4.  
  5. windows = Hash[(1..100).map { | window | [ window, :c ] }]
  6.  
  7. def switch(windows, window)
  8.   if windows[window] == :c
  9.     windows[window] = :o
  10.   else
  11.     windows[window] = :c
  12.   end
  13. end
  14.  
  15. (1..100).each do | person |
  16.   #puts "=== person #{person}"
  17.   (0..100).step(person).each do | window |
  18.     next if window == 0
  19.     #puts "window #{window}"
  20.     switch(windows, window)
  21.   end
  22. end
  23.  
  24. #pp windows
  25. windows.each_pair do | window, state |
  26.   puts window if state == :o
  27. end
Advertisement
Add Comment
Please, Sign In to add comment