# Frog Racing in CF

Sep 10th, 2020 (edited)
831
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.
2. double_input :: IO ->> (Int, Int)
3. Empty ~> {
4.     () => raw_input "",
5.     (v1, v2) => (Int v1, Int v2)
6. }
7.
8. data Frog = (Int nb, Int score, Int ahead)
9. data Leader = (Int idx, Int score, Bool tied)
10.
11. frog_list :: Int ->> [Mut Frog]
12. x | x <= 0 => []
13. x => @ [0...x]''0 ~ (n => Mut Frog(n, 0, 0))
14.
15. compare_two :: String, Frog, Leader ->> Leader
16. prop, f, l | f[prop] == l.score => Leader(l.nb, f[prop], True)
17. f, l => f[prop] > l.score ? Leader(f.nb, f[prop], False) : l
18.
19. best_score :: [Frog] ->> Frog
20. frogs >\> compare_two_scores "score" <0?> Leader(-1, -1, True)
21.
22. best_lead :: [Frog] ->> Frog
23. frogs >\> compare_two_scores "ahead" <0?> Leader(-1, -1, True)
24.
25. do:
26.     nbFrogs = IO.raw_input ""
27.     frogs = frog_list nb
28.
29.     nbRounds = IO.raw_input ""
30.
31.     for _ in [0..nbRounds]:
32.         leader = best_score frogs
33.         if not leader.tied:
34.             frogs[leader.idx - 1].ahead += 1
35.
36.         idx, dst = double_input ()
37.         frogs[idx - 1].score += dst
38.
39.     IO.log <- (best_lead frogs).idx
RAW Paste Data