views:

51

answers:

1

Hello, I 'm trying to create a program that prints how many smooth numbers are, between an interval. A part of the code is here:

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
).

There is also an argument "primes", that creates all the prime number, from 2 to B. For example if B=11, then FilPrimes = [2,3,5,7,11]. When I call countsmooth in swiprolog, like countsmooth(1, [2,3,5,7,11,13,17,19,23], 1, 100000000, Count). I get a result.

When I call smooth, like smooth(2,100,10000,Smooths). I get the following:

ERROR: is/2: Arguments are not sufficiently instantiated

Could you help me please?? I'm lost!

A: 

I'm really sorry. I have been trying all day to find out what was going wrong and finally I saw that in same places I had written "FilPrimes" and in some other places "Filprimes".

I'm such an idiot!

Alex