Script started on Mon Mar 30 20:33:37 1998 xavier[11]% cat AHmwk6.pp cat: cannot open Hmwk6.pp xavier[12]% cat Hmwk8.pp /* Webber Assignment 8 Dan J. Fraser (1219229) */ list_of_k_integers(X, List) :- counter(X,0,List). counter(Size, Count, List) :- list_of_k_integers_that_sum_to_S(Size,Count,List). counter(Size,Count,List) :- plus(Count,1,New_Count), counter(Size,New_Count,List). an_integer_less_than_or_equal_to(X, X) :- . an_integer_less_than_or_equal_to(Int, X) :- plus(Z, 1, Int), an_integer_less_than_or_equal_to(Z,X). list_of_k_integers_that_sum_to_S(0, 0, nil) :- . list_of_k_integers_that_sum_to_S(Size, 0, 0:Tail) :- not Size = 0, plus(New_Size,1,Size), list_of_k_integers_that_sum_to_S(New_Size, 0, Tail). list_of_k_integers_that_sum_to_S(Size, Sum, Y:X ) :- not Size = 0, not Sum = 0, an_integer_less_than_or_equal_to(Sum,Y), plus(New_Size,1,Size), plus(New_Sum,Y,Sum), list_of_k_integers_that_sum_to_S(New_Size, New_Sum, X). xavier[13]% cat Hmwk8.Given.pp pythagorean_triples(X, Y, Z) :- list_of_k_integers(3, X:Y:Z:nil), plus(2, Something, X), /* X >= 2 */ plus(X, SomethingElse, Y), /* Y >= X */ times(X,X,Xsquared), times(Y,Y,Ysquared), times(Z,Z,Zsquared), plus(Xsquared,Ysquared,Zsquared). sum_of_four_squares(S, W, X, Y, Z) :- list_of_k_integers(4, W:X:Y:Z:nil), times(W,W,Wsquared), times(X,X,Xsquared), times(Y,Y,Ysquared), times(Z,Z,Zsquared), plus(Wsquared, Xsquared, FirstSubTotal), plus(Ysquared,Zsquared, SecondSubTotal), plus(FirstSubTotal, SecondSubTotal, S). xavier[14]% exit exit script done on Mon Mar 30 20:33:54 1998