SWI-Prolog:FEHLER:ist/2:Argumente werden nicht ausreichend instanziiert
-
18-09-2020 - |
Frage
Ich versuche, ein Programm zu erstellen, das ausgibt, wie viele glatte Zahlen sich in einem Intervall befinden.Ein Teil des Codes ist hier:
countsmooth(_, [], _, _, Count) :-
Count is 0.
countsmooth(X, [H|T], Min, Max, Count) :-
( Y is X*H,
Y =< Max
-> ( Y >= Min
-> NewX is X*H,
countsmooth(X, T, Min, Max, NCount1),
countsmooth(NewX, [H|T], Min, Max, NCount2),
Count is (1+NCount1+NCount2)
; NewX is X*H,
countsmooth(X, T, Min, Max, NCount1),
countsmooth(NewX, [H|T], Min, Max, NCount2),
Count is (NCount1+NCount2)
)
; Count is 0
).
smooth(B, I, J, Smooths) :-
( B =< 1
-> Smooths is 0
; I =:= 1
-> primes(B, FilPrimes),
countsmooth(1, Filprimes, I, J, Count),
Smooths is (1+Count)
; primes(B, FilPrimes),
countsmooth(1, Filprimes, I, J, Count),
Smooths is Count
).
Es gibt auch ein Prädikat primes
das erzeugt alle Primzahlen aus 2
Zu B
.
Zum Beispiel, wenn B = 11
, Dann FilPrimes = [2,3,5,7,11]
.
Wenn ich anrufe countsmooth
im SWI-Prolog wie?- countsmooth(1, [2,3,5,7,11,13,17,19,23], 1, 100000000, Count)
.Ich bekomme ein Ergebnis.
Aber wenn ich anrufe smooth
wie ?- smooth(2,100,10000,Smooths).
Ich erhalte die folgende Fehlermeldung:
ERROR: is/2: Arguments are not sufficiently instantiated
Keine korrekte Lösung
Andere Tipps
Es tut mir wirklich leid.Ich habe den ganzen Tag versucht herauszufinden, was falsch lief, und schließlich sah ich, dass ich an denselben Stellen „FilPrimes“ und an einigen anderen Stellen „Filprimes“ geschrieben hatte.
Ich bin so ein Idiot!