Created
January 31, 2018 16:29
-
-
Save samsartor/25780c662081c80600790b55aa4cf3a7 to your computer and use it in GitHub Desktop.
Plays the "linear" version of Solitaire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Card = (Int, Int) | |
type Deck = [Card] | |
type Hand = [Card] | |
collase_one :: Hand -> Hand | |
collase_one ((_, ra) : _ : _ : (_, rb) : rest) | ra == rb = rest | |
collase_one (a@(sa, _) : _ : _ : b@(sb, _) : rest) | sa == sb = [a, b] ++ rest | |
collase_one t = t | |
collape_all :: Hand -> Hand | |
collape_all = until (\d -> (collase_one d) == d) collase_one | |
play :: (Deck, Hand) -> [(Deck, Hand)] | |
play s@([], _) = [s] | |
play s@(deck, hand) = s : play (tail deck, collape_all $ head deck : hand) | |
score :: Deck -> Int | |
score deck = length . snd . last $ play (deck, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment