Articles taggés :zsh

euler 1 en zsh

Par mc, 30 janvier 2010 18 h 48 min

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

Panorama Theme by Themocracy