Replies: 1 comment
-
Very interesting, thank you a lot for sharing this! To remove the infinitely many redundant solutions, I think it suffices to add The predicate np_(C,Cp,N,P):- zcompare(Comp, N, 1), c_np_(Comp, C, Cp, N, P). c_np_(=, C, _, _, C). c_np_(>, C, Cp, N, P) :- if_(r_div(N,Cp), (Q#=N/Cp,D#=C+1,np_(D,Cp,Q,P)), (Np#=Cp+1,np_(C,Np,N,P))). With r_div(A, B, T) :- A mod B #= R, if_(R = 0, T = true, T = false). Yielding: ?- np(27, N). N = 3. ?- ch2([11,8,27,4], Ls). Ls = [11,4,8,27]. Note that |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This program is an attempt at Perl Weekly Challenge 241.
The recursion I have implemented in
np_
implicates an infinite number of solutions that point at the same result, resulting inch2
also doing the same.I have tried using
if_/3
for checking theN=1
case instead, which works, but i was wondering if i could make this work with the pattern match as well.Beta Was this translation helpful? Give feedback.
All reactions