Gamified challenge · State-space search
Coloured balls are jumbled across test tubes that each hold capacity balls. tubes[i] lists tube i's balls from bottom to top as colour letters ("rgr" is red, green, red; "" is empty). A move "i j" takes the top ball of tube i onto tube j, allowed only when tube j is empty, or not full with the same colour on top.
Write sortBalls(tubes, capacity) (sort_balls in Python) that returns at most 200 moves after which every tube is empty or full of one colour; any such list passes. For ["ggg", "rr", "r"] with capacity 3, ["2 1"] sorts it in one move.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google