From f341a5c3ce2ec13e27b2dcfec3c6f7043f37a7a8 Mon Sep 17 00:00:00 2001
From: noe
Date: Tue, 18 Jun 2024 15:22:04 -0400
Subject: [PATCH] dollcode: decode
---
dollcode/index.html | 34 +++++++++++++++++++++++++++++++---
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/dollcode/index.html b/dollcode/index.html
index 20d91ab..c6fcd2d 100644
--- a/dollcode/index.html
+++ b/dollcode/index.html
@@ -47,12 +47,14 @@
- input a number
+ input a number or dollcode
+
+
@@ -98,6 +100,22 @@
return output.join("");
};
+ const parseDollcode = (code) => {
+ // reverse the nibs!
+ const nibs = code.trim().split("").reverse();
+
+ console.log({ nibs });
+
+ return nibs
+ .map((nib) => (nib === "▖" ? 1 : nib === "▘" ? 2 : 3))
+ .reduce((acc, val, index) => {
+ const r = val * Math.pow(3, index);
+ const res = r + acc;
+ console.log({ acc, val, index, r, res });
+ return res;
+ }, 0);
+ };
+
const setOutput = (t) => {
document.querySelector("#output").innerHTML = t;
};
@@ -108,9 +126,19 @@
const updateEvent = () => {
const id = document.querySelector("#id").value;
- const number = parseInt(id, getIDRadix());
- setOutput(genCode(number));
+ if (document.querySelector("#dollcode").checked) {
+ const number = parseDollcode(id);
+ console.log({ number });
+ setOutput(
+ `- dec: ${number.toString(10)}
- hex: ${number.toString(
+ 16
+ )}
`
+ );
+ } else {
+ const number = parseInt(id, getIDRadix());
+ setOutput(genCode(number));
+ }
};
document.querySelectorAll("input").forEach((x) => {