aboutsummaryrefslogtreecommitdiff
path: root/challenge-060
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-05-17 19:24:33 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-05-17 19:24:33 +0100
commit39b08bd942cf379f103f31ef0200a1d89768ab45 (patch)
tree86393b1e093761d9ebe68e940d6ed9dbf41e790f /challenge-060
parent79667b6d2609dfc6587526f8a2debe0b7125c8ca (diff)
downloadperlweeklychallenge-club-39b08bd942cf379f103f31ef0200a1d89768ab45.tar.gz
perlweeklychallenge-club-39b08bd942cf379f103f31ef0200a1d89768ab45.tar.bz2
perlweeklychallenge-club-39b08bd942cf379f103f31ef0200a1d89768ab45.zip
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-060')
-rw-r--r--challenge-060/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-060/laurent-rosenfeld/perl/ch-1.pl16
-rw-r--r--challenge-060/laurent-rosenfeld/perl/ch-2.pl21
-rw-r--r--challenge-060/laurent-rosenfeld/raku/ch-1.p613
-rw-r--r--challenge-060/laurent-rosenfeld/raku/ch-2.p611
5 files changed, 62 insertions, 0 deletions
diff --git a/challenge-060/laurent-rosenfeld/blog.txt b/challenge-060/laurent-rosenfeld/blog.txt
new file mode 100644
index 0000000000..4be7bd5aa5
--- /dev/null
+++ b/challenge-060/laurent-rosenfeld/blog.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/laurent_r/2020/05/perl-weekly-challenge-60-excel-columns-and-find-numbers.html
diff --git a/challenge-060/laurent-rosenfeld/perl/ch-1.pl b/challenge-060/laurent-rosenfeld/perl/ch-1.pl
new file mode 100644
index 0000000000..ccd781f42a
--- /dev/null
+++ b/challenge-060/laurent-rosenfeld/perl/ch-1.pl
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use feature qw /say/;
+use constant MAXNUM => 16_384;
+use constant MAXLET => 'XFD';
+
+my @cols = ('', 'A'..MAXLET);
+my %nums = map { $cols[$_] => $_ } 1..MAXNUM;
+my $in = shift // 28;
+if ($in =~ /^\d+$/) {
+ say "Column $in = $cols[$in]";
+} elsif ( $in =~ /^[A-Z]+$/ ) {
+ say "Column $in = $nums{$in}";
+} else {
+ say "$in is invalid input.";
+}
diff --git a/challenge-060/laurent-rosenfeld/perl/ch-2.pl b/challenge-060/laurent-rosenfeld/perl/ch-2.pl
new file mode 100644
index 0000000000..b221e0c114
--- /dev/null
+++ b/challenge-060/laurent-rosenfeld/perl/ch-2.pl
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use feature qw /say/;
+
+my $length = shift;
+my $max_val = shift;
+my @L = @ARGV;
+
+sub permute {
+ my ($seed, @list) = @_;
+ return if length $seed > $length;
+ for my $val (@list) {
+ next if $seed eq "" and $val == 0;
+ my $new_seed = 0 + ($seed . $val);
+ say $new_seed if length $new_seed == $length
+ and $new_seed < $max_val;
+ permute($new_seed, @list);
+ }
+}
+
+permute "", @L;
diff --git a/challenge-060/laurent-rosenfeld/raku/ch-1.p6 b/challenge-060/laurent-rosenfeld/raku/ch-1.p6
new file mode 100644
index 0000000000..014a72ffa6
--- /dev/null
+++ b/challenge-060/laurent-rosenfeld/raku/ch-1.p6
@@ -0,0 +1,13 @@
+use v6;
+
+constant \MAX = 16_384;
+my @cols = '', 'A', 'B' ... *;
+my %nums = map { @cols[$_] => $_}, 1..MAX;
+
+multi sub MAIN (Int $n = 28) {
+ say "Column $n = @cols[$n]";
+}
+
+multi sub MAIN (Str $col-name where * ~~ /^<[A..Z]>+$/) {
+ say "Column $col-name = %nums{$col-name}";
+}
diff --git a/challenge-060/laurent-rosenfeld/raku/ch-2.p6 b/challenge-060/laurent-rosenfeld/raku/ch-2.p6
new file mode 100644
index 0000000000..7b3c7a8871
--- /dev/null
+++ b/challenge-060/laurent-rosenfeld/raku/ch-2.p6
@@ -0,0 +1,11 @@
+sub MAIN (Int $length, Int $max-val, Str $list) {
+ my @L = | $list.split(" ") xx $length;
+ my @out;
+ for @L.combinations: 1..$length -> $seq {
+ for $seq.permutations>>.join('') -> $num {
+ push @out, +$num if $num < $max-val
+ and $num.Int.chars == $length;
+ }
+ }
+ .say for @out.sort.squish;
+}