Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
円周率を求めるシェル芸
#/bin/bash
#NUMが大きいほど精度がよくなる
NUM=50; paste <(seq 1 2 $NUM) <(seq $NUM) | \
awk 'NF==2' | awk '{print $1"+ "$2"^2/"}' | \
xargs | awk '$0="4/ "$0" 1"' | xargs -n 1 | \
sed 's/^/(/g'| perl -anle '{print $_}END{print ")" x $.}' | \
xargs | awk '$0="scale=20;"$0' | bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.