// ./tc factor.6.2.tc -r 'debug(1)' // supports larger numbers [ H:\>tc factor.6.2.tc -r main(0) *** TINY-C VERSION 1.0, COPYRIGHT 1977, T A GIBSON *** This C version copyright 2017, T A Gibson 2020-02-13 07:45:20 factor.tc - 2/13/20 - lrb - source code has 1647 bytes Enter number to factor 235039561 15331 15331 = 235039561 2020-02-13 07:52:55 ] // 1947545161 = 44131*44131 (supported but would take a very long time) // added time reporting size [ char foo(3000) return readfile"factor.6.2.tc",foo,3000 ] main int dbg [ char datebuff(30);cdate datebuff;printf"%c%s%c",10,datebuff,10 printf"%cfactor.tc - 2/13/20 - lrb - source code has %d bytes%c",10,size(),10 int f,p(5000),idx,j,pc,sw,ft;ft=1 p(0)=2;p(1)=3;idx=1;pc=5 // pc is a prime candidate pl"Enter number to factor ";f=gn while f%2==0 [pn 2;f=f/2;ft=ft*2] while f%3==0 [pn 3;f=f/3;ft=ft*3] while 1 [ if dbg [ printf"%cdebug idx = %d p(%d) = %d",10,idx,idx,p(idx) printf" pc = %d f = %d%c",pc,f,10 ] // exit if we got 'em all if f==1 [printf" = %d%c",ft,10;cdate datebuff;printf"%c%s%c",10,datebuff,10;abort] // is what's left prime? if yes, print and exit if pc*pc>f [pn f;ft=ft*f;printf" = %d%c",ft,10;cdate datebuff;printf"%c%s%c",10,datebuff,10;abort] sw=0;j=0 while p(j)