Last active
December 14, 2023 17:51
-
-
Save kbridge/0e9050462bdfaaf89562e3d24eba0c43 to your computer and use it in GitHub Desktop.
ocaml implementation of a puzzle operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Puzzle = struct | |
let (+) a b = | |
let rec work accum base remain = | |
if remain = 0 | |
then accum | |
else work | |
(Int.add accum (remain mod b * base)) | |
(base * 10) | |
(remain / b) | |
in | |
work 0 1 a | |
end |
utop [0]: #use "puzzle.ml";;
module Puzzle : sig val ( + ) : int -> int -> int end
utop [1]: Puzzle.(5 + 5);;
- : int = 10
utop [2]: Puzzle.(6 + 3 + 7 + 10);;
- : int = 26
utop [3]: Puzzle.(6 + 4);;
- : int = 12
utop [4]: Puzzle.(8 + 4 + 9);;
- : int = 22
utop [5]: Puzzle.(3000 + 333 + 30 + 3);;
- : int = 1020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://puzzling.stackexchange.com/questions/124653/a-strange-operator-on-my-new-calculator