diff options
author | Matthias Braendli <matthias.braendli@u-blox.com> | 2015-02-09 17:02:44 +0100 |
---|---|---|
committer | Matthias Braendli <matthias.braendli@u-blox.com> | 2015-02-09 17:02:44 +0100 |
commit | 0ad88bb252766f7555f099dccea8d282e9e3bd9a (patch) | |
tree | 279a7938119fd6a537041cca57ccb2e253e9277d /solitairesimulator2015.hs | |
parent | 3eb2d8f6125c8b527ca1ee2ecc8af0b0a3131d48 (diff) | |
download | haskell-master.tar.gz haskell-master.tar.bz2 haskell-master.zip |
Diffstat (limited to 'solitairesimulator2015.hs')
-rw-r--r-- | solitairesimulator2015.hs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/solitairesimulator2015.hs b/solitairesimulator2015.hs index 2a55969..1c30030 100644 --- a/solitairesimulator2015.hs +++ b/solitairesimulator2015.hs @@ -150,13 +150,13 @@ instance Show End where where Board pegs = b num_pegs = length pegs -solve_r :: Board -> String -> [End] -solve_r b s | null moves = [End (s ++ ".") b] - | otherwise = concat (map (uncurry solve_r) boards_strmoves ) +solve_r :: Board -> [Move] -> [End] +solve_r b m | null moves = [End (show m) b] + | otherwise = concat (map (uncurry solve_r) boards_moves ) where Board pegs = b (moves, boards) = unzip $ all_moves b - strmoves = map ((++) (s ++ " ")) (map show moves) :: [String] - boards_strmoves = zip boards strmoves :: [(Board, String)] + moves_append = map (flip (:) $ m) moves :: [[Move]] + boards_moves = zip boards moves_append :: [(Board, [Move])] pr board = putStrLn ("Welcome to Solitaire Simulator 2015 Deluxe Edition!\n From board\n" ++ show board ++ "\nIt is possible to do\n" ++ unlines (map show $ all_moves board)) @@ -173,6 +173,6 @@ main = do putStrLn $ unlines $ map show perfect_ends putStrLn "Only-one peg solutions:" putStrLn $ unlines $ map show good_ends - where ends = solve_r testboard "" + where ends = solve_r testboard [] good_ends = filter good_end ends perfect_ends = filter perfect_end ends |