diff options
| -rw-r--r-- | challenge-134/andinus/README | 71 | ||||
| -rw-r--r-- | challenge-134/andinus/README.org | 30 | ||||
| -rw-r--r-- | challenge-134/andinus/blog-1.txt | 1 | ||||
| -rw-r--r-- | challenge-134/andinus/raku/ch-1.raku | 3 |
4 files changed, 49 insertions, 56 deletions
diff --git a/challenge-134/andinus/README b/challenge-134/andinus/README index 93034423ed..1d5171cfa8 100644 --- a/challenge-134/andinus/README +++ b/challenge-134/andinus/README @@ -1,81 +1,40 @@ ━━━━━━━━━━━━━━━ - CHALLENGE 133 + CHALLENGE 134 Andinus ━━━━━━━━━━━━━━━ - 2021-10-04 + 2021-10-11 -Task 1 - Integer Square Root -════════════════════════════ +Task 1 - Pandigital Numbers +═══════════════════════════ - You are given a positive integer `$N'. + Write a script to generate first 5 Pandigital Numbers in base 10. - Write a script to calculate the integer square root of the given - number. + As per the [wikipedia], it says: - Please avoid using built-in function. Find out more about it [here]. - - ┌──── - │ Input: $N = 10 - │ Output: 3 - │ - │ Input: $N = 27 - │ Output: 5 - │ - │ Input: $N = 85 - │ Output: 9 - │ - │ Input: $N = 101 - │ Output: 10 - └──── + A pandigital number is an integer that in a given base has + among its significant digits each digit used in the base + at least once. -[here] <https://en.wikipedia.org/wiki/Integer_square_root> +[wikipedia] <https://en.wikipedia.org/wiki/Pandigital_number> Raku ──── • Program: <file:raku/ch-1.raku> - Initial estimate is set to `$n +> 1', then we loop infinitely until - previous 2 estimates are equal. - - ┌──── - │ my $x = $n +> 1; - │ loop { - │ given ($x + ($n / $x)) / 2 { - │ last if $x == $_; - │ $x = $_; - │ } - │ } - │ put $x; - └──── - - -C -─ - - • Program: <file:c/ch-1.c> - - `argv' holds the input & `argc' holds the number of inputs. The input - should be a single integer so `argc' should be equal to 2. After - checking for that, we check if valid value was passed. - - Loop until previous 2 estimates are equal. + Loop from 1023456789 (first Pandigital Number) and take if it contains + every digit in base 10. ┌──── - │ double x = num >> 1; - │ for (;;) { - │ double x_next = (x + (num / x)) / 2; - │ if (x == x_next) - │ break; - │ x = x_next; - │ } - │ printf("%f\n", x); + │ put gather for 1023456789 .. ∞ { + │ .take if .comb>>.Int.Set ≡ (0 .. 9).Set; + │ }[^5] └──── diff --git a/challenge-134/andinus/README.org b/challenge-134/andinus/README.org new file mode 100644 index 0000000000..a9d0829f77 --- /dev/null +++ b/challenge-134/andinus/README.org @@ -0,0 +1,30 @@ +#+title: Challenge 134 +#+date: 2021-10-11 +#+html_link_up: ../ +#+export_file_name: index +#+options: toc:nil +#+setupfile: ~/.emacs.d/org-templates/level-2.org + +* Task 1 - Pandigital Numbers + +Write a script to generate first 5 Pandigital Numbers in base 10. + +As per the [[https://en.wikipedia.org/wiki/Pandigital_number][wikipedia]], it says: + +#+begin_quote +A pandigital number is an integer that in a given base has among its +significant digits each digit used in the base at least once. +#+end_quote + +** Raku + +- Program: [[file:raku/ch-1.raku]] + +Loop from 1023456789 (first Pandigital Number) and take if it contains +every digit in base 10. + +#+begin_src raku +put gather for 1023456789 .. ∞ { + .take if .comb>>.Int.Set ≡ (0 .. 9).Set; +}[^5] +#+end_src diff --git a/challenge-134/andinus/blog-1.txt b/challenge-134/andinus/blog-1.txt new file mode 100644 index 0000000000..cd040d689d --- /dev/null +++ b/challenge-134/andinus/blog-1.txt @@ -0,0 +1 @@ +https://andinus.unfla.me/pwc/challenge-133/ diff --git a/challenge-134/andinus/raku/ch-1.raku b/challenge-134/andinus/raku/ch-1.raku new file mode 100644 index 0000000000..8380756076 --- /dev/null +++ b/challenge-134/andinus/raku/ch-1.raku @@ -0,0 +1,3 @@ +put gather for 1023456789 .. ∞ { + .take if .comb>>.Int.Set ≡ (0 .. 9).Set; +}[^5] |
