diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-11-22 17:49:01 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-22 17:49:01 +0000 |
| commit | 421350d1addc6b1787f7b00403a2daf77ec92a29 (patch) | |
| tree | 9e9a29fe576f1ce6f9a989e3582e57a84491610b | |
| parent | 2b9bacca5a0a51ca677a54c9a298fdd39b6da3fe (diff) | |
| parent | 3e0b1f00d4355224a2562550145e2ab60b7ce5f0 (diff) | |
| download | perlweeklychallenge-club-421350d1addc6b1787f7b00403a2daf77ec92a29.tar.gz perlweeklychallenge-club-421350d1addc6b1787f7b00403a2daf77ec92a29.tar.bz2 perlweeklychallenge-club-421350d1addc6b1787f7b00403a2daf77ec92a29.zip | |
Merge pull request #7141 from adamcrussell/challenge-191
updated Prolog solution for 191.2
| -rw-r--r-- | challenge-191/adam-russell/prolog/ch-2.p | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/challenge-191/adam-russell/prolog/ch-2.p b/challenge-191/adam-russell/prolog/ch-2.p index 6711b4d1ff..83b7f8518d 100644 --- a/challenge-191/adam-russell/prolog/ch-2.p +++ b/challenge-191/adam-russell/prolog/ch-2.p @@ -1,11 +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)}, + length(CuteList, CuteListLength), + succ(CuteListLength, I), + (0 is mod(X, I); 0 is mod(I, X)), + append(CuteList, [X], CuteListUpdated)}, 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).
\ No newline at end of file + +main:- + N = 15, + findall(Cute, (length(Cute, N), phrase(cute(N, []), Cute)), C), + sort(C, CuteList), + length(CuteList, NumberCuteList), + write(NumberCuteList), nl.
\ No newline at end of file |
