home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / ras_fact.sit < prev    next >
Encoding:
Text File  |  1988-06-20  |  1.6 KB  |  62 lines

  1. 18-Jun-88 14:28:52-MDT,1623;000000000000
  2. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  3. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:28:49 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22213; Sat, 18 Jun 88 14:28:50 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24594; Sat, 18 Jun 88 14:28:48 MDT
  8. Date: Sat, 18 Jun 88 14:28:48 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182028.AA24594@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: Factor.ras
  13.  
  14. program factor;
  15. (* Factors big numbers
  16.  
  17.    c. 1985 The Reed Institute
  18.    
  19.    ..... 88.01.11.rec
  20.    
  21. *)
  22.  
  23. Uses __Quickdraw;
  24. Link __David, __Extras ;
  25.  
  26. Type Giant = Integer[50];   (* We can go up to 147 = 3*49 digits *)
  27.  
  28. proc _init();
  29. { syscall(4);
  30.   syscall(20,-1,"This factoring program finds all prime factors, except");
  31.   syscall(4);
  32.   syscall(20,-1,"decomposition beyond pseudoprimes is not performed.");
  33.   syscall(4);
  34.   syscall(20,-1,"Use mouse to exit a lengthy factorization.");
  35.   syscall(4);
  36.   syscall(4);
  37. };
  38.  
  39. proc _main();
  40. var x,y,z,w,u:giant; found:integer;
  41. {
  42.    syscall(4);
  43.    syscall(20,-1,"Number to be factored: ");
  44.    readg(x);
  45.    watch();
  46.    if (x[0]>1) or (x[1]>1) then
  47.       { loop(,found:=0,,((x[0]=1) and (x[1]=1)) or (button()))
  48.           { factor(x,u);
  49.             divG(u,x);
  50.             loop(,,,((u[0]=1) and (u[1]=1)) or (button()))
  51.             { factor(u,w);
  52.               if found=1 then syscall(20,-1," *"); writeG(w); found:=1;
  53.               divG(w,u);
  54.             };
  55.           };
  56.       } else { itoG(1,w); writeG(w); };
  57.     syscall(4);
  58.     arrow();
  59.   
  60. }; 
  61.  
  62.