Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. @world = []
  2.  
  3. @thingy = {
  4. "111" => 0,
  5. "110" => 1,
  6. "101" => 1,
  7. "100" => 0,
  8. "011" => 1,
  9. "010" => 1,
  10. "001" => 1,
  11. "000" => 0
  12. }
  13.  
  14. 50.times do
  15. @world << rand(1);
  16. end
  17. @world << 1
  18.  
  19. def tick(world)
  20. next_generation = []
  21. world.each_with_index do |x, i|
  22. if i == world.length - 1
  23. next_generation[i] = @thingy[[world[i-1], x, world[0]].join.to_s]
  24. else
  25. next_generation[i] = @thingy[[world[i-1], x, world[i+1]].join.to_s]
  26. end
  27. end
  28. next_generation
  29. end
  30.  
  31. system("clear")
  32. loop do
  33. @world = tick(@world)
  34. derp = @world.map{|e| e == 1 ? "# " : " " }.join
  35. puts derp
  36. sleep 0.05
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement