tobogganSe connecter

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.

33 lignes · 586 octetsBrut · Historique
1// Allocation-heavy list code: map, filter, fold, reverse (Perceus reuse
2// and drop paths).
3
4import std/io
5import std/list
6
7fn 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
16fn 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
28pub fn main :: -> () / <io>
29{
30 let xs = list.range 1 200000
31 io.println (show (rounds xs 20 0))
32}
33//> 8000000