aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-06-18 14:12:36 +0100
committerGitHub <noreply@github.com>2025-06-18 14:12:36 +0100
commit810d3e0617ad607e0ba397d289417eccf26c0f03 (patch)
tree766f03e3a327ba97efdf32b025df130cf4966d25
parentb1c4e60f507b06a4eeda7879af02782cf2d7fabe (diff)
parent3b9e37f15c2e0ef544590961ea580c74542cac05 (diff)
downloadperlweeklychallenge-club-810d3e0617ad607e0ba397d289417eccf26c0f03.tar.gz
perlweeklychallenge-club-810d3e0617ad607e0ba397d289417eccf26c0f03.tar.bz2
perlweeklychallenge-club-810d3e0617ad607e0ba397d289417eccf26c0f03.zip
Merge pull request #12200 from packy/master
Challenge 326 solutions by Packy Anderson
-rw-r--r--challenge-326/packy-anderson/README.md2
-rw-r--r--challenge-326/packy-anderson/blog.txt1
-rwxr-xr-xchallenge-326/packy-anderson/elixir/ch-1.exs19
-rwxr-xr-xchallenge-326/packy-anderson/elixir/ch-2.exs30
-rwxr-xr-xchallenge-326/packy-anderson/perl/ch-1.pl21
-rwxr-xr-xchallenge-326/packy-anderson/perl/ch-2.pl25
-rwxr-xr-xchallenge-326/packy-anderson/python/ch-1.py17
-rwxr-xr-xchallenge-326/packy-anderson/python/ch-2.py26
-rwxr-xr-xchallenge-326/packy-anderson/raku/ch-1.raku17
-rwxr-xr-xchallenge-326/packy-anderson/raku/ch-2.raku25
10 files changed, 182 insertions, 1 deletions
diff --git a/challenge-326/packy-anderson/README.md b/challenge-326/packy-anderson/README.md
index f8e5961b41..f16c1ab69f 100644
--- a/challenge-326/packy-anderson/README.md
+++ b/challenge-326/packy-anderson/README.md
@@ -23,4 +23,4 @@
## Blog Post
-[Perl Weekly Challenge: The Final Count One!](https://packy.dardan.com/b/WY)
+[Perl Weekly Challenge: Got a date with compression!](https://packy.dardan.com/b/Wn)
diff --git a/challenge-326/packy-anderson/blog.txt b/challenge-326/packy-anderson/blog.txt
new file mode 100644
index 0000000000..0e58247ea2
--- /dev/null
+++ b/challenge-326/packy-anderson/blog.txt
@@ -0,0 +1 @@
+https://packy.dardan.com/b/Wn \ No newline at end of file
diff --git a/challenge-326/packy-anderson/elixir/ch-1.exs b/challenge-326/packy-anderson/elixir/ch-1.exs
new file mode 100755
index 0000000000..a427cd0c7f
--- /dev/null
+++ b/challenge-326/packy-anderson/elixir/ch-1.exs
@@ -0,0 +1,19 @@
+#!/usr/bin/env elixir
+
+defmodule PWC do
+
+ def solution(dateStr) do
+ IO.puts("Input: $date = '#{dateStr}'")
+ day_of_year = Date.from_iso8601!(dateStr) |> Date.day_of_year
+ IO.puts("Output: #{day_of_year}")
+ end
+end
+
+IO.puts("Example 1:")
+PWC.solution("2025-02-02")
+
+IO.puts("\nExample 2:")
+PWC.solution("2025-04-10")
+
+IO.puts("\nExample 3:")
+PWC.solution("2025-09-07")
diff --git a/challenge-326/packy-anderson/elixir/ch-2.exs b/challenge-326/packy-anderson/elixir/ch-2.exs
new file mode 100755
index 0000000000..09e6c2f53d
--- /dev/null
+++ b/challenge-326/packy-anderson/elixir/ch-2.exs
@@ -0,0 +1,30 @@
+#!/usr/bin/env elixir
+
+defmodule PWC do
+ def decompress([], out), do: out
+
+ def decompress(ints, out) do
+ {i, ints} = List.pop_at(ints, 0)
+ {j, ints} = List.pop_at(ints, 0)
+ decompress(ints, out ++ List.duplicate(j, i))
+ end
+
+ def decompress(ints) do
+ decompress(ints, [])
+ end
+
+ def solution(ints) do
+ IO.puts("Input: @ints = (" <> Enum.join(ints, ", ") <> ")")
+ out = decompress(ints)
+ IO.puts("Output: (" <> Enum.join(out, ", ") <> ")")
+ end
+end
+
+IO.puts("Example 1:")
+PWC.solution([1, 3, 2, 4])
+
+IO.puts("\nExample 2:")
+PWC.solution([1, 1, 2, 2])
+
+IO.puts("\nExample 3:")
+PWC.solution([3, 1, 3, 2])
diff --git a/challenge-326/packy-anderson/perl/ch-1.pl b/challenge-326/packy-anderson/perl/ch-1.pl
new file mode 100755
index 0000000000..9d575be553
--- /dev/null
+++ b/challenge-326/packy-anderson/perl/ch-1.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+use v5.40;
+
+use Time::Piece;
+
+sub solution($date) {
+ say qq{Input: \$date = '$date'};
+ my $tp = Time::Piece->strptime($date, "%Y-%m-%d")
+ ->truncate(to => 'day');
+ my $day_of_year = $tp->day_of_year + 1;
+ say qq{Output: $day_of_year};
+}
+
+say "Example 1:";
+solution('2025-02-02');
+
+say "\nExample 2:";
+solution('2025-04-10');
+
+say "\nExample 3:";
+solution('2025-09-07');
diff --git a/challenge-326/packy-anderson/perl/ch-2.pl b/challenge-326/packy-anderson/perl/ch-2.pl
new file mode 100755
index 0000000000..95bb6148ba
--- /dev/null
+++ b/challenge-326/packy-anderson/perl/ch-2.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+use v5.40;
+
+sub decompress(@ints) {
+ my @out;
+ for my ($i, $j) ( @ints ) {
+ push @out, ($j) x $i;
+ }
+ @out
+}
+
+sub solution($ints) {
+ say 'Input: @ints = (' . join(', ', @$ints) . ')';
+ my @out = decompress(@$ints);
+ say 'Output: (' . join(', ', @out) . ')';
+}
+
+say "Example 1:";
+solution([1, 3, 2, 4]);
+
+say "\nExample 2:";
+solution([1, 1, 2, 2]);
+
+say "\nExample 3:";
+solution([3, 1, 3, 2]);
diff --git a/challenge-326/packy-anderson/python/ch-1.py b/challenge-326/packy-anderson/python/ch-1.py
new file mode 100755
index 0000000000..2e0ac9e6fd
--- /dev/null
+++ b/challenge-326/packy-anderson/python/ch-1.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+
+from datetime import date
+def solution(dateStr):
+ print(f'Input: $date = \'{dateStr}\'')
+ day_of_year = int(date.fromisoformat(dateStr).strftime('%j'))
+ print(f'Output: {day_of_year}')
+
+
+print('Example 1:')
+solution('2025-02-02')
+
+print('\nExample 2:')
+solution('2025-04-10')
+
+print('\nExample 3:')
+solution('2025-09-07')
diff --git a/challenge-326/packy-anderson/python/ch-2.py b/challenge-326/packy-anderson/python/ch-2.py
new file mode 100755
index 0000000000..3afd4888da
--- /dev/null
+++ b/challenge-326/packy-anderson/python/ch-2.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+from itertools import batched, chain
+
+def decompress(ints):
+ out = []
+ for i, j in batched(ints, 2):
+ out.append([j] * i)
+ return list(chain.from_iterable(out))
+
+def int_join(joiner, arr):
+ return joiner.join(map(lambda i: str(i), arr))
+
+def solution(ints):
+ print(f'Input: @ints = ({int_join(", ", ints)})')
+ print(f'Output: {decompress(ints)}')
+
+
+print('Example 1:')
+solution([1, 3, 2, 4])
+
+print('\nExample 2:')
+solution([1, 1, 2, 2])
+
+print('\nExample 3:')
+solution([3, 1, 3, 2])
diff --git a/challenge-326/packy-anderson/raku/ch-1.raku b/challenge-326/packy-anderson/raku/ch-1.raku
new file mode 100755
index 0000000000..fe3ee884ba
--- /dev/null
+++ b/challenge-326/packy-anderson/raku/ch-1.raku
@@ -0,0 +1,17 @@
+#!/usr/bin/env raku
+use v6;
+
+sub solution($date) {
+ say qq{Input: \$date = '$date'};
+ my $day_of_year = Date.new($date).day-of-year;
+ say qq{Output: $day_of_year};
+}
+
+say "Example 1:";
+solution('2025-02-02');
+
+say "\nExample 2:";
+solution('2025-04-10');
+
+say "\nExample 3:";
+solution('2025-09-07');
diff --git a/challenge-326/packy-anderson/raku/ch-2.raku b/challenge-326/packy-anderson/raku/ch-2.raku
new file mode 100755
index 0000000000..e91e15870d
--- /dev/null
+++ b/challenge-326/packy-anderson/raku/ch-2.raku
@@ -0,0 +1,25 @@
+#!/usr/bin/env raku
+use v6;
+
+sub decompress(@ints) {
+ my @out;
+ for @ints -> $i, $j {
+ @out.append($j xx $i);
+ }
+ @out
+}
+
+sub solution(@ints) {
+ say 'Input: @ints = (' ~ @ints.join(', ') ~ ')';
+ my @out = decompress(@ints);
+ say 'Output: (' ~ @out.join(', ') ~ ')';
+}
+
+say "Example 1:";
+solution([1, 3, 2, 4]);
+
+say "\nExample 2:";
+solution([1, 1, 2, 2]);
+
+say "\nExample 3:";
+solution([3, 1, 3, 2]);