diff options
| author | Adam Russell <ac.russell@live.com> | 2022-11-19 01:49:16 -0500 |
|---|---|---|
| committer | Adam Russell <ac.russell@live.com> | 2022-11-19 01:49:16 -0500 |
| commit | 70b92e315c96453b74fbe999d7fe48edabcc9d59 (patch) | |
| tree | c60d885d4ecc2ba3674175d701eebf1f8ab4578d | |
| parent | 8b4586760efa4ae9b92ca6bf7b2ab258b2000906 (diff) | |
| download | perlweeklychallenge-club-70b92e315c96453b74fbe999d7fe48edabcc9d59.tar.gz perlweeklychallenge-club-70b92e315c96453b74fbe999d7fe48edabcc9d59.tar.bz2 perlweeklychallenge-club-70b92e315c96453b74fbe999d7fe48edabcc9d59.zip | |
initial commit
| -rw-r--r-- | challenge-191/adam-russell/perl/ch-1.pl | 0 | ||||
| -rw-r--r-- | challenge-191/adam-russell/perl/ch-2.pl | 40 | ||||
| -rw-r--r-- | challenge-191/adam-russell/prolog/ch-1.p | 0 | ||||
| -rw-r--r-- | challenge-191/adam-russell/prolog/ch-2.p | 14 |
4 files changed, 54 insertions, 0 deletions
diff --git a/challenge-191/adam-russell/perl/ch-1.pl b/challenge-191/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-191/adam-russell/perl/ch-1.pl diff --git a/challenge-191/adam-russell/perl/ch-2.pl b/challenge-191/adam-russell/perl/ch-2.pl new file mode 100644 index 0000000000..5964e231bb --- /dev/null +++ b/challenge-191/adam-russell/perl/ch-2.pl @@ -0,0 +1,40 @@ +use v5.36; +use strict; +use warnings; +## +# You are given an integer, 0 < $n <= 15. +# Write a script to find the number of orderings of numbers that form a cute list. +## +use Hash::MultiKey; + +sub cute_list{ + my($n) = @_; + my %cute; + tie %cute, "Hash::MultiKey"; + for my $i (1 .. $n){ + $cute{[$i]} = undef; + } + my $i = 1; + { + $i++; + my %cute_temp; + tie %cute_temp, "Hash::MultiKey"; + for my $j (1 .. $n){ + for my $cute (keys %cute){ + if(0 == grep {$j == $_} @{$cute}){ + if(0 == $j % $i || 0 == $i % $j){ + $cute_temp{[@{$cute}, $j]} = undef; + } + } + } + } + %cute = %cute_temp; + untie %cute_temp; + redo unless $i == $n; + } + return keys %cute; +} + +MAIN:{ + say cute_list(15) . q//; +}
\ 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 new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-191/adam-russell/prolog/ch-1.p diff --git a/challenge-191/adam-russell/prolog/ch-2.p b/challenge-191/adam-russell/prolog/ch-2.p new file mode 100644 index 0000000000..414b6395a4 --- /dev/null +++ b/challenge-191/adam-russell/prolog/ch-2.p @@ -0,0 +1,14 @@ +cute(_, _) --> []. +cute(N, CuteList) --> [X], {between(1, N, X), \+ member(X, CuteList), + append(CuteList, [X], CuteListUpdated), + nth(I, CuteListUpdated, X), + 0 is mod(X, I)}, + cute(N, CuteListUpdated). +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 |
