diff options
author | Marvin Borner | 2024-03-14 13:53:46 +0100 |
---|---|---|
committer | Marvin Borner | 2024-03-14 13:53:46 +0100 |
commit | 0b77800262b5c46d994e6cb6159f773de8a05c51 (patch) | |
tree | 54e63cfea8fcc046072cb9e0028a12fd34937265 /std/Math.bruijn | |
parent | 004f853f260d321753af32318ecdeb2c585af7b0 (diff) |
More samples
Diffstat (limited to 'std/Math.bruijn')
-rw-r--r-- | std/Math.bruijn | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/std/Math.bruijn b/std/Math.bruijn index 78e3006..5952592 100644 --- a/std/Math.bruijn +++ b/std/Math.bruijn @@ -60,12 +60,15 @@ product L.foldl mul (+1) ⧗ (List Number) → Number :test (∏ (+1) → (+3) | ++‣) ((+24)) -# greatest common divisor -gcd z [[[1 =? 0 case-eq (1 >? 0 case-gre case-les)]]] ⧗ Number → Number → Number +# greatest common divisor using repeated subtraction +gcd* z [[[1 =? 0 case-eq (1 >? 0 case-gre case-les)]]] ⧗ Number → Number → Number case-eq 1 case-gre 2 (1 - 0) 0 case-les 2 1 (0 - 1) +# greatest common divisor using modulo (mostly faster than gcd*) +gcd z [[[=?0 1 (2 0 (1 % 0))]]] ⧗ Number → Number → Number + :test ((gcd (+2) (+4)) =? (+2)) (true) :test ((gcd (+10) (+5)) =? (+5)) (true) :test ((gcd (+3) (+8)) =? (+1)) (true) |