Within the conceptual sphere of numbers between 0 and 9, we’ve explored Prolog by writing a few relatively useless predicates.
These predicates were required for the assignment:
rnprint(N) – writes N random numbers
rnlist(N,List) – creates a List with N random numbers
count(N,List,F) – returns F, the number of appearances of N in List
singleton_count(List,F) – returns F, the number of single-appearing numbers in List
doubleton_count(List,F) – returns F, the number of twice-appearing numbers in List
And then these predicates were weird useless things that I made up:
rnexclusion(List,N) – returns N, a random number from 0 to 9 inclusive that is not a member of List
rnsequence(List) – returns List, a list of 10 numbers from 0 to 9 inclusive in random order
iota(N,List) – returns List, a list counting from 1 to N, or an empty list if N=0
sum(N,List) – returns List, a list of elements with a sum equal to N
removeAll(N,List,Out) – returns Out, the List with all elements N removed
factors(N,List) – returns List, a list of all the factors of N