Alright, so we know how to build an arbitrary string consisting of a-fh (as well as A-FH, by making use of the c operator). It turns out that there exists a string consisting of only a-hA-H, such that it turns into the desired output after applying an a followed by 14 ps (don't quote me on this number). We can calculate this string in many ways, such as with dynamic programming.
Alright, so we know how to build an arbitrary string consisting of a-f (as well as A-F, by making use of the c operator). It turns out that there exists a string consisting of only a-hA-H, such that it turns into the desired output after applying an a followed by 14 ps (don't quote me on this number). We can calculate this string in many ways, such as with dynamic programming.
Alright, so we know how to build an arbitrary string consisting of a-h (as well as A-H, by making use of the c operator). It turns out that there exists a string consisting of only a-hA-H, such that it turns into the desired output after applying an a followed by 14 ps (don't quote me on this number). We can calculate this string in many ways, such as with dynamic programming.
Alright, so we know how to build an arbitrary string consisting of a-f (as well as A-F, by trivially modifyingmaking use of the algorithmc operator). It turns out that there exists a string consisting of only a-fAhA-FH, such that it turns into the desired output after applying an a followed by 14 ps (don't quote me on this number). We can calculate this string in many ways, such as with dynamic programming.
Alright, so we know how to build an arbitrary string consisting of a-f (as well as A-F, by trivially modifying the algorithm). It turns out that there exists a string consisting of only a-fA-F, such that it turns into the desired output after applying an a followed by 14 ps (don't quote me on this number). We can calculate this string in many ways, such as with dynamic programming.
Alright, so we know how to build an arbitrary string consisting of a-f (as well as A-F, by making use of the c operator). It turns out that there exists a string consisting of only a-hA-H, such that it turns into the desired output after applying an a followed by 14 ps (don't quote me on this number). We can calculate this string in many ways, such as with dynamic programming.
This was a very interesting puzzle to solve. I will add an explanation soon;solve; note that this is definitely not the cleanest solution.
Explanation
The main idea is to generate a long string of letters, and then perform a single a operation to convert it to the desired output. By itself, there is no such sequence of letters which lead exactly to the first 50 digits of pi. To increase our chances, we can instead find a sequence that works after performing some number of p operations. To illustrate this, if p=1, we would need to find a sequence of letters that decodes to the below (the ?s are wildcards):
?????1??41?5?92??6?535?89793?2??3846?264?3?383?27950?28841?9?71?69?399?3?7510
And for p=2:
??????????????1?????41??5?92?????6?5?35??8?979?3?2???3846??2?64??3??38?3??2795?0?2?8841??9?71?69??39?9??3??7?510
As you can see, the position of the digits become more sparse, therefore there is more room for a valid letter sequence to exist.
The next part is figuring out how to build this letter sequence. First, notice that a command with 33 hs followed by 7 ?s appends exactly one h to the buffer. Second, take note of the a and r operations, which increments and rot13s each character, respectively. Using these two facts, we can effectively append every letter from a to h.
For example, to append c to abg, we can take these steps:
- Perform
aaaaa, soabgbecomesfgl - Perform 33
hs + 7?s, sofglbecomesfglh - Perform
aaaaaaaa, sofglhbecomesnotp - Perform
n, sonotpbecomesabgc
Alright, so we know how to build an arbitrary string consisting of a-f (as well as A-F, by trivially modifying the algorithm). It turns out that there exists a string consisting of only a-fA-F, such that it turns into the desired output after applying an a followed by 14 ps (don't quote me on this number). We can calculate this string in many ways, such as with dynamic programming.
In essence, this is how the algorithm works. The actual code actually applies another optimization that decreased my score from 30K to <10K. That is, instead of using 33 hs and 7 ?s every time we want to append, we can instead use 5 hs and 1 ?, which creates the string hel. Note that this requires more ps so that the digits are sparse enough for a solution to exist.
This was a very interesting puzzle to solve. I will add an explanation soon; note that this is definitely not the cleanest solution.
This was a very interesting puzzle to solve; note that this is definitely not the cleanest solution.
Explanation
The main idea is to generate a long string of letters, and then perform a single a operation to convert it to the desired output. By itself, there is no such sequence of letters which lead exactly to the first 50 digits of pi. To increase our chances, we can instead find a sequence that works after performing some number of p operations. To illustrate this, if p=1, we would need to find a sequence of letters that decodes to the below (the ?s are wildcards):
?????1??41?5?92??6?535?89793?2??3846?264?3?383?27950?28841?9?71?69?399?3?7510
And for p=2:
??????????????1?????41??5?92?????6?5?35??8?979?3?2???3846??2?64??3??38?3??2795?0?2?8841??9?71?69??39?9??3??7?510
As you can see, the position of the digits become more sparse, therefore there is more room for a valid letter sequence to exist.
The next part is figuring out how to build this letter sequence. First, notice that a command with 33 hs followed by 7 ?s appends exactly one h to the buffer. Second, take note of the a and r operations, which increments and rot13s each character, respectively. Using these two facts, we can effectively append every letter from a to h.
For example, to append c to abg, we can take these steps:
- Perform
aaaaa, soabgbecomesfgl - Perform 33
hs + 7?s, sofglbecomesfglh - Perform
aaaaaaaa, sofglhbecomesnotp - Perform
n, sonotpbecomesabgc
Alright, so we know how to build an arbitrary string consisting of a-f (as well as A-F, by trivially modifying the algorithm). It turns out that there exists a string consisting of only a-fA-F, such that it turns into the desired output after applying an a followed by 14 ps (don't quote me on this number). We can calculate this string in many ways, such as with dynamic programming.
In essence, this is how the algorithm works. The actual code actually applies another optimization that decreased my score from 30K to <10K. That is, instead of using 33 hs and 7 ?s every time we want to append, we can instead use 5 hs and 1 ?, which creates the string hel. Note that this requires more ps so that the digits are sparse enough for a solution to exist.