r/adventofcode • u/topaz2078 (AoC creator) • Dec 23 '15
Upping the Ante [Day 23] Further Exercises
- Everyone's VM implements the same algorithm. What is it?
- The VM uses an initialization sequence that can construct any number using only
incandtpl. What algorithm can you use to produce such a sequence for any number? - What other math can you construct using only the existing features of the VM?
5
Upvotes
9
u/boowhitie Dec 23 '15
http://xkcd.com/710/
4
u/[deleted] Dec 23 '15 edited Dec 23 '15
Sample for
n= 50: http://pastebin.com/STzwgWFzIt's far from efficient, of course.
1
u/[deleted] Dec 23 '15
Is it Collatz conjecture? Seeing "adding one", "multiplying by three" and "dividing by two" sounds familiar.
2
u/markgritter Dec 23 '15
I'm pretty sure it's counting iterations of the Collatz conjecture. My 'A' register goes ... 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1.
As far as #2, the trivial version is just to represent the number in base 3. Then build the 1st digit (most significant) with inc, triple to move onto the next-most-significant digit, etc.
2
u/markgritter Dec 23 '15 edited Dec 23 '15
Here is a program which checks divisibility by 5, of the number in the "A" register, as long as it's greater than 0. It sets "B" to either "5" (if divisible) or "0" (if not)
Having no decrement nor copy is a pain. If we assume that HLF rounds down then this program can be simplified. (Also there's an unnecessary JMP because of the way I constructed it.)
2
u/askalski Dec 23 '15
Do you mean something like this implementation of Day 4 in the Collatz VM?
2
u/jonathan_paulson Dec 24 '15
Write the number in base 3. Use inc ton construct each digit, and tpl to switch to the next digit. This is optimal.
For example, for 7 (21 in base 3) the sequence is
1
u/Johnicholas Dec 23 '15
There's a recipe here: https://en.wikipedia.org/wiki/Counter_machine
I think with some modifications, we might be able to follow that recipe in order to show that the day 23 language is turing complete?
1
u/Aushin Dec 23 '15
This is probably the first reference to something (wondrous numbers) that you've made that I recognized!
1
u/randrews Dec 23 '15
This is actually how I solved it. I had a bug originally (stupid typo), and my program didn't halt. I figured I'd trace through and do it by hand. It didn't take me long to figure out what it was doing, so I found an online Collatz-conjecture-solver thing, plugged in two numbers and got it right. :)
Then went back and fixed my code of course.