2022-09-06 13:52:29 +00:00
|
|
|
let square = x -> x^2;
|
2022-09-07 20:11:51 +00:00
|
|
|
let also_square(x) = x^2;
|
2022-09-06 13:52:29 +00:00
|
|
|
|
|
|
|
let primes = range(100) |: filter(is_prime);
|
|
|
|
let prime_squares = range(100) |: map(square);
|
|
|
|
let also_prime_squares = range(100) |? is_prime |> square;
|
|
|
|
|
|
|
|
#
|
|
|
|
let primes_and_prime_squares = primes |& prime_squares;
|
|
|
|
|
|
|
|
if 49 <~ data {
|
|
|
|
println("49 is the square of a prime");
|
|
|
|
} else {
|
|
|
|
println("49 is not the square of a prime");
|
|
|
|
}
|
|
|
|
|
2022-09-07 22:10:43 +00:00
|
|
|
for p : primes {
|
|
|
|
println(p);
|
|
|
|
}
|
|
|
|
|
2022-09-06 13:52:29 +00:00
|
|
|
# LET IDENT(square) EQ IDENT(x) ARROW IDENT(x) CARET INT(2) SEMICOLON
|
|
|
|
#
|
|
|
|
# LET IDENT(data) EQ IDENT(range) LPAREN INT(100) RPAREN PIPECOLON IDENT(filter) LPAREN IDENT(is_prime) RPAREN PIPECOLON IDENT(map) LPAREN IDENT(square) RPAREN SEMICOLON
|
|
|
|
# LET IDENT(also_data) EQ IDENT(range) LPAREN INT(100) RPAREN PIPEQUESTION IDENT(is_prime) PIPEPOINT IDENT(square) SEMICOLON
|
|
|
|
|
|
|
|
# D = x:(fold(map(factors(x), n:(to_int(fold(factors(x),mul)/n))), add))
|
|
|
|
|
|
|
|
let D = x -> {
|
|
|
|
let facts = factors(x);
|
|
|
|
let product = facts |: foldl(1, mul);
|
|
|
|
return facts |> (n -> product / n) |: foldl(0, add);
|
|
|
|
}
|