diff options
author | Marvin Borner | 2023-03-04 00:07:39 +0100 |
---|---|---|
committer | Marvin Borner | 2023-03-04 00:07:39 +0100 |
commit | 023cc08c6702ceedeaa4ca3317b55c1d521e7d16 (patch) | |
tree | 2296e1ae315049c0888be7f44f47efc999bb408f /std/Number | |
parent | 52a4e7103e1d4d2150f8497aea45b95d6bb6f316 (diff) |
Added odd/even functions
Diffstat (limited to 'std/Number')
-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 |