import curl (CURL) let c = CURL('https://figure.game/') let html = c.perform().str() let nMoves = int(html.match!(/(?<="moves":)\d+/)) let tiles = html.match!(/(?<="tiles":\[).*?(?=\])/).split(',').map(int).groupsOf(5) print(tiles.map(&unwords).unlines()) function flood(tiles, i, j, t) { if tiles[i][j] != t return tiles[i][j] = nil if (j > 0) flood(tiles, i, j - 1, t) if (j < 4) flood(tiles, i, j + 1, t) if (i > 0) flood(tiles, i - 1, j, t) } function slide(tiles, col) { for row in 4...1 { tiles[row][col] = tiles[row - 1][col] } tiles[0][col] = nil } function fix(tiles) { for col in ..5 { for _ in ..5 while tiles[4][col] == nil { slide(tiles, col) } } } function do(tiles, i) { let copy = [row.clone() for row in tiles] flood(copy, 4, i, tiles[4][i]) fix(copy) return copy } function solve(tiles, moves, move) { if (tiles[-1].all?((== nil))) return moves if (move == nMoves) return nil for t, i in tiles[-1] if t != nil { if let $sol = solve(do(tiles, i), moves + [i], move + 1) { return sol } } } print(solve(tiles, [], 0).group().map(g -> match g { [i] => i, i => "{i.0}x{#i}" }).join(', '))