diff options
| author | Abigail <abigail@abigail.freedom.nl> | 2022-01-06 13:59:18 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.freedom.nl> | 2022-01-06 13:59:42 +0100 |
| commit | 27889f392ae8b7b56530ad79424eb9054a249275 (patch) | |
| tree | 3dfd381cbc39d6c8eeb219f1be9cc0cc4ab67786 | |
| parent | 76e71dbba093a8fa883b945df09e22d4b5b94ae2 (diff) | |
| download | perlweeklychallenge-club-27889f392ae8b7b56530ad79424eb9054a249275.tar.gz perlweeklychallenge-club-27889f392ae8b7b56530ad79424eb9054a249275.tar.bz2 perlweeklychallenge-club-27889f392ae8b7b56530ad79424eb9054a249275.zip | |
Copied bc solution of week 3, part 1
| -rw-r--r-- | challenge-003/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-123/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-123/abigail/bc/ch-1.bc | 35 |
3 files changed, 37 insertions, 0 deletions
diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md index 365945625a..83d08b3cd7 100644 --- a/challenge-003/abigail/README.md +++ b/challenge-003/abigail/README.md @@ -15,6 +15,7 @@ ### Part 2 * [AWK](awk/ch-2.awk) +* [Bash](bash/ch-2.sh) * [C](c/ch-2.c) * [Lua](lua/ch-2.lua) * [Node.js](node/ch-2.js) diff --git a/challenge-123/abigail/README.md b/challenge-123/abigail/README.md index e71bda7e0f..b3a9755e81 100644 --- a/challenge-123/abigail/README.md +++ b/challenge-123/abigail/README.md @@ -21,6 +21,7 @@ Output: 12 ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) +* [bc](bc/ch-1.bc) * [C](c/ch-1.c) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) diff --git a/challenge-123/abigail/bc/ch-1.bc b/challenge-123/abigail/bc/ch-1.bc new file mode 100644 index 0000000000..17ac31515a --- /dev/null +++ b/challenge-123/abigail/bc/ch-1.bc @@ -0,0 +1,35 @@ +#!/usr/bin/bc + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-123 +# + +# +# Run as: bc ch-1.bc < input-file +# + +while (1) { + n = read () + if (n == 0) { + break + } + ugly [0] = 1 + next_2 = 0 + next_3 = 0 + next_5 = 0 + index = 1 + while (index < n) { + u2 = 2 * ugly [next_2] + u3 = 3 * ugly [next_3] + u5 = 5 * ugly [next_5] + if ((u2 <= u3) && (u2 <= u5)) {min = u2} + if ((u3 <= u2) && (u3 <= u5)) {min = u3} + if ((u5 <= u2) && (u5 <= u3)) {min = u5} + ugly [index] = min + if (2 * ugly [next_2] <= ugly [index]) {next_2 = next_2 + 1} + if (3 * ugly [next_3] <= ugly [index]) {next_3 = next_3 + 1} + if (5 * ugly [next_5] <= ugly [index]) {next_5 = next_5 + 1} + index = index + 1 + } + ugly [index - 1] +} |
