Context
Now that we know how to build a quine, let's build it.Obviously, the shorter the code will be, the sorter the data will be as well, and same for the final quine. We'll see in next article how to obtain the data part easily
Initial state
- Memory: empty
- Cursor: first cell
- Input: any
Process
- In order to have a short code, we will build constants for + and > symbols, and print them as needed
- To go efficiently through our array, we should move those constants after each iteration (less expensive than going back to the array start every time)
- Therefore, we need to leave some space before setting data in memory, to store these constants at initialization, and then move them. 4 cells are enough.
- The final code looks like
- Move 4 cells to the left
- Store data (using + and > only)
- Go back to first cell
- Generate + and > symbols just before first cell
- Print > four times (to match the first row above, as this is outside data)
- Go to first array cell and iterate
- print + as many times as needed (and save a copy of the value)
- print > once
- move constants one cell to the left
- go to next cell
- Go back to first array cell and iterate
- print value
Code
>>>>
data (that ends with a >)
go to array start
<[<]
build PLUS and GT
<<<+++++++[->+++<]>[->++>+++<<]>+>-
print GT 4 times
....
go to first cell
>
[
print PLUS as many times as needed and save current data value
[-<<.<+>>>]
print GT
<.
move symbols
[->+<]<[->+<]
>>>
]
print code
<<<<[<]>[.>]
Final state
- Memory: uncleaned
- Cursor: who cares ?
- Input: unused - non-cheating quine !
- Output : 4 >, then data generation code, then data
To be continued...
Aucun commentaire:
Enregistrer un commentaire