Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List
- ----- the numbers on the clock are [3,2,1,1,2,1] and their orders are [0..5] correspondingly
- testdata1 :: [Int]
- testdata1 = [3,2,1,1,2,1]
- ----- convert the order of the elements to a list of possible next moves
- ----- 1 (order) -> [3,2,1,1,2,1] (list of numbers) -> [3,5] (list of orders)
- getSRoutine :: Int -> [Int] -> [Int]
- getSRoutine a ls = nub [fd, sd]
- where len = length ls
- fd = (a + ls!!a) `mod` len
- sd = (a - ls!!a) `mod` len
- ----- a naive backtrack solver to show the orders of all possible routes
- ----- REMARK: the orders are of [0..], not [1..]
- tokSolver :: [Int] -> [[Int]]
- tokSolver [] = []
- tokSolver ls = concat [ tokSolver' len [[a]] | a <- [0..len-1] ]
- where len = length ls
- tokSolver' :: Int -> [[Int]] -> [[Int]]
- tokSolver' 1 routes = routes
- tokSolver' len routes = tokSolver' (len-1) (concatMap nextMove routes)
- where nextMove route = [ route ++ [s] | s <- filter (\x -> x `notElem` route) $ getSRoutine (last route) ls ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement