|
The above is Jason's idea of a "scary Paige" (from page 129 of "Math, Science and Unix Underpants" by Bill Amend) Please note: since the color orange is not available in tiny-c, we use magenta.
prime int p [return(factor(p)==p)]
factor int f [int p(42),j
p(0)=2;p(1)=3;p(2)=5;p(3)=7;p(4)=11;p(5)=13
p(6)=17;p(7)=19;p(8)=23;p(9)=29;p(10)=31
p(11)=37;p(12)=41;p(13)=43;p(14)=47;p(15)=53
p(16)=59;p(17)=61;p(18)=67;p(19)=71
p(20)=73;p(21)=79;p(22)=83;p(23)=89
p(24)=97;p(25)=101;p(26)=103;p(27)=107
p(28)=109;p(29)=113;p(30)=127;p(31)=131
p(32)=137;p(33)=139;p(34)=149;p(35)=151
p(36)=157;p(37)=163;p(38)=167;p(39)=173
p(40)=179;p(41)=181;p(42)=191
for (j=0;j<=42;++j) if (!(f%p(j))) return p(j)
return f
]
/* amend.tc - tct - 5/2/2010
split int t(0);char s(0),d(0) [
int y,ix,tx,sl,ds;ds=strlen(d);t(0)=s;sl=strlen(s)
while (sl-tx) [
ix=index(s+tx,sl-tx,d,ds)
tx=tx+ix+ds-1;t(++y)=s+tx;s(tx-ds)=0
]
return y
]
amend [
int amend(200),v(0),m,n,c,i,tc
char aft(1000),crlf(2);crlf(0)=13;crlf(1)=10
char cs(30);strcpy cs,"green magenta red yellow "
int colors(3);split(colors,cs," ")
char colorsc(3);colorsc(0)='2';colorsc(1)='5';colorsc(2)='1';colorsc(3)='3'
int primes(2);primes(0)=13;primes(1)=17;primes(2)=19
readfile("af.txt",aft,aft+1000,1)
m=split(amend,aft,crlf)
pl "amend.tc - tct - 5/2/2010"
pl "please visit http://primepuzzle.com/tc/amend.html"
for (i=0;i<4;++i) [
pl "";color(colorsc(i));pl colors(i);pl "";pl ""
n=m;c=0
while n [
atoi(amend(n-1),v)
if i<3 [
if !(v(0)%primes(i)) [++c;MC v(0),14;ps " "]
]
else [
if prime(v(0)) [++c;MC v(0),14;ps " "]
]
if ((c!=0)*(c%17==0)) [tc=tc+c;pl "";c=0]
--n
]
tc=tc+c
]
pl "";pl "";color('7')
if tc==m [MC m,14;ps " numbers processed."]
else [MC m-tc,14;ps " number(s) not processed."]
pl ""
]
|