From 786579fc8f23db25a7c8de1b2d420cf357d25c7b Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Thu, 24 Jun 2021 19:55:43 +0100 Subject: Add bc solution to challenge 009 --- challenge-009/paulo-custodio/bc/ch-1.bc | 31 ++++++++++++++++++++++++++++ challenge-009/paulo-custodio/t/test-1.yaml | 25 ++++++++++++++++++++++ challenge-009/paulo-custodio/t/test-2.yaml | 9 ++++++++ challenge-009/paulo-custodio/test.pl | 33 +++--------------------------- 4 files changed, 68 insertions(+), 30 deletions(-) create mode 100644 challenge-009/paulo-custodio/bc/ch-1.bc create mode 100644 challenge-009/paulo-custodio/t/test-1.yaml create mode 100644 challenge-009/paulo-custodio/t/test-2.yaml 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"), <