Skip to content

Commit

Permalink
Added lcm
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinborner committed Mar 21, 2024
1 parent 8b82e5d commit 93b53a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion samples/rosetta/hailstone.bruijn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ seq-27 hailstone (+27b)
:test (take (+4) <~>seq-27) ((+1b) : ((+2b) : ((+4b) : {}(+8b))))

all-below-100000 [0 : ∀(hailstone 0)] <$> seq
seq take (+1000) (iterate ++‣ (+1b))
seq take (+99999) (iterate ++‣ (+1b))

main [head (max-by (M.compare ⋔ tail) all-below-100000)]
8 changes: 8 additions & 0 deletions samples/rosetta/least_common_multiple.bruijn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:import std/Math .

lcm [[=?1 1 (=?0 0 |(1 / (gcd 1 0) ⋅ 0))]]

:test ((lcm (+12) (+18)) =? (+36)) ([[1]])
:test ((lcm (+42) (+25)) =? (+1050)) ([[1]])

main [[0]]
6 changes: 6 additions & 0 deletions std/Math.bruijn
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ gcd z [[[=?0 1 (2 0 (1 % 0))]]] ⧗ Number → Number → Number
:test ((gcd (+10) (+5)) =? (+5)) (true)
:test ((gcd (+3) (+8)) =? (+1)) (true)

# least common multiple using gcd
lcm [[=?1 1 (=?0 0 |(1 / (gcd 1 0) ⋅ 0))]] ⧗ Number → Number → Number

:test ((lcm (+12) (+18)) =? (+36)) (true)
:test ((lcm (+42) (+25)) =? (+1050)) (true)

# power function
pow […!!… (iterate (…⋅… 0) (+1))] ⧗ Number → Number → Number

Expand Down

0 comments on commit 93b53a5

Please sign in to comment.