Created
July 6, 2019 16:21
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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