diff options
-rw-r--r-- | std/Number/Ternary.bruijn | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/std/Number/Ternary.bruijn b/std/Number/Ternary.bruijn index dfed84c..7ebb978 100644 --- a/std/Number/Ternary.bruijn +++ b/std/Number/Ternary.bruijn @@ -435,6 +435,26 @@ mod ~‣ ∘∘ quot-rem ⧗ Number → Number …%… mod +# returns true if the number is even (remainder mod 2 == 0) +# TODO: faster solution (using tupling?) +even? z [[rec]] + rec =?0 case-end case-rec + case-rec t⁰? (lst 0) (1 /³0) ¬(1 /³0) + case-end true + +:test (even? (+0)) (true) +:test (even? (+1)) (false) +:test (even? (+41)) (false) +:test (even? (+42)) (true) + +# returns true if the number is odd (remainder mod 2 == 1) +odd? ¬‣ ∘ even? + +:test (odd? (+0)) (false) +:test (odd? (+1)) (true) +:test (odd? (+41)) (true) +:test (odd? (+42)) (false) + # returns max number of two max [[(1 ≤? 0) 0 1]] ⧗ Number → Number → Number |