From e4dc5918cdfc231bee29ca5808e37ee23f33712e Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 10 Mar 2024 14:18:17 +0100 Subject: Samples and std additions --- std/Math.bruijn | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'std/Math.bruijn') diff --git a/std/Math.bruijn b/std/Math.bruijn index 58da709..62d04e0 100644 --- a/std/Math.bruijn +++ b/std/Math.bruijn @@ -12,6 +12,13 @@ sum foldl add (+0) ⧗ (List Number) → Number :test (∑((+1) : ((+2) : {}(+3)))) ((+6)) +# digit sum of all values +digit-sum sum ∘ number→list ⧗ Number → Number + +:test ((digit-sum (+0)) =? (+0)) (true) +:test ((digit-sum (+10)) =? (+1)) (true) +:test ((digit-sum (+19)) =? (+10)) (true) + # returns max value of list lmax foldl1 max ⧗ (List Number) → Number @@ -22,14 +29,6 @@ lmin foldl1 min ⧗ (List Number) → Number :test (lmin ((+2) : ((+1) : {}(+0)))) ((+0)) -# converts number to list of its digits -digits z [[rec]] ⧗ Number → (List Number) - rec =?0 case-end case-rec - case-rec (1 (0 / (+10))) ; (0 % (+10)) - case-end empty - -:test (digits (+0)) (empty) - # list from num to num {…→…} z [[[rec]]] ⧗ Number → Number → (List Number) rec (1 =? ++0) case-end case-list -- cgit v1.2.3