Created
January 3, 2023 13:42
-
-
Save ytaki0801/a4a6ede76dd4a9fd1287f1d7f9c5776a to your computer and use it in GitHub Desktop.
Collatz Sequence on Cyclic Tag System in JavaScript/Node.js
This file contains 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
// Collatz Sequence on 2-tag system | |
// rule: {A -> BC, B -> A, C -> AAA}, value: AAA for 3, for example | |
// Translation from 2-tag system to cyclic tag system | |
const A = "100", B = "010", C = "001", S = " "; | |
const clist = [B+C, A, A+A+A, S, S, S]; | |
function printn(q) { | |
let n = 0; | |
while (q.length != 0 && q.slice(0, 3) == A) { | |
n += 1; q = q.slice(3); | |
} | |
if (q.length == 0 && n % 2 != 0) console.log(n); | |
} | |
const n = 39; | |
let queue = A.repeat(n), ci = 0; | |
printn(queue); | |
while (queue.length > 3) { | |
if (queue[0] == '1' && clist[ci] != S) queue += clist[ci]; | |
queue = queue.slice(1); | |
ci = (ci + 1) % clist.length; | |
if (ci == 0) printn(queue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment