|| THE MIRANDA SOLUTION || This program finds the sum of primes || of a number given as input || You must first increase the Miranda heap space || by typing the following at the Miranda prompt || /heap 100000000 || However, after using this program, chnage || the heap back to /heap 1000000 otherwise || less computationally-intensive programs || will take longer to run. is_prime n = True, if #(factors n) = 1 = False, otherwise factors n = [x | x <- [1..(sqroot n)]; n mod x = 0] sqroot n = entier (sqrt n) two_primes n = [(x,y) | x <- [entier(n/2), (entier(n/2))-1..1]; y <- [x..n]; x + y = n; is_prime x; is_prime y] three_primes n = [(x,y,z) | x <- [entier(n/2), (entier(n/2))-1..1]; y <- [entier((n-x)/2), (entier ((n-x)/2))-1..x]; z <- [y..n]; x + y + z= n; is_prime x; is_prime y; is_prime z] sum_of_primes n = my_show1 n, if is_prime n = my_show2((two_primes n)!0), if (n mod 2 = 0) = my_show3((three_primes n)!0), otherwise my_show1 :: num -> [char] my_show1 x = show x my_show2 :: (num,num) -> [char] my_show2 (x,y) = show x ++ " + " ++ show y my_show3 :: (num,num,num) -> [char] my_show3 (x,y,z) = show x ++ " + " ++ show y ++ " + " ++ show z sp = sum_of_primes || try sp 90118 this returns 44987 + 45131 || also try sp 4565973 this returns 1521991 + 1521991 + 1521991