22 lines
348 B
Text
22 lines
348 B
Text
term() {
|
|
b=$1;res=$2
|
|
echo "scale=5;$res+$b" | bc
|
|
}
|
|
|
|
sum() {
|
|
(read B; res=$1;
|
|
test -n "$B" && (term $B $res) || (term 0 $res))
|
|
}
|
|
|
|
fold() {
|
|
func=$1
|
|
(while read a ; do
|
|
fold $func | $func $a
|
|
done)
|
|
}
|
|
|
|
mean() {
|
|
tee >(wc -l > count) | fold sum | xargs echo "scale=5;(1/" $(cat count) ") * " | bc
|
|
}
|
|
|
|
(echo 3; echo 1; echo 4) | mean
|