EXAPUNKS

EXAPUNKS

View Stats:
Trash World News #3 optimization...
According to the histograms, it is possible to solve this puzzle in ~579 instructions -- and, in fact, this is the most common solution (by a large margin). I can't see how this is possible.

The optimum solution that I can find sends one XEA to grab the file that needs to be changed (#1) while another grabs the file with the "find" / "replace" pairs of words (#2). The overall logic is:

#1 Sends a message with the current word, backs up one, waits for a message and writes the message to the file. It repeats this process until it hits EOF, at which point it walks back to the starting node, kills the other XEA, and finishes the puzzle (moves 200 to outbox)

#2:
1) Reset to begining of file,
2) Receives a message into X,
3) checks for EOF
- if EOF, send a message with the contents of X and goto #1
4) Checks to see if the value in the file matches the value in X
- If so, it sends a message with the next value in the file, backs up 2, deletes two values from the file, and goto #1
5) Skip 1, goto 3

Note that #2 has no exit condition -- this is why #1 has to drop by and kill it.

This may not be optimial, but it should be fairly close. The absolute minimum runtime would be 73 [words in long file] * 1/2 [assuming that words to be replaced are distributed evenly among the long file] * 5 [pairs of words to be replaced] = 182.5 -- but this assumes that a single instruction can read a value from the long file, compare it with a value from the short file, and output the correct value in the correct place in the long file. Since there is no such instruction, the execution time is going to be longer, and frankly it is going to be *much* longer.

If multiple XEA's could read a single message of the bus it *might* be possible (5x copies of #2, each one positioned to compare a single word, only outputing a word if there is a match, and #1 configured to pause while the comparisons occur to see if a message appears ("TEST MRD") ) but this isn't possible -- and if you have to send out 5x copies of each word you lose much of the benefit (not only will you spend more time sending out multiple copies of each words, you'll still have to NOOP to ensure that all comparison XEA's have had an opportunity to send a message if they are going to).

My conclusion is that the historgram's weren't reset prior to release, and this puzzle was changed in the release version.
< >
Showing 1-5 of 5 comments
No, you can get 579 in the current version. My strategy is

1 - Grab the file with the words to replace
2 - Link 800, spawn a guy to carry the file to outbox, link 799. The original EXA is now in the host with the file to be changed, carrying the file with the substitutions
3 - Copy the current word to X. (The advances the cursor, so the file is now pointing to the value to change it to)
4 - Spawn a new EXA to grab the file to be changed (He inherits the value of X, the original word to be replaced)
5 - The original copies F to M (Meaning, he's trying to transfer the new value for the first word, and waits until the other exa can pick it up)
6 - The second exa searches through the file until it finds the word, replaces it with the value from M, then halts
7 - Repeat 3 - 6 until the original exa reaches EoF
8 - Original Exa halts

TLDR: Don't try to replace all the words at once. Pick a word, replace it, then move on to the next. It's faster, even if you have to search through the text for each word.
ohh man this is so much better then what i did
Yeah, this video was posted a bit after I made my original post with a more efficent solution:

https://youtu.be/mJd4dDuK6FE?t=6m48s

The key is to get the inner loop (the one that iterates the most frequently) down to *two* instructions for the most common case (where a match isn't found).

Specifically:

COPY M X
MARK INNER_LOOP
TEST F = X
FJMP INNER_LOOP

A tight loop like this is only possible:

1) The inner loop iterates over the long string to be searched (file 212).
2) You realize that the exit condition will always fire-- each and every "string to be searched for" is guranteed to appear in the "string to be searched".

For those who were wondering, here is the INNER_LOOP that I came up with (running on file 212).

COPY F X
MARK INNER_LOOP
COPY M T
FJMP EOF_FAIL
TEST X = T
TJMP FOUND_MATCH
VOID M
JUMP INNER_LOOP

The logic in the XEA scanning 200 would return a 0 if and only if it hit EOF, thus the "COPY M T" / "FJMP EOF_FAIL" logic. This takes 3569 to complete.

Realizing that this was very slow, I then moved the inner loop from the long file (212) to the short file (300), reducing the number of messages that needed to be exchanged. This results in :

COPY M X
TEST X = 1
TJMP DONE
SEEK -9999
MARK INNER_LOOP
TEST EOF
TJMP EOF
TEST X = F
SEEK +1
FJMP INNER_LOOP

Which, now that I'm reviewing it in detail, takes the same amount of time to execute... :) However, I did pickup some addition efficency in this solution elsewhere (by deleting pairs of strings from file 300 after I used them) to get the time to complete down to 2119.

I love these games... :)
My score is 573 using 3 exas. One is just to grab the file and move it to dropbox and die. Second is "reader" who grabs the file with pairs to find and replace and just reads them in sequential order to M (message queue) and dies on reaching end of file.

All the replace logic is in the third exo which grabs the file to be rewritten. Reads value from M and uses a loop to find that value in file. Move back one (SEEK -1) , read second value from M and writes it to file = value is replaced. Repeat while there is a message to be read (TEST MRD).
I did something very similar, but mine is 554 cycles. The only difference I can see is that I never check for the end of transmission, I have the reader come over and kill number 2
< >
Showing 1-5 of 5 comments
Per page: 1530 50