 ## Dardos: 501en Haskell

por josejuan hace 6 años

Sirve para cualquier número de jugadores.

Simular una partida de dardos 501

 `1` `2` `3` `4` `5` `6` `7` `8` `9` `10` `11` `12` `13` `14` `15` `16` `17` `18` `19` `20` `21` `22` `23` `24` `25` `26` `27`
 ``playGame :: (Num a, Ord a) => Int -> [a] -> (Bool, [a]) `` ``playGame nplayers = takeFirstOrLast fst . scanl playRound (False, take nplayers \$ repeat 501) . zip (cycle [1..nplayers]) `` `` `` ``playRound :: (Num a, Ord a) => (t, [a]) -> (Int, a) -> (Bool, [a]) `` ``playRound (_, pa) (cp, p) = (q' == 0, h ++ [q'] ++ t) `` `` where (h, q:t) = splitAt (cp - 1) pa `` `` q' = if q - p < 0 then q else q - p `` `` `` `` `` `` `` `` `` `` `` ``-- a helper function `` ``takeFirstOrLast _ (x:[]) = x `` ``takeFirstOrLast f (x:xs) = if f x then x else takeFirstOrLast f xs `` `` `` `` `` ``{-- `` `` `` ``*Main> playGame 3 [2, 3, 1, 4, 5, 100, 6, 7, 100, 8, 9, 100, 10, 11] `` ``(False,[471,466,200]) `` `` `` ``*Main> playGame 3 [2, 3, 1, 4, 5, 100, 6, 7, 100, 8, 9, 100, 10, 11, 100, 12, 13, 100, 14, 15, 100] `` ``(True,[459,453,0]) `` `` `` `` `` ``--} ``

### Comenta la solución

Tienes que identificarte para poder publicar tu comentario.