It is such a nice feeling that Mu is such a capable little language ๐ And I decided to write code code in Mu by hand ๐ค haha ๐คฃ and start solving Project Euler problems, like Problem 8 which works out to be a nice elegant solution in Mu:
#!/usr/bin/env mu
// Largest Product in a Series
import "fp"
import "sys"
fn usage() {
print("Usage: cat |", args()[0], "<n>")
}
fn products(xs) {
return fp.reduce(xs, 1, fn(x, y) {
if y == nil {
return x
}
return x * y
})
}
fn main() {
if len(args()) < 2 {
usage()
exit(1)
}
s := must(sys.read_all(0))
if len(s) == 0 {
usage()
exit(1)
}
n := must(int(args()[1]))
r := fp.max(fp.map(fp.sliding(fp.map(s, int), n), products))
print(r)
}
main()
