||
||	for jwj: based on a Miranda past paper question
||


||
||	divisors (using filter for simplicity)
||	n div 2 could be n-1 instead: n div 2 merely saves it wasting time
||		on the second half.
||
divisors_using_filter :: num -> [num]
	divisors_using_filter n = filter ($is_divisor_of n) [1 .. n div 2]
					where
					x $is_divisor_of n = n mod x = 0

||
||	or...without higher-order functions...
||
divisors :: num -> [num]
	divisors n = all_divisors_of_from_to n 1 (n div 2)
			where
			all_divisors_of_from_to n start finish
			  = [], if start > finish
			  = start : all_divisors_of_from_to n (start+1) finish,
					if start <= finish & n mod start  = 0
			  =         all_divisors_of_from_to n (start+1) finish,
					if start <= finish & n mod start ~= 0


||
||	all_perfect (using filter for simplicity)
||
all_perfect_using_filter :: num -> [num]
	all_perfect_using_filter n = filter is_perfect [1..n]
					where
					is_perfect x = sum (divisors x) = x


||
||	or...without higher-order functions...
||
all_perfect :: num -> [num]
	all_perfect n
	 = all_perfect_from_to 1 n
	   where
	   all_perfect_from_to start finish
		= [], if start > finish
		= start : all_perfect_from_to (start+1) finish,
			  if start <= finish & sum (divisors start)  = start
		=         all_perfect_from_to (start+1) finish,
			  if start <= finish & sum (divisors start) ~= start


||
||	or...using foldr...(a rather unnatural thing to do, but contrived
||				for exam purposes!)
||
all_perfect_using_foldr :: num -> [num]
	all_perfect_using_foldr n = foldr add_if_perfect [] [1..n]
					where
					add_if_perfect x list
					 = x : list, if sum (divisors x)  = x
					 =     list, if sum (divisors x) ~= x
