aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-228/dave-jacoby/blog.txt1
-rw-r--r--challenge-228/dave-jacoby/perl/ch-1.pl32
-rw-r--r--challenge-228/dave-jacoby/perl/ch-2.pl39
3 files changed, 72 insertions, 0 deletions
diff --git a/challenge-228/dave-jacoby/blog.txt b/challenge-228/dave-jacoby/blog.txt
new file mode 100644
index 0000000000..2b1a2630d8
--- /dev/null
+++ b/challenge-228/dave-jacoby/blog.txt
@@ -0,0 +1 @@
+https://jacoby.github.io/2023/07/31/get-sum-weekly-challenge-228.html
diff --git a/challenge-228/dave-jacoby/perl/ch-1.pl b/challenge-228/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..4996d31312
--- /dev/null
+++ b/challenge-228/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use List::Util qw( sum0 );
+
+my @examples = (
+
+ [ 2, 1, 3, 2 ],
+ [ 1, 1, 1, 1 ],
+ [ 2, 1, 3, 4 ],
+);
+
+for my $e (@examples) {
+ my @array = $e->@*;
+ my $array = join ', ', @array;
+ my $sum = uniq_sum(@array);
+ say <<~"END";
+ Input: \@int = ($array)
+ Output: $sum
+ END
+}
+
+sub uniq_sum (@array) {
+ my %hash;
+ for my $int (@array) {
+ $hash{$int}++;
+ }
+ return sum0 grep { $hash{$_} == 1 } keys %hash;
+}
diff --git a/challenge-228/dave-jacoby/perl/ch-2.pl b/challenge-228/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..512108a149
--- /dev/null
+++ b/challenge-228/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use List::Util qw( min );
+
+my @examples = (
+
+ [ 3, 4, 2 ],
+ [ 1, 2, 3 ],
+
+);
+
+for my $e (@examples) {
+ my @array = $e->@*;
+ my $array = join ', ', @array;
+ my $output = empty_array(@array);
+ say <<~"END";
+ Input: \@int = ($array)
+ Output: $output
+ END
+}
+
+# if the first element is the smallest
+# then remove it
+# else
+# move it to the end
+sub empty_array (@array) {
+ my $c = 0;
+ while ( scalar @array ) {
+ my $min = min @array;
+ my $next = shift @array;
+ if ( $min != $next ) { push @array, $next; }
+ $c++;
+ }
+ return $c;
+}