## Kristen Lew, Homework 18Special ## ExpMath, Spring 2012 # Post what you wish. Help:=proc(): print(`mex(S), afunc(n), countTwos(n) `): end: mex:=proc(S) local Maxi, i: Maxi:=max(S): for i from 0 to Maxi+1 do if member(i,S)=false then return(i): fi: od: end: afunc:=proc(n) local k,r: option remember: if n<1 then RETURN(FAIL): elif n=1 then RETURN(2): elif n=2 then RETURN(3): fi: mex({0,1} union {seq(seq(j*afunc( r), j=1..50), r=1..n-1)}): end: ## seq(afunc(i),i=1..20); gives ## 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71 ## which are the prime numbers. ## Hence, the two properties follow. ## I also wrote this problem to count how many two's show up in a_i+1 - a_i. ## This problem is slow, but kind of shows that the count ## continues to increase at a relatively steady rate. countTwos:=proc(n) local counter, k: option remember: counter:=0: for k from 1 to n+1 do if afunc(k+1)-afunc(k)=2 then counter:=counter+1: fi: od: counter: end: