[ Back to the overview Matrix ]

Test case : Prime Numbers using Forth

Lines used: 12
(Note: I have been informed that this code isn't compatible to the requirements. I'll still leave it up for information, until a better one comes in)
: .PRIMES  0 LOCALS| #primes |  pad 8192 1 FILL  CR
   8192 0 DO I pad +
	     C@ IF I 2*  3 + 
	             DUP 5 .R  
		     #primes 1+ DUP TO #primes  
		     1000 >= IF  DROP LEAVE  ENDIF
		   DUP  I +
	  	    BEGIN  DUP 8192
		 U< WHILE  0 OVER pad + C!  OVER +
		    REPEAT 2DROP 
	     ENDIF
	LOOP ;

Contributed by Marcel Hendrix, mhx at iae.nl