diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-30 02:49:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-30 02:49:55 +0100 |
| commit | 8490ef56992acf564e601b51701173338eeb82ef (patch) | |
| tree | 9c7082dff99c32291447796f1737c6fc8dd10705 | |
| parent | 19512217abbfc21a924a540a27cd6a4018bf80af (diff) | |
| parent | 2709ea346959034827c5174aa6d431131c22b9f1 (diff) | |
| download | perlweeklychallenge-club-8490ef56992acf564e601b51701173338eeb82ef.tar.gz perlweeklychallenge-club-8490ef56992acf564e601b51701173338eeb82ef.tar.bz2 perlweeklychallenge-club-8490ef56992acf564e601b51701173338eeb82ef.zip | |
Merge pull request #12254 from adamcrussell/challenge-327
initial commit
| -rw-r--r-- | challenge-327/adam-russell/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-327/adam-russell/blog1.txt | 1 | ||||
| -rw-r--r-- | challenge-327/adam-russell/perl/ch-1.pl | 18 | ||||
| -rw-r--r-- | challenge-327/adam-russell/perl/ch-2.pl | 44 | ||||
| -rw-r--r-- | challenge-327/adam-russell/prolog/ch-1.p | 9 | ||||
| -rw-r--r-- | challenge-327/adam-russell/prolog/ch-2.p | 10 |
6 files changed, 83 insertions, 0 deletions
diff --git a/challenge-327/adam-russell/blog.txt b/challenge-327/adam-russell/blog.txt new file mode 100644 index 0000000000..a42fa2df9f --- /dev/null +++ b/challenge-327/adam-russell/blog.txt @@ -0,0 +1 @@ +http://rabbitfarm.com/cgi-bin/blosxom/perl/2025/06/29 diff --git a/challenge-327/adam-russell/blog1.txt b/challenge-327/adam-russell/blog1.txt new file mode 100644 index 0000000000..114d603e33 --- /dev/null +++ b/challenge-327/adam-russell/blog1.txt @@ -0,0 +1 @@ +http://rabbitfarm.com/cgi-bin/blosxom/prolog/2025/06/29 diff --git a/challenge-327/adam-russell/perl/ch-1.pl b/challenge-327/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..4c77fbfa46 --- /dev/null +++ b/challenge-327/adam-russell/perl/ch-1.pl @@ -0,0 +1,18 @@ + + use v5.40; + + sub find_missing{ + my %h = (); + my @missing = (); + do{ $h{$_} = -1 } for @_; + @missing = grep {!exists($h{$_})} 1 .. @_; + return @missing; + } + + +MAIN:{ + say q/(/ . join(q/, /, find_missing 1, 2, 1, 3, 2, 5) . q/)/; + say q/(/ . join(q/, /, find_missing 1, 1, 1) . q/)/; + say q/(/ . join(q/, /, find_missing 2, 2, 1) . q/)/; +} + diff --git a/challenge-327/adam-russell/perl/ch-2.pl b/challenge-327/adam-russell/perl/ch-2.pl new file mode 100644 index 0000000000..8569bf839e --- /dev/null +++ b/challenge-327/adam-russell/perl/ch-2.pl @@ -0,0 +1,44 @@ + + use v5.40; + + sub mad_pairs{ + my %mad = (); + my $mad = ~0; + for my $i (0 .. @_ - 1){ + for my $j ($i + 1 .. @_ - 1){ + my $d = abs($_[$i] - $_[$j]); + $mad = $d if $d < $mad; + push @{$mad{$d}}, [$_[$i], $_[$j]]; + } + } + return @{$mad{$mad}}; + } + + +MAIN:{ + my $s = q//; + do{ + $s .= q/[/ . join(q/, /, @{$_}) . q/], /; + } for mad_pairs 4, 1, 2, 3; + chop $s; + chop $s; + say $s; + $s = q//; + + do{ + $s .= q/[/ . join(q/, /, @{$_}) . q/], /; + } for mad_pairs 1, 3, 7, 11, 15; + chop $s; + chop $s; + say $s; + $s = q//; + + do{ + $s .= q/[/ . join(q/, /, @{$_}) . q/], /; + } for mad_pairs 1, 5, 3, 8; + chop $s; + chop $s; + say $s; + $s = q//; +} + diff --git a/challenge-327/adam-russell/prolog/ch-1.p b/challenge-327/adam-russell/prolog/ch-1.p new file mode 100644 index 0000000000..8640e953cf --- /dev/null +++ b/challenge-327/adam-russell/prolog/ch-1.p @@ -0,0 +1,9 @@ + + + missing_integers(L, Missing):- + length(L, Length), + findall(M, ( + between(1, Length, M), + \+ member(M, L) + ), Missing). + diff --git a/challenge-327/adam-russell/prolog/ch-2.p b/challenge-327/adam-russell/prolog/ch-2.p new file mode 100644 index 0000000000..37fed505d4 --- /dev/null +++ b/challenge-327/adam-russell/prolog/ch-2.p @@ -0,0 +1,10 @@ + + + mad(L, Pairs):- + fd_max_integer(MAX_INT), + fd_domain([I, J], L), + fd_domain(D, 1, MAX_INT), + J #> I, + fd_minimize((D #= J - I, fd_labeling([D])), D), + findall(Pair, (fd_labeling([I, J]), Pair = [I, J]), Pairs). + |
