aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-06-24 19:55:43 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2021-06-24 19:55:43 +0100
commit786579fc8f23db25a7c8de1b2d420cf357d25c7b (patch)
tree1024de374ca6c9f421ed39a9e9c175942181b633
parentdd2a41d26cfab5d551a88ff16d0b6062518d34e0 (diff)
downloadperlweeklychallenge-club-786579fc8f23db25a7c8de1b2d420cf357d25c7b.tar.gz
perlweeklychallenge-club-786579fc8f23db25a7c8de1b2d420cf357d25c7b.tar.bz2
perlweeklychallenge-club-786579fc8f23db25a7c8de1b2d420cf357d25c7b.zip
Add bc solution to challenge 009
-rw-r--r--challenge-009/paulo-custodio/bc/ch-1.bc31
-rw-r--r--challenge-009/paulo-custodio/t/test-1.yaml25
-rw-r--r--challenge-009/paulo-custodio/t/test-2.yaml9
-rw-r--r--challenge-009/paulo-custodio/test.pl33
4 files changed, 68 insertions, 30 deletions
diff --git a/challenge-009/paulo-custodio/bc/ch-1.bc b/challenge-009/paulo-custodio/bc/ch-1.bc
new file mode 100644
index 0000000000..0449047840
--- /dev/null
+++ b/challenge-009/paulo-custodio/bc/ch-1.bc
@@ -0,0 +1,31 @@
+#!/usr/bin/bc -ql
+
+/*
+Challenge 009
+
+Challenge #1
+Write a script that finds the first square number that has at least 5 distinct
+digits. This was proposed by Laurent Rosenfeld.
+*/
+
+scale = 0
+num = read()
+
+define num_diff_digits(n) {
+ auto digit, digits[], i, sum
+ while (n > 0) {
+ digit = n % 10
+ n /= 10
+ digits[digit] = 1
+ }
+ sum = 0
+ for (i = 0; i < 10; i++)
+ sum += digits[i]
+ return sum;
+}
+
+n = 1
+while (num_diff_digits(n*n) < num)
+ n = n+1
+n*n
+quit
diff --git a/challenge-009/paulo-custodio/t/test-1.yaml b/challenge-009/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..0e7966c514
--- /dev/null
+++ b/challenge-009/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,25 @@
+- setup:
+ cleanup:
+ args: 1
+ input:
+ output: 1
+- setup:
+ cleanup:
+ args: 2
+ input:
+ output: 16
+- setup:
+ cleanup:
+ args: 3
+ input:
+ output: 169
+- setup:
+ cleanup:
+ args: 4
+ input:
+ output: 1024
+- setup:
+ cleanup:
+ args: 5
+ input:
+ output: 12769
diff --git a/challenge-009/paulo-custodio/t/test-2.yaml b/challenge-009/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..06e3445fb4
--- /dev/null
+++ b/challenge-009/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,9 @@
+- setup:
+ cleanup:
+ args: 2 3 1 4 2 2 1 0
+ input:
+ output: |
+ |Data: 2, 3, 1, 4, 2, 2, 1, 0
+ |Standard ranking: 3, 2, 6, 1, 3, 3, 6, 8
+ |Modified ranking: 5, 2, 7, 1, 5, 5, 7, 8
+ |Dense ranking: 3, 2, 4, 1, 3, 3, 4, 5
diff --git a/challenge-009/paulo-custodio/test.pl b/challenge-009/paulo-custodio/test.pl
index c5275ed8f4..ba6c37260b 100644
--- a/challenge-009/paulo-custodio/test.pl
+++ b/challenge-009/paulo-custodio/test.pl
@@ -1,31 +1,4 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use 5.030;
+#!/usr/bin/env perl
+use Modern::Perl;
use Test::More;
-
-is capture("perl perl/ch-1.pl 1"), "1\n";
-is capture("perl perl/ch-1.pl 2"), "16\n";
-is capture("perl perl/ch-1.pl 3"), "169\n";
-is capture("perl perl/ch-1.pl 4"), "1024\n";
-is capture("perl perl/ch-1.pl 5"), "12769\n";
-
-
-is capture("perl perl/ch-2.pl 2 3 1 4 2 2 1 0"), <<END;
-Data: 2, 3, 1, 4, 2, 2, 1, 0
-Standard ranking: 3, 2, 6, 1, 3, 3, 6, 8
-Modified ranking: 5, 2, 7, 1, 5, 5, 7, 8
-Dense ranking: 3, 2, 4, 1, 3, 3, 4, 5
-END
-
-
-done_testing;
-
-
-sub capture {
- my($cmd) = @_;
- my $out = `$cmd`;
- $out =~ s/[ \r\t]*\n/\n/g;
- return $out;
-}
+require '../../challenge-001/paulo-custodio/test.pl';