In section 4.5.4 of Knuth's TAOCP, he gives this version of Pollard's famous "rho" algorithm in Algorithm B (page 385 of the 3rd edition); the variable "N" indicates the number to be factored (the input argument, if you like.) (Note that "%" below represents the modulo operator).
Your assignment is to write programs implementing this function in C, Racket, and Gauche. Please don't use the factorization routines included in Racket's number theory module, such as factorize or prime-divisors, or those included in Gauche's math.prime module, such as naive-factorize or mc-factorize; instead, you must implement Knuth's version of the Rho algorithm given above.
Your programs should be able to factor the following numbers in a reasonable time (a few seconds, not a few minutes):
The programming languages that you are to use for the assignment are:
Note that Gauche and Racket are both dialects of Scheme; once you write your code in one, you can largely re-use the same code for the other.
Your output should look like the following (order of factors reported is not important, though this algorithm tends to be better at finding smaller factors):
COP4020_test ~% ./kr 35 Attempting to factor N = 35 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 7 5 COP4020_test ~% ./kr.gosh 35 Attempting to factor N = 35 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 7 5 COP4020_test ~% ./kr.racket 35 Attempting to factor N = 35 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 7 5 COP4020_test ~% ./kr 367756293167964701 Attempting to factor N = 367756293167964701 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 7 11 13 107 101 103 109 3001 1009 COP4020_test ~% ./kr.gosh 367756293167964701 Attempting to factor N = 367756293167964701 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 7 11 13 107 101 103 109 3001 1009 COP4020_test ~% ./kr.racket 367756293167964701 Attempting to factor N = 367756293167964701 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 7 11 13 107 101 103 109 3001 1009 COP4020_test ~% ./kr 2688307493077732358348134727 Attempting to factor N = 2688307493077732358348134727 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 689816117 7688151521 506901611 COP4020_test ~% ./kr.gosh 2688307493077732358348134727 Attempting to factor N = 2688307493077732358348134727 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 689816117 7688151521 506901611 COP4020_test ~% ./kr.racket 2688307493077732358348134727 Attempting to factor N = 2688307493077732358348134727 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 689816117 7688151521 506901611 COP4020_test ~% ./kr 12902144921579660477018619711827 Attempting to factor N = 12902144921579660477018619711827 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 359195201 35919591591591616161427 COP4020_test ~% ./kr.gosh 12902144921579660477018619711827 Attempting to factor N = 12902144921579660477018619711827 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 359195201 35919591591591616161427 COP4020_test ~% ./kr.racket 12902144921579660477018619711827 Attempting to factor N = 12902144921579660477018619711827 with Pollard rho algorithm from Knuth's Algorithm B in section 4.5.4 of TAOCP Factors are: 359195201 35919591591591616161427
What makes these assignments interesting from a programming languages perspective?
There are separate submission links for each of these assignments, and these each will be graded as a separate assignment. Please just turn in one file for each; for the C program, turn in your source file called "kr.c" and which should require the GMP library. For the Gauche version, turn in your source file called "kr.gosh". For the Racket version, turn in your source file called "kr.racket".
The assignment is due by 11:59pm on Sunday, October 27.