aboutsummaryrefslogtreecommitdiffhomepage
path: root/std/Math.bruijn
diff options
context:
space:
mode:
authorMarvin Borner2024-03-10 14:18:17 +0100
committerMarvin Borner2024-03-10 14:18:17 +0100
commite4dc5918cdfc231bee29ca5808e37ee23f33712e (patch)
treeb73f9384964f96fe92ad6a08d393ba73b942a73c /std/Math.bruijn
parent6ae44d09faa0ae353c0818705503cad42127d102 (diff)
Samples and std additions
Diffstat (limited to 'std/Math.bruijn')
-rw-r--r--std/Math.bruijn15
1 files changed, 7 insertions, 8 deletions
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