aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/primecount.ds22
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/primecount.ds b/examples/primecount.ds
new file mode 100755
index 0000000..8bb4fc8
--- /dev/null
+++ b/examples/primecount.ds
@@ -0,0 +1,22 @@
+#!/bin/ducky
+LOG Counting...
+NEWLINE
+LET primes=0
+LET MAX=100000
+LET n = 2
+LBL test_number
+ LET iter = 2
+ LET stop = sqrt n
+ LBL test_loop
+ IF !(n % iter); GOTO composite
+ INC iter
+ IF iter < stop; GOTO test_loop
+ INC primes
+ LBL composite
+ INC n
+ IF n < MAX; GOTO test_number
+LOG Number of primes below
+LOGVAR MAX
+LOG :
+LOGVAR primes
+NEWLINE