euler 1 en zsh
as we debated about reusability in shell scripting. i wrote a solution for the euler’s project problem 1.
- multiple_of writes a condition string usable by awk.
- sum compute the sum of the stdin entries that matches the condition
- seq is a standard command that generate a list of natural
multiples_of () { print -n '!( $0 % '$^@') || ' 0 }</code>
sum () {
awk "$( $@ )"' { i=+$0 }
END { print i }
'
}
seq 9 | sum multiples_of 3 5