aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Russell <adamcrussell@outlook.com>2025-06-22 18:45:57 -0400
committerAdam Russell <adamcrussell@outlook.com>2025-06-22 18:45:57 -0400
commita7968890b5d0656fb3d8d48201e4dfdbc70d6618 (patch)
tree85644caf6ba000a987facd74f170dc941269eabe
parentcf38a6108a1b0635a8c9375c3eea633fe833ca1a (diff)
downloadperlweeklychallenge-club-a7968890b5d0656fb3d8d48201e4dfdbc70d6618.tar.gz
perlweeklychallenge-club-a7968890b5d0656fb3d8d48201e4dfdbc70d6618.tar.bz2
perlweeklychallenge-club-a7968890b5d0656fb3d8d48201e4dfdbc70d6618.zip
initial commit
-rw-r--r--challenge-326/adam-russell/blog.txt1
-rw-r--r--challenge-326/adam-russell/blog1.txt1
-rw-r--r--challenge-326/adam-russell/blog1.xt0
-rw-r--r--challenge-326/adam-russell/perl/ch-1.pl24
-rw-r--r--challenge-326/adam-russell/perl/ch-2.pl27
-rw-r--r--challenge-326/adam-russell/prolog/ch-1.p35
-rw-r--r--challenge-326/adam-russell/prolog/ch-2.p19
7 files changed, 107 insertions, 0 deletions
diff --git a/challenge-326/adam-russell/blog.txt b/challenge-326/adam-russell/blog.txt
new file mode 100644
index 0000000000..1c0d3ac923
--- /dev/null
+++ b/challenge-326/adam-russell/blog.txt
@@ -0,0 +1 @@
+http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2025/06/22
diff --git a/challenge-326/adam-russell/blog1.txt b/challenge-326/adam-russell/blog1.txt
new file mode 100644
index 0000000000..9669971af4
--- /dev/null
+++ b/challenge-326/adam-russell/blog1.txt
@@ -0,0 +1 @@
+http://www.rabbitfarm.com/cgi-bin/blosxom/prolog/2025/06/22
diff --git a/challenge-326/adam-russell/blog1.xt b/challenge-326/adam-russell/blog1.xt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/challenge-326/adam-russell/blog1.xt
diff --git a/challenge-326/adam-russell/perl/ch-1.pl b/challenge-326/adam-russell/perl/ch-1.pl
new file mode 100644
index 0000000000..52a528eae5
--- /dev/null
+++ b/challenge-326/adam-russell/perl/ch-1.pl
@@ -0,0 +1,24 @@
+
+ use v5.40;
+
+ sub day_of_year {
+ my ($date) = @_;
+ my $day_of_year = 0;
+ my ($year, $month, $day) = split /-/, $date;
+
+ my $is_leap_year = ($year % 400 == 0) || ($year % 4 == 0 && $year % 100 != 0);
+ my $february_days = $is_leap_year ? 29 : 28;
+
+ my @days_in_month = (31, $february_days, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
+ $day_of_year += $days_in_month[$_] for (0 .. $month - 2);
+ $day_of_year += $day;
+ return $day_of_year;
+ }
+
+
+MAIN:{
+ say day_of_year q/2025-02-02/;
+ say day_of_year q/2025-04-10/;
+ say day_of_year q/2025-09-07/;
+}
+
diff --git a/challenge-326/adam-russell/perl/ch-2.pl b/challenge-326/adam-russell/perl/ch-2.pl
new file mode 100644
index 0000000000..dafb7c88d6
--- /dev/null
+++ b/challenge-326/adam-russell/perl/ch-2.pl
@@ -0,0 +1,27 @@
+
+ use v5.40;
+
+ sub decompress_list{
+ my $r = shift @_;
+ if(!ref($r) || ref($r) ne q/ARRAY/){
+ unshift @_, $r;
+ $r = [];
+ }
+ unless(@_ == 0){
+ my $i = shift @_;
+ my $j = shift @_;
+ push @{$r}, ($j) x $i;
+ decompress_list($r, @_);
+ }
+ else{
+ return @{$r};
+ }
+ }
+
+
+MAIN:{
+ say join q/, /, decompress_list 1, 3, 2, 4;
+ say join q/, /, decompress_list 1, 1, 2, 2;
+ say join q/, /, decompress_list 3, 1, 3, 2;
+}
+
diff --git a/challenge-326/adam-russell/prolog/ch-1.p b/challenge-326/adam-russell/prolog/ch-1.p
new file mode 100644
index 0000000000..383a7eb331
--- /dev/null
+++ b/challenge-326/adam-russell/prolog/ch-1.p
@@ -0,0 +1,35 @@
+
+
+ day_month_year(S, Day, Month, Year):-
+ append(Y, [45|T], S),
+ append(M, [45|D], T),
+ number_codes(Day, D),
+ number_codes(Month, M),
+ number_codes(Year, Y).
+
+
+ leap_year(Year):-
+ M1 is Year mod 4,
+ M2 is Year mod 100,
+ M3 is Year mod 400,
+ ((M1 == 0, \+ M2 == 0);
+ (M1 == 0, M2 == 0, M3 == 0)).
+
+
+ february_days(Year, Days):-
+ leap_year(Year),
+ Days = 29.
+ february_days(_, Days):-
+ Days = 28.
+
+
+ day_of_year(Date, DayOfYear) :-
+ day_month_year(Date, Day, Month, Year),
+ february_days(Year, FebruaryDays),
+ DaysInMonth = [31, FebruaryDays, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
+ succ(M, Month),
+ length(Prefix, M),
+ prefix(Prefix, DaysInMonth),
+ sum_list(Prefix, MonthSum),
+ DayOfYear is MonthSum + Day.
+
diff --git a/challenge-326/adam-russell/prolog/ch-2.p b/challenge-326/adam-russell/prolog/ch-2.p
new file mode 100644
index 0000000000..937fed74db
--- /dev/null
+++ b/challenge-326/adam-russell/prolog/ch-2.p
@@ -0,0 +1,19 @@
+
+
+ decompression(Decompression), [Decompression] --> [Decompression].
+ decompression(D, Decompression), [Decompression] --> [D].
+
+
+ decompress(Input) --> decompression(D, Decompression),
+ {Input = [I, J|T],
+ length(L, I),
+ maplist(=(J), L),
+ append(D, L, Decompression)
+ },
+ decompress(T).
+ decompress([]) --> [].
+
+
+ decompress_list(L, Decompressed):-
+ phrase(decompress(L), [[]], [Decompressed]).
+