[racket] How to verify prime numbers.

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Thu Jul 14 02:49:50 EDT 2011

·Éµ¶ wrote at 07/14/2011 01:56 AM:
> I want a program to verify prime numbers which can be runned in 
> mzscheme. The following is C source. I don't konwn how to convert it 
> to lisp.

It looks like that C code is trying to do a one-time population of a 
large lookup table, for later determining in constant time whether a 
given number 0 through 999,999 is prime.

Are you sure that this is the approach that you want to use for 
primality testing? This approach has the merit of being extremely fast 
in C once the table is built, but there are alternative approaches: 

If you do still want to use this same approach in Racket, you can indeed 
rewrite the C code in equivalent Racket code. Nobody wants to spoil 
someone else's learning experience by telling them the equivalent Racket 
code. To help you figure out the Racket code yourself, you probably want 
to start reading one of the following URLs:

You will also want to make test cases, for verifying the correctness of 
your approach and its implementation.

Feel free to ask questions on the list as you work through the 
documentation and the programming problem.


Posted on the users mailing list.