aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-10-11 21:57:35 +0100
committerGitHub <noreply@github.com>2021-10-11 21:57:35 +0100
commiteca4184bd77a0c74bc224d7377e1e20091e97512 (patch)
treec0588686c586e399de6aaf4abe91b39818617b84
parent5f01f0a38aa1e5a76c4262de8c7c6e1977c594ea (diff)
parente5050bc6b5641ac4855d3c8a58dd95df9a6b855e (diff)
downloadperlweeklychallenge-club-eca4184bd77a0c74bc224d7377e1e20091e97512.tar.gz
perlweeklychallenge-club-eca4184bd77a0c74bc224d7377e1e20091e97512.tar.bz2
perlweeklychallenge-club-eca4184bd77a0c74bc224d7377e1e20091e97512.zip
Merge pull request #5010 from andinus/master
Add Raku solution for challenge-134
-rw-r--r--challenge-134/andinus/README71
-rw-r--r--challenge-134/andinus/README.org28
-rw-r--r--challenge-134/andinus/blog-1.txt1
-rw-r--r--challenge-134/andinus/raku/ch-1.raku3
4 files changed, 47 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..dddda91b7f
--- /dev/null
+++ b/challenge-134/andinus/README.org
@@ -0,0 +1,28 @@
+#+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
+
+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..559fff7b37
--- /dev/null
+++ b/challenge-134/andinus/blog-1.txt
@@ -0,0 +1 @@
+https://andinus.unfla.me/pwc/challenge-134/
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]