Advertisement
heroofhyla

Untitled

Oct 26th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.89 KB | None | 0 0
  1. def construct_tri(balls)
  2.   #not aware of an easy way to turn linear coordinates into triangular
  3.   #coordinates, so this is all hardcoded for now
  4.   balls[5] = (balls[0]-balls[1]).abs
  5.   balls[6] = (balls[1] - balls[2]).abs
  6.   balls[7] = (balls[2] - balls[3]).abs
  7.   balls[8] = (balls[3] - balls[4]).abs
  8.   balls[9] = (balls[5] - balls[6]).abs
  9.   balls[10] = (balls[6] - balls[7]).abs
  10.   balls[11] = (balls[7] - balls[8]).abs
  11.   balls[12] = (balls[9] - balls[10]).abs
  12.   balls[13] = (balls[10] - balls[11]).abs
  13.   balls[14] = (balls[12] - balls[13]).abs
  14. end
  15.  
  16. def valid_tri?(balls)
  17.   used = []
  18.   balls.each do |ball|
  19.     return false if used.include?(ball)
  20.     used.push(ball)
  21.   end
  22.   true
  23. end
  24.  
  25. balls = Array.new
  26.  
  27. max = 15**5
  28. for i in 0...max
  29.   val = i
  30.   for k in 0...5
  31.     balls[k] = val%15 + 1
  32.     val /= 15
  33.   end
  34.   construct_tri(balls)
  35.   print balls, "\n" if valid_tri?(balls)
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement