diff options
| author | Adam Russell <ac.russell@live.com> | 2022-11-20 14:41:35 -0500 |
|---|---|---|
| committer | Adam Russell <ac.russell@live.com> | 2022-11-20 14:41:35 -0500 |
| commit | b5791fac00294ed02e86dd60f70cd0416f66ebfd (patch) | |
| tree | 4586661c17001fa086ca13f2ea4b5128e884807f | |
| parent | 70b92e315c96453b74fbe999d7fe48edabcc9d59 (diff) | |
| download | perlweeklychallenge-club-b5791fac00294ed02e86dd60f70cd0416f66ebfd.tar.gz perlweeklychallenge-club-b5791fac00294ed02e86dd60f70cd0416f66ebfd.tar.bz2 perlweeklychallenge-club-b5791fac00294ed02e86dd60f70cd0416f66ebfd.zip | |
updated solutions. added blogs.
| -rw-r--r-- | challenge-191/adam-russell/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-191/adam-russell/blog1.txt | 1 | ||||
| -rw-r--r-- | challenge-191/adam-russell/perl/ch-1.pl | 30 | ||||
| -rw-r--r-- | challenge-191/adam-russell/prolog/ch-1.p | 17 | ||||
| -rw-r--r-- | challenge-191/adam-russell/prolog/ch-2.p | 5 |
5 files changed, 50 insertions, 4 deletions
diff --git a/challenge-191/adam-russell/blog.txt b/challenge-191/adam-russell/blog.txt new file mode 100644 index 0000000000..22ccf20284 --- /dev/null +++ b/challenge-191/adam-russell/blog.txt @@ -0,0 +1 @@ +http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2022/11/20
\ No newline at end of file diff --git a/challenge-191/adam-russell/blog1.txt b/challenge-191/adam-russell/blog1.txt new file mode 100644 index 0000000000..6a46aadfe3 --- /dev/null +++ b/challenge-191/adam-russell/blog1.txt @@ -0,0 +1 @@ +http://www.rabbitfarm.com/cgi-bin/blosxom/prolog/2022/11/20
\ No newline at end of file diff --git a/challenge-191/adam-russell/perl/ch-1.pl b/challenge-191/adam-russell/perl/ch-1.pl index e69de29bb2..aa6095c94b 100644 --- a/challenge-191/adam-russell/perl/ch-1.pl +++ b/challenge-191/adam-russell/perl/ch-1.pl @@ -0,0 +1,30 @@ +use v5.36; +use strict; +use warnings; +## +# You are given list of integers, @list. Write a script to find out whether the largest +# item in the list is at least twice as large as each of the other items. +## +use boolean; + +sub twice_largest{ + my(@list_integers) = @_; + my $twice_max = -1; + for my $i (0 .. @list_integers - 1){ + my $twice_rest = true; + for my $j (0 .. @list_integers - 1){ + unless($i == $j){ + $twice_rest = $list_integers[$i] >= 2 * $list_integers[$j]; + } + } + $twice_max = $list_integers[$i] if $twice_rest; + } + return $twice_max>-1?1:-1; +} + +MAIN:{ + say twice_largest(1, 2, 3, 4); + say twice_largest(1, 2, 0, 5); + say twice_largest(2, 6, 3, 1); + say twice_largest(4, 5, 2, 3); +}
\ No newline at end of file diff --git a/challenge-191/adam-russell/prolog/ch-1.p b/challenge-191/adam-russell/prolog/ch-1.p index e69de29bb2..e6f1c443e8 100644 --- a/challenge-191/adam-russell/prolog/ch-1.p +++ b/challenge-191/adam-russell/prolog/ch-1.p @@ -0,0 +1,17 @@ +twice_greater(X, Y, TwiceGreater):- + X \== Y, + TwiceY is 2 * Y, + X >= TwiceY, + TwiceGreater = -1. +twice_greater(X, Y, TwiceGreater):- + TwiceY is 2 * Y, + X < TwiceY, + TwiceGreater = 1. + +twice_largest(List):- + max_list(List, Max), + maplist(twice_greater(Max), List, TwiceGreater), + delete(TwiceGreater, -1, TwiceGreaterOneDeleted), + length(TwiceGreaterOneDeleted, TwiceGreaterOneDeletedLength), + TwiceGreaterOneDeletedLength == 1, !. +
\ No newline at end of file diff --git a/challenge-191/adam-russell/prolog/ch-2.p b/challenge-191/adam-russell/prolog/ch-2.p index 414b6395a4..6711b4d1ff 100644 --- a/challenge-191/adam-russell/prolog/ch-2.p +++ b/challenge-191/adam-russell/prolog/ch-2.p @@ -8,7 +8,4 @@ cute(N, CuteList) --> [X], {between(1, N, X), \+ member(X, CuteList), append(CuteList, [X], CuteListUpdated), nth(I, CuteListUpdated, X), 0 is mod(I, X)}, - cute(N, CuteListUpdated). - -%N = 10, findall(Cute, (length(Cute, N), phrase(cute(N, []), Cute)), C), sort(C, CuteList), length(CuteList, NumberCuteList). -
\ No newline at end of file + cute(N, CuteListUpdated).
\ No newline at end of file |
