2021-12-01

Dec 1 In-Class Exercise Thread.

Please post your solutions to the Dec 1 In-Class Exercise to this thread.
Best,
Chris
Please post your solutions to the Dec 1 In-Class Exercise to this thread. Best, Chris

-- Dec 1 In-Class Exercise Thread
whole(1). whole(X) :- whole(X1), X is X1+1. composite(Y) :- whole(Z), whole(W), Z < Y, W < Y, Z > 1, Y is Z*W. prime(Y) :- whole(Y), Y >= 2, not(composite(Y)).
<nowiki>whole(1). whole(X) :- whole(X1), X is X1+1. composite(Y) :- whole(Z), whole(W), Z < Y, W < Y, Z > 1, Y is Z*W. prime(Y) :- whole(Y), Y >= 2, not(composite(Y)).</nowiki>

-- Dec 1 In-Class Exercise Thread
 whole(1).
 whole(X) :- whole(X1),
             X is X1 + 1.
 
 compositing(Y) :- whole(Z), 
                   whole(W),
                   Z < Y,
                   W < Y,
                   Z > 1,
                   Y is Z * W.
 
 priming(Y) :- whole(Y), 
 	       X >= 2,
 	       not(compositing(Y)).
 
whole(1). whole(X) :- whole(X1), X is X1 + 1. compositing(Y) :- whole(Z), whole(W), Z < Y, W < Y, Z > 1, Y is Z * W. priming(Y) :- whole(Y), X >= 2, not(compositing(Y)).

-- Dec 1 In-Class Exercise Thread
whole(1).
whole(X) :- whole(X1), X is X1+1.
composite(Y) :- whole(Z), whole(W), Z < Y, W < Y, Z > 1, Y is Z*W.
prime(Y) :- whole(Y),
            Y >= 2,
            not(composite(Y)). 
(Edited: 2021-12-01)
whole(1). whole(X) :- whole(X1), X is X1+1. composite(Y) :- whole(Z), whole(W), Z < Y, W < Y, Z > 1, Y is Z*W. prime(Y) :- whole(Y), Y >= 2, not(composite(Y)).

-- Dec 1 In-Class Exercise Thread
Resource Description for 20211201_185935.jpg
((resource:20211201_185935.jpg|Resource Description for 20211201_185935.jpg))

-- Dec 1 In-Class Exercise Thread
whole (1). whole (X) :- whole(X1), X is X1 + 1 . composite (Y) :- whole(W) Z < Y, W < Y, Z > 1, Y is Z * W . prime (Y) :- whole(Y), Y >= Z, not(composite(Y)) . my_for_loop(N) :- prime(N), write(N), n1, N < 100, N > 0, !.
<nowiki> whole (1). whole (X) :- whole(X1), X is X1 + 1 . composite (Y) :- whole(W) Z < Y, W < Y, Z > 1, Y is Z * W . prime (Y) :- whole(Y), Y >= Z, not(composite(Y)) . my_for_loop(N) :- prime(N), write(N), n1, N < 100, N > 0, !. </nowiki>

-- Dec 1 In-Class Exercise Thread
 whole(1)
 whole(x) :- whole(x1), x is x1+1
 composite(y) :- whole(z), 
 whole(w), 
 z<y, 
 w<y, 
 z>1, 
 y is z*w
 prime(y) :- whole(y)
	y >= 2
	not(composite(y))
(Edited: 2021-12-01)
whole(1) whole(x) :- whole(x1), x is x1+1 composite(y) :- whole(z), whole(w), z<y, w<y, z>1, y is z*w prime(y) :- whole(y) y >= 2 not(composite(y))

-- Dec 1 In-Class Exercise Thread
natural(0). natural(N) :- natural(M), N is M+1.
divisible(X,Y) :- 0 is X mod Y, !. divisible(X,Y) :- X > Y+1, divisible(X, Y+1).
isPrime(2) :- true,!. isPrime(X) :- X < 2,!,false. isPrime(X) :- not(divisible(X, 2)).
prime(100) :- natural(I),
                  isPrime(I), write(I), nl,
                  I = 97, !.
natural(0). natural(N) :- natural(M), N is M+1. divisible(X,Y) :- 0 is X mod Y, !. divisible(X,Y) :- X > Y+1, divisible(X, Y+1). isPrime(2) :- true,!. isPrime(X) :- X < 2,!,false. isPrime(X) :- not(divisible(X, 2)). prime(100) :- natural(I), isPrime(I), write(I), nl, I = 97, !.

-- Dec 1 In-Class Exercise Thread
 whole(1).
 whole(X) :- whole(X1), X is X1+1.
 composite(Y) :- whole(Z),   
                 whole(W), 
                 Z < Y,
                 W < Y, 
                 Z > 1, 
                 Y is Z*W.
     
     prime(Y) :- whole(Y),
                 Y >= 2,
                 not(composite(Y)). 
whole(1). whole(X) :- whole(X1), X is X1+1. composite(Y) :- whole(Z), whole(W), Z < Y, W < Y, Z > 1, Y is Z*W. prime(Y) :- whole(Y), Y >= 2, not(composite(Y)).

-- Dec 1 In-Class Exercise Thread
 whole(1).
whole(X) :- whole(X1), X is X1+1. 
 
composite(Y) :- whole(Z), whole(W), Z<Y, W<Y, Z>1, Y is Z*W. 
 
prime(2).
prime(X) :-  whole(X), X>=2, not(composite(X)).
<pre> whole(1). whole(X) :- whole(X1), X is X1+1. composite(Y) :- whole(Z), whole(W), Z<Y, W<Y, Z>1, Y is Z*W. prime(2). prime(X) :- whole(X), X>=2, not(composite(X)).</pre>
[ Next ]
X