Guest User

Untitled

a guest
Apr 24th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. def solve(n = 1)
  2. return true if n == @cubes.length
  3. rotationCount = 0
  4. solved = false
  5. while not solved
  6. solved = true
  7. n.times do |i|
  8. if @cubes[n] == @cubes[i]
  9. solved = false
  10. break
  11. end
  12. end
  13.  
  14. if solved and (solved = solve(n + 1))
  15. return true
  16. else
  17. @cubes[n].rotate
  18. rotationCount += 1
  19. if rotationCount > 3
  20. return false
  21. end
  22. end
  23. end
  24. end
Add Comment
Please, Sign In to add comment