` Sieve of Eratosthenes ` Really a test of the FreeRAM features. "Sieve of Eratosthenes"# "Upper limit to test to ? " ? = L "Zeroing array"# ` Set array to TRUE ` Everything is prime until proven otherwise... 0=C 1[ 1 = !C C + 1 = C - L ] "Done." ` Preset a few known ones... 0 = C 0 = !C ` 0 is not prime 1 = C 0 = !C ` Neither is 1. L ;Q = M ` Test up to the square root of our upper bound ;S ;P _ ` P: Print the array (P 0 = C 1[ C % 72 [ \ # 0] !C [ "*" \ "." 0] C + 1 = C - L ] # ) ` S: Sift through the array looking for Primes (S 1 = P ` Start at 1 1[ P + 1 = P ` This is the next potential Prime. ` Loop until we find the next Prime 1[ !P ` Fetch flag } ` If TRUE then break-out P + 1 = P ` Next candidate P > M [ ) ] ` End? Return. 1] ` Loop P ;X 1] ) ` X: Strike out all the multiples of the current target (X = F + F = J [ 0 = !J J + F = J < L ] ) ` Integer Square root ` Herons Method ` Uses S ` Uses but preserves X and Y. (Q = S > 2 [ \ S ) ] X,Y, S / 2 = X S / X + X / 2 = Y 1[ Y = X S / X + X / 2 = Y Y < X ] X = S '=Y '=X S )