Skip to content

Instantly share code, notes, and snippets.

@ConnorBaker
Created July 6, 2019 16:21
Show Gist options
  • Select an option

  • Save ConnorBaker/b4fc20741518ba3d73e261961790bf10 to your computer and use it in GitHub Desktop.

Select an option

Save ConnorBaker/b4fc20741518ba3d73e261961790bf10 to your computer and use it in GitHub Desktop.
Computes the orbit of a number in (0,1] in a base in (1,\infty). Requires GNU awk
if [ $# -ne 4 ]; then
echo "Usage: bash wrapper.sh <precision> <number of iterations> <number to find orbit of> <base>"
exit 1
fi
gawk -M -v "PREC=$1" -v "ITER=$2" -v "NUM=$3" -v "BASE=$4" \
'BEGIN{
r = NUM;
pair[0] = 0.0;
pair[1] = 0.0;
printf "0.";
for (i = 0; i < ITER; i++) {
betaMap(BASE, r, pair);
r = pair[1];
printf "%d", pair[0];
}
print;
}
# Computes the quotient and remainder of a and b, storing them in ret[0] and
# ret[1], respectively.
function quotRem(a, b, pair) {
quot = 0;
while (a > b) {
a -= b;
quot++;
}
pair[0] = quot;
pair[1] = a;
}
# Computes (b * r) mod 1, and stores the result in
function betaMap(b, r, pair) {
quotRem((b * r), 1.0, pair);
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment