
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1199 · main · 10 min 33 s
1Étoiles
0Forks
0Issues
| 1 | // A map/filter/fold pipeline over a million integers, ten times (each |
| 2 | // round a little longer, so that no compiler computes it only once). |
| 3 | |
| 4 | import std/io |
| 5 | import std/list |
| 6 | |
| 7 | fn round :: k: Int acc: Int -> Int |
| 8 | { |
| 9 | if k == 0 |
| 10 | { |
| 11 | acc |
| 12 | } |
| 13 | else |
| 14 | { |
| 15 | let doubled = list.map (list.range 1 (1000000 + k)) fn x { x * 2 } |
| 16 | let sum = |
| 17 | list.fold (list.filter doubled fn x { x % 3 == 0 }) 0 fn a x { a + x } |
| 18 | round (k - 1) (acc + sum) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | pub fn main :: -> () / <io> |
| 23 | { |
| 24 | io.println (show (round 10 0)) |
| 25 | } |