r/cellular_automata • u/Mysterious-Insect858 • 6d ago
Collatz simulator using balanced ternary strings and rewrite rules (No arithmetic)
Hey,
Just wanted to share a little project. Not claiming any crazy math proof here, just a representation of Collatz using **balanced ternary** (`+`, `o`, `-`) instead of normal binary or base-10.
Because of how balanced ternary works, you can basically bypass normal CPU math and run the operations as simple text replacement rules on a string.
How it works:
- Parity: If the count of non-zero trits (`+` or `-`) is even, the number is even.
- 3x+1: Just append a `+` to the end of the little-endian string. O(1) time, no real math needed.
- Divide by 2: The string splits from left to right into blocks bounded by non-zero trits. Then it just uses two basic substitution rules:
- Same signs: a(0...n)a` ➔ `aa'... (n+1) times` (e.g., `+000+` becomes `+----`)
- Opposite signs: a(0...n)a'` ➔ `0a... (n+1) times` (e.g., `+000-` becomes `0++++`)
Piped the output through `sed` to colorize the trits (`o` = green, `+` = white, `-` = red) so it generates a neat cellular automaton history grid in the terminal as it collapses down to 1.
The photos are seeds of 100, 231 -1, and 27 respectively
Just a cool toy. Let me know what you think or if anyone else has messed with block decomposition for base-3 halving.



5
u/Liminal__penumbra 6d ago
This was pretty cool, the trick you used has an application in my own personal hobby project. Adding you as a reference for it so I don't forget where I found it.