Skip to content

Commit 368dd2b

Browse files
better prime example
1 parent d2a06dd commit 368dd2b

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

content/_index.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,13 @@ Cognate is a stack-oriented programming language similar to Forth or Factor, exc
6262
Def Factor (Zero? Modulo Swap);
6363
6464
Def Primes (
65-
Let U is upper bound;
66-
initially List ();
67-
For Range 2 to U (
68-
Let P is potential prime;
69-
Let Found be list of found primes;
70-
Let To-check be Take-while (<= Sqrt P) Found;
71-
When All (Not Factor of P) To-check (
72-
Append P
73-
) to Found
74-
)
65+
Fold (
66+
Let I be our potential prime;
67+
Let Primes are the found primes;
68+
Let To-check be Take-while (<= Sqrt I) Primes;
69+
When None (Factor of I) To-check
70+
(Append List (I)) to Primes;
71+
) from List () over Range from 2
7572
);
7673
7774
Print Primes up to 1000;

0 commit comments

Comments
 (0)