aboutsummaryrefslogtreecommitdiff
path: root/challenge-060
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-060')
-rw-r--r--challenge-060/javier-luque/blog.txt1
-rw-r--r--challenge-060/javier-luque/perl/ch-1.pl25
-rw-r--r--challenge-060/javier-luque/perl/ch-2.pl23
-rw-r--r--challenge-060/javier-luque/raku/ch-1.p619
-rw-r--r--challenge-060/javier-luque/raku/ch-2.p619
5 files changed, 87 insertions, 0 deletions
diff --git a/challenge-060/javier-luque/blog.txt b/challenge-060/javier-luque/blog.txt
new file mode 100644
index 0000000000..9ca6a6a5a6
--- /dev/null
+++ b/challenge-060/javier-luque/blog.txt
@@ -0,0 +1 @@
+https://perlchallenges.wordpress.com/2020/05/11/perl-weekly-challenge-060/
diff --git a/challenge-060/javier-luque/perl/ch-1.pl b/challenge-060/javier-luque/perl/ch-1.pl
new file mode 100644
index 0000000000..c1be7ebcca
--- /dev/null
+++ b/challenge-060/javier-luque/perl/ch-1.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+# Test: ./ch-1.pl 30
+use strict;
+use warnings;
+use feature qw /say/;
+
+say to_excel($ARGV[0]);
+
+sub to_excel {
+ my $n = shift;
+
+ # Array to store digits
+ my @digits;
+
+ # Break down the digits to base 26
+ while ($n > 0) {
+ push @digits, ($n-1) % 26;
+ $n = int(($n-1)/26);
+ }
+
+ # Join the digits
+ return join '',
+ map { chr(ord('A') + $_) }
+ reverse @digits;
+}
diff --git a/challenge-060/javier-luque/perl/ch-2.pl b/challenge-060/javier-luque/perl/ch-2.pl
new file mode 100644
index 0000000000..2cbab657b6
--- /dev/null
+++ b/challenge-060/javier-luque/perl/ch-2.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+# Test: ./ch-2.pl
+
+use strict;
+use warnings;
+use feature qw /say/;
+use Algorithm::Combinatorics qw /variations/;
+
+my @L = (0, 1, 2, 5);
+my $X = 2;
+my $Y = 21;
+my @answers;
+
+# Brute force the variations
+my $variations = variations(\@L, $X);
+while (my $v = $variations->next) {
+ my $n = join '', @$v;
+ $n = int($n); #Remove leading 0
+ push @answers, $n
+ if ($n < $Y && length($n) == $X);
+}
+
+say join ', ', sort @answers;
diff --git a/challenge-060/javier-luque/raku/ch-1.p6 b/challenge-060/javier-luque/raku/ch-1.p6
new file mode 100644
index 0000000000..5bfc03ec28
--- /dev/null
+++ b/challenge-060/javier-luque/raku/ch-1.p6
@@ -0,0 +1,19 @@
+# Test: perl6 ch-1.p6 30
+sub MAIN(Int $n) {
+ say to-excel($n);
+}
+
+
+sub to-excel(Int $n is copy) {
+ # Array to store digits
+ my @digits;
+
+ # Break down the digits to base 26
+ while ($n > 0) {
+ @digits.push(($n-1) % 26);
+ $n = Int( ($n-1)/26 );
+ }
+
+ # Join the digits
+ return @digits.reverse.map({ chr(ord('A') + .Int) }).join('');
+}
diff --git a/challenge-060/javier-luque/raku/ch-2.p6 b/challenge-060/javier-luque/raku/ch-2.p6
new file mode 100644
index 0000000000..7ef6bbc4c6
--- /dev/null
+++ b/challenge-060/javier-luque/raku/ch-2.p6
@@ -0,0 +1,19 @@
+# Test: perl6 ch-2.p6
+sub MAIN() {
+ my @L = (0, 1, 2, 5);
+ my $X = 2;
+ my $Y = 21;
+ my @answers;
+
+ # Brute force the variations
+ my @combos = @L.combinations: $X;
+ for @combos -> $combo {
+ for $combo.permutations -> $perms {
+ my $n = $perms.join('').Int;
+ @answers.push($n)
+ if ($n < $Y && $n.chars == $X);
+ }
+ }
+
+ say @answers.sort.join(', ');
+}