diff options
Diffstat (limited to 'challenge-112/abigail/awk')
| -rw-r--r-- | challenge-112/abigail/awk/ch-1.awk | 44 | ||||
| -rw-r--r-- | challenge-112/abigail/awk/ch-2.awk | 18 |
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-112/abigail/awk/ch-1.awk b/challenge-112/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..fde01cf5de --- /dev/null +++ b/challenge-112/abigail/awk/ch-1.awk @@ -0,0 +1,44 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk < input-file +# + +BEGIN { + FS = "/" # So we split into directory parts +} + +{ + delete path + j = 0 # Tracks the number of parts in + # the canonical part. + for (i = 1; i <= NF; i ++) { # Loop over directory parts + if ($i == "") { # Skip empty parts + continue; + } + if ($i == ".") { # Skip current directory + continue; + } + if ($i == "..") { # Back up to parent directory + if (j > 0) { + j -- + } + continue; + } + path [j] = $i # Copy + j ++ + } + if (j == 0) { # Root directory + print "/" + } + else { # Print parts, preceeded by a / + for (k = 0; k < j; k ++) { + printf "/%s", path [k] + } + print "" + } +} diff --git a/challenge-112/abigail/awk/ch-2.awk b/challenge-112/abigail/awk/ch-2.awk new file mode 100644 index 0000000000..57f4b8cc6f --- /dev/null +++ b/challenge-112/abigail/awk/ch-2.awk @@ -0,0 +1,18 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-2.awk < input-file +# + +BEGIN { + SQRT5 = sqrt (5) + PHI = (1 + SQRT5) / 2 +} + +{ + print int (0.5 + PHI ^ ($1 + 1) / SQRT5) +} |
