Algorithms
Classic MiniScript+ algorithms with traceable state and compact implementations.
On this page
These examples combine variables, conditions, and loops into complete algorithms.
Prime number test
n = 7divisor = 2isPrime = n >= 2WHILE divisor * divisor <= n AND isPrime IF n MOD divisor == 0 THEN isPrime = FALSE END divisor = divisor + 1ENDIF isPrime THEN PRINT "Prime"ELSE PRINT "Not prime"ENDExpected result: Prime.
Fibonacci sequence
count = 5first = 0second = 1FOR index FROM 1 TO count PRINT first next = first + second first = second second = nextENDExpected result: 0, 1, 1, 2, 3.
Greatest common divisor
Euclid's remainder method preserves the GCD and also handles a zero second argument. Inputs are non-negative integers, not both zero.
first = 12second = 8WHILE second != 0 remainder = first MOD second first = second second = remainderENDPRINT firstExpected result: 4.
Maximum of three values
first = 3second = 7third = 5maximum = firstIF second > maximum THEN maximum = secondENDIF third > maximum THEN maximum = thirdENDPRINT maximumExpected result: 7.
Why it works and what to test
Primality excludes 0 and 1, then tries divisors through the square root, inclusively. Test 1, 2, 4, 49, 97. Fibonacci retains just two terms; the temporary value saves their sum before either is overwritten. GCD visits (12, 8), (8, 4), (4, 0); (12, 0) immediately prints 12. Maximum starts with an input value so negative inputs work too.
Read divisibility and numeric sequences. Use small inputs within the executor’s step and precision limits.