aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCY Fung <fungcheokyin@gmail.com>2023-01-22 19:50:12 +0800
committerCY Fung <fungcheokyin@gmail.com>2023-01-22 19:50:12 +0800
commit6ad63c725d47df8bcd8efc923670cea67e66c677 (patch)
tree0ceb892a34dc9d20624ba0b6700893dcb81f5e6f
parentfeecb8ab9a0c286c805d12532051dbb8f6e43a54 (diff)
downloadperlweeklychallenge-club-6ad63c725d47df8bcd8efc923670cea67e66c677.tar.gz
perlweeklychallenge-club-6ad63c725d47df8bcd8efc923670cea67e66c677.tar.bz2
perlweeklychallenge-club-6ad63c725d47df8bcd8efc923670cea67e66c677.zip
Week 200
-rw-r--r--challenge-200/cheok-yin-fung/perl/ch-1.pl25
-rw-r--r--challenge-200/cheok-yin-fung/perl/ch-2.pl50
2 files changed, 75 insertions, 0 deletions
diff --git a/challenge-200/cheok-yin-fung/perl/ch-1.pl b/challenge-200/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..acf84c12bc
--- /dev/null
+++ b/challenge-200/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,25 @@
+# The Weekly Challenge 200
+# Task 1 Arithmetic Slices
+use v5.30.0;
+use warnings;
+use Algorithm::Combinatorics qw/combinations/;
+
+my @a = @ARGV;
+@a = (1,2,3,4) if scalar @ARGV == 0;
+
+for my $i (3..1+$#a) {
+ my $iter = combinations(\@a, $i);
+ while (my $p = $iter->next) {
+ say join ",", $p->@* if verify($p);
+ }
+}
+
+sub verify {
+ my @a = $_[0]->@*;
+ return 0 if scalar @a < 3;
+ my $diff = $a[1]-$a[0];
+ for (1..$#a-1) {
+ return 0 if $diff != $a[$_+1]-$a[$_];
+ }
+ return 1;
+}
diff --git a/challenge-200/cheok-yin-fung/perl/ch-2.pl b/challenge-200/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..e555efe364
--- /dev/null
+++ b/challenge-200/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,50 @@
+# The Weekly Challenge 200
+# Task 1 Seven Segment 200
+use v5.30.0;
+use warnings;
+
+my @truth = qw<abcdef bc abdeg abcdg bcfg
+ acdfg acdefg abc abcdefg abcfg>;
+
+draw($ARGV[0] || 200);
+
+sub draw {
+ my @arr = split "", $_[0];
+ for my $d (0..$#arr) {
+ drawA(index($truth[$arr[$d]], "a"));
+ print(($d==$#arr)?"\n":" ");
+ }
+ for (1..2) {
+ for my $d (0..$#arr) {
+ drawFB(index($truth[$arr[$d]], "f"), index($truth[$arr[$d]], "b"));
+ print(($d==$#arr)?"\n":" ");
+ }
+ }
+ for my $d (0..$#arr) {
+ drawA(index($truth[$arr[$d]], "g"));
+ print(($d==$#arr)?"\n":" ");
+ }
+ for (1..2) {
+ for my $d (0..$#arr) {
+ drawFB(index($truth[$arr[$d]], "e"), index($truth[$arr[$d]], "c"));
+ print(($d==$#arr)?"\n":" ");
+ }
+ }
+ for my $d (0..$#arr) {
+ drawA(index($truth[$arr[$d]], "d"));
+ print(($d==$#arr)?"\n":" ");
+ }
+}
+
+
+sub drawA {
+ print " " if $_[0] == -1;
+ print "-------" if $_[0] != -1;
+}
+
+sub drawFB {
+ print " " if $_[0] == -1 && $_[1] == -1;
+ print "| " if $_[0] != -1 && $_[1] == -1;
+ print " |" if $_[0] == -1 && $_[1] != -1;
+ print "| |" if $_[0] != -1 && $_[1] != -1;
+}