louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | // Allocation-heavy list code: map, filter, fold, reverse (Perceus reuse |
| 2 | // and drop paths). |
| 3 | |
| 4 | import std/io |
| 5 | import std/list |
| 6 | |
| 7 | fn round :: xs: List<Int> -> Int |
| 8 | { |
| 9 | let doubled = list.map xs fn x { x * 2 } |
| 10 | let kept = list.filter doubled fn x { x % 3 != 0 } |
| 11 | let back = list.reverse kept |
| 12 | use acc, x <- list.fold back 0 |
| 13 | acc + x % 7 |
| 14 | } |
| 15 | |
| 16 | fn rounds :: xs: List<Int> n: Int acc: Int -> Int |
| 17 | { |
| 18 | if n == 0 |
| 19 | { |
| 20 | acc |
| 21 | } |
| 22 | else |
| 23 | { |
| 24 | rounds xs (n - 1) (acc + round xs) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | pub fn main :: -> () / <io> |
| 29 | { |
| 30 | let xs = list.range 1 200000 |
| 31 | io.println (show (rounds xs 20 0)) |
| 32 | } |
| 33 | //> 8000000 |