Welcome to SWI-Prolog (Multi-threaded, Version 5.6.24) Copyright (c) 1990-2006 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details. For help, use ?- help(Topic). or ?- apropos(Word). ?- consult('rnex.pro'). List Processing Exercise Available predicates: 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 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,F) - returns F, the List with all elements N removed factors(N,List) - returns List, a list of all the factors of N % rnex.pro compiled 0.01 sec, 9,840 bytes Yes ?- rnprint(2). 1 7 Yes ?- rnprint(0). Yes ?- rnprint(9). 1 6 5 1 1 1 3 6 8 Yes ?- rnlist(9,L). L = [8, 3, 7, 0, 0, 3, 6, 1, 8] Yes ?- rnlist(9,L). L = [0, 7, 1, 1, 2, 1, 6, 4, 7] Yes ?- rnlist(9,L). L = [5, 7, 1, 3, 4, 3, 5, 2, 7] Yes ?- count(1,[1,2,3,4,5,6,7,8,9,2,3,5,7,4,4,9,9],C). C = 1 Yes ?- count(2,[1,2,3,4,5,6,7,8,9,2,3,5,7,4,4,9,9],C). C = 2 Yes ?- count(4,[1,2,3,4,5,6,7,8,9,2,3,5,7,4,4,9,9],C). C = 3 Yes ?- singleton_count([1,2,3,4,5,6,7,8,9,2,3,5,7,4,4,9,9],C). C = 3 Yes ?- doubleton_count([1,2,3,4,5,6,7,8,9,2,3,5,7,4,4,9,9],C). C = 4 Yes ?- rnexclusion([2,3,5,7],N). N = 0 ; N = 6 ; N = 8 ; N = 4 ; N = 9 ; N = 6 ; N = 0 ; N = 6 ; N = 1 ; N = 9 ; N = 6 ; N = 1 ; N = 1 Yes ?- rnsequence(L). L = [1, 9, 7, 6, 4, 3, 5, 2, 0|...] Yes ?- rnsequence(L),write(L). [7, 3, 4, 9, 8, 2, 5, 1, 0, 6] L = [7, 3, 4, 9, 8, 2, 5, 1, 0|...] Yes ?- rnsequence(L),write(L). [1, 6, 9, 2, 8, 0, 3, 5, 4, 7] L = [1, 6, 9, 2, 8, 0, 3, 5, 4|...] Yes ?- iota(5,L). L = [1, 2, 3, 4, 5] Yes ?- iota(9,L). L = [1, 2, 3, 4, 5, 6, 7, 8, 9] Yes ?- sum(5,L). L = [4, 1] Yes ?- sum(25,L). L = [3, 4, 8, 7, 2, 1] Yes ?- sum(99,L). L = [3, 8, 9, 5, 2, 8, 6, 3, 4|...] Yes ?- sum(99,L),write(L). [4, 1, 2, 7, 2, 8, 2, 2, 3, 6, 1, 4, 5, 4, 5, 1, 6, 6, 4, 9, 6, 3, 2, 4, 1, 1] L = [4, 1, 2, 7, 2, 8, 2, 2, 3|...] Yes ?- removeAll(1,[1,2,4,5,1,2,3,1,2,1],L). L = [2, 4, 5, 2, 3, 2] Yes ?- removeAll(2,[1,2,4,5,1,2,3,1,2,1],L). L = [1, 4, 5, 1, 3, 1, 1] Yes ?- factors(20,L). L = [1, 2, 4, 5, 10, 20] Yes ?- factors(100,L). L = [1, 2, 4, 5, 10, 20, 25, 50, 100] Yes ?- factors(12600,L). L = [1, 2, 3, 4, 5, 6, 7, 8, 9|...] Yes ?- factors(12600,L),write(L). [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 18, 20, 21, 24, 25, 28, 30, 35, 36, 40, 42, 45, 50, 56, 60, 63, 70, 72, 75, 84, 90, 100, 105, 120, 126, 140, 150, 168, 175, 180, 200, 210, 225, 252, 280, 300, 315, 350, 360, 420, 450, 504, 525, 600, 630, 700, 840, 900, 1050, 1260, 1400, 1575, 1800, 2100, 2520, 3150, 4200, 6300, 12600] L = [1, 2, 3, 4, 5, 6, 7, 8, 9|...] Yes ?- halt.