Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Player = Integer
- type Card = Integer
- type Hand = [Card]
- type Deck = Hand
- type Hands = Player -> Hand
- deal' :: Player -> (Player -> Player) -> Deck -> [Hands -> Hands]
- deal' player next [] = []
- deal' player next (card : cards) = giveTo player card : deal' (next player) next cards
- giveTo player card hands = \player' ->
- if player == player'
- then card : hands player'
- else hands player'
- deal'' :: [Hands -> Hands] -> Hands
- deal'' [] = const []
- deal'' (action : actions) = action (deal'' actions)
- deal players = deal'' . deal' 0 (\player -> (player + 1) `mod` players)
- -- *Main> deal 3 [5,6,8,9,7,5,4,2,3,1,5,6,7] 0
- -- [5,9,4,1,7]
- -- *Main> deal 3 [5,6,8,9,7,5,4,2,3,1,5,6,7] 1
- -- [6,7,2,5]
- -- *Main> deal 3 [5,6,8,9,7,5,4,2,3,1,5,6,7] 2
- -- [8,5,3,6]
- -- *Main> deal 3 [5,6,8,9,7,5,4,2,3,1,5,6,7] 3
- -- []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement