Skip to content

Instantly share code, notes, and snippets.

@aprell
Created December 13, 2012 16:39
Show Gist options
  • Save aprell/4277768 to your computer and use it in GitHub Desktop.
Save aprell/4277768 to your computer and use it in GitHub Desktop.
Simple script to calculate the standard deviation of a series of numbers (Bash, Io)
#!/bin/bash
# Calculate the standard deviation of a series of numbers
cat > stddev.io <<IOCODE
#!/usr/bin/env io
l := List clone
IOCODE
chmod +x stddev.io
while read number; do
echo $number
cat >> stddev.io <<IOCODE
l append($number)
IOCODE
done
cat >> stddev.io <<IOCODE
((l map(x, (x - l average) squared) sum) / (l size - 1)) sqrt println
IOCODE
echo "===================="
echo " Standard deviation "
echo "===================="
echo "scale=2; $(io stddev.io)/1" | bc
rm stddev.io
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment