Created
June 8, 2024 12:33
-
-
Save avitkauskas/4e35b2d8fb4b61dad552cac343e566f9 to your computer and use it in GitHub Desktop.
Exploding Dots Machine
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
(ns dots-machine.core) | |
(defn representation | |
"Create a string representation of the digits in dot-machine notation." | |
[explode create digits] | |
(apply str create "←" explode ": " | |
(map (fn [digit] (if (< digit 10) digit (char (+ 87 digit)))) digits))) | |
(defn dots-machine | |
"Transform the decimal `number` using the `create<-explode` dot-machine." | |
[explode create number] | |
{:pre [(> explode create 0) (>= number 0)]} | |
(loop [carry number | |
digits '()] | |
(if (= 0 carry) | |
(representation explode create digits) | |
(recur | |
(-> carry (quot explode) (* create)) | |
(conj digits (rem carry explode)))))) | |
(comment | |
(dots-machine 2 1 2024) ; "1←2: 11111101000" | |
(dots-machine 8 1 2024) ; "1←8: 3750" | |
(dots-machine 16 1 2024) ; "1←16: 7e8" | |
(dots-machine 16 2 2024) ; "2←16: 2ec8" | |
(dots-machine 16 8 2024) ; "8←16: 88888808" | |
(dots-machine 3 2 2024) ; "2←3: 2120222122021112" | |
(dots-machine 4 3 2024) ; "3←4: 321020110103231130120" | |
(def dot2<-3 (partial dots-machine 3 2)) | |
(dot2<-3 5) ; "2←3: 22" | |
(dot2<-3 7) ; "2←3: 211" | |
(mapv dot2<-3 [1 2 3 5 8 13 21])) | |
; ["2←3: 1" | |
; "2←3: 2" | |
; "2←3: 20" | |
; "2←3: 22" | |
; "2←3: 212" | |
; "2←3: 2121" | |
; "2←3: 21220"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on James Tanton’s Exploding Dots™ Machine (https://globalmathproject.org/wp-content/uploads/2020/09/Written-Guide-EXPERIENCE-9_2020_English.pdf)