Jump to content
BrainDen.com - Brain Teasers
  • 0


unreality
 Share

Question

VNA Riddles!!!

(1) Using VNA Code, make a program that copies itself to a new location 70 nodes forward while COMPLETELY ERASING its previous self in the process - it can leave no trace of itself behind.... the program must be as small & efficient as possible of course.

If nobody can get it after a little while, I may post some hints or my answer (I'm sure there are multiple ways to do it). For the shortest number of lines that I've made, open this spoiler:

Spoiler for number of lines my solution has:

1 :P Talk about efficiency

(2&3) Consider a new command, 'SPAWN' (it's not an actual command I've made but let's pretend it exists solely for riddles #2 and #3). Say that this command creates an entirely new program pointer at the node denoted by the SPAWN's a-parameter. The new program is completely independent of the other programs and also is now trying to win, just like the others. It's turn directly follows the program that spawned it.

(2) What is the fatal design flaw in this program? [there may be several]

COPY 3;50;0

COPY 3;b(-1);0

SHIFT 3;b(-2);4

EDITI 1;2;1

SHIFT 1;10;-1

BOMB 0;0;0

SPAWN sub(b(-6),6);0;0

EDITI -7;45;1

JUMP -8;0;0

(3) Now say that your only goal is to defeat the enemy program, so all of your SPAWNed programs are like your allies. Write a program that evolves via natural selection to build the optimal program for destroying the enemy. [This one is tough, I haven't attempted it yet, although I'm pretty sure it's possible :D]

(SPAWN is not an actual command and was only used for 2&3. It doesn't exist anymore for the rest of the problems :P)

(4) Write a program specifically to defeat this program before it overwrites you:

SHIFT 0;3;3

(5) Describe how you could use existing functions to create a random/pseudorandom/unpredictable 1-digit number as a result (there was a rand function in VNA 2.0 for a short time, but I removed it for many reasons - #5 is like creating your own rand function)

(6) Write a program that does something cool :D

Link to comment
Share on other sites

14 answers to this question

Recommended Posts

  • 0
nope :D Think of what that does: copies itself one node forward, then jumps 70 nodes forward. That achieves nothing ;D Nice try though :) hint:
You've got the right command

sorry, i got the wrong order...

SHIFT 0;1;70

Edit: Wait, no... this command

copys line a (1: a blank) into line b(the shift command) and then jumps to point c(70 nodes forward)

So which is it?

Edited by Mekal
Link to comment
Share on other sites

  • 0

The following is most likely to do what #1 assignment requires in just one statement, as long as there is no accidentally matching parameter somehwere. So, no guaranty.

SHIFT equ(b(-70),70,1,0);equ(b(-70),70,-70,70);equ(b(-70),70,0,70);

If I got it right, it is a puzzle in itself to see why and how it works. I'll hold off on the explanation for now. With that I am giving away a special and very useful technique implicit in SHIFT command. That technique, I think, was mostly unnoticed till now. In return, I expect UR to look into my post in the VNA topic in the "Games" forum and answer it. :)

The program with the SPAWN will obviously bomb itself soon enough. I would hold off on implementing that command for now.

As a side note, most people on this forum don't even know what we are discussing here. For that matter, shouldn't this puzzle be in the Games forum?

Link to comment
Share on other sites

  • 0

Prime: you are superclose on #1. So close that I'm going to post the solution:

SHIFT equ(b(70),70,-1,0);equ(b(70),70,0,70);equ(b(70),70,70,0)

it works like this:

* round one: copies itself into node 70 and then jumps 0 (back to itself)

* round two: copies the line right before it onto itself, then jumps 70 (to the new copy of itself)

The line right before doesn't have to be a BLANK (although BLANK is probably ideal). It could be anything, all that matters is that it's overwriting itself before it jumps off.

This program presumes that b(140) is not 70 already, which is a pretty safe presumption

** Prime's may work too, even though it's slightly different. I'll analyze it in a sec

For Prime's answer to #4, not necessarily ;D The concept takes advantage that the VNA is 200 nodes long, which is not divisible by 3. Only 2 of 3 iteration starting points would result in a potential overwrite (the third will become one of them on the next cycle around). 1 of those 2 gets bombed and you win, but the other one would overwrite your bomb, thus you copying it backwards would just be copying the same program backwards, so when the program cycles back around, it will overwrite your program. This doesn't mean you have lost the game (just an infinite tie), but the conditions of the riddle require you destroy the program before it overwrites you. The possible starting positions of the other program lead to 1 of 3 different positions when it's closest to you:

1

2

3

SHIFT 1;-3;0

BOMB 0;0;0

1 - good job, your program wins

2 - your program loses (it gets overwritten, causing the infinite loop that the riddle question says counts as losing)

3 - this one misses both of your lines, but in 66 rounds it will have gone 198 lines farther, putting it at position 1 (which is your victory)

So while you still have a 2/3 chance of definite victory, 1/3 of the time (depending on starting placement), the other program will overwrite yours

#5: Obviously 'rand' is unnecessary, or I wouldn't have removed it :P The point of the question was how you could artificially make an unpredictable function (yet constrained to one digit)

[edit - typo]

Edited by unreality
Link to comment
Share on other sites

  • 0

Here is the answer to #4 (mine at least, there are probably more ways)

SHIFT 1;equ(b(-3),3,-3,-2);0

BOMB 0;0;0

It works because it's impossible for both -3 and -2 to both have the SHIFT line, because if one does, then it gets bombed. Prime was very close on this one, his just had a 1/3 chance of being overwritten, this has 0

Link to comment
Share on other sites

  • 0

Your program (for #1) is a two-step process, which 1) copies itself 2) Erases itself and jumps to new location.

Mine: 1) erases its old copy left 70 paces behind; 2) Copies itself to new location and jumps.

First, I came up with the solution identical to yours, but then opted for the second variation as it seems to be better in a combat situation.

Why:

After the program copies itself in the first step, it has two points of vulnerability: 1) The same location where it is going to execute its second step, and 2) The location where its new copy resides and where it plans to jump in another step.

Whereas second variation has only one point of vulnerability at all times -- the location it is going to execute on the very next step.

Your comment with respect to #4 solution duly noted. I forgot to protect the bomb. However, here is another way to take care of it simply:

SHIFT 3;-3;0

BLANK

BLANK

BOMB 0;0;0

Link to comment
Share on other sites

  • 0
COPY 3;50;0

COPY 3;b(-1);0

SHIFT 3;b(-2);4

EDITI 1;2;1

SHIFT 1;10;-1

BOMB 0;0;0

SPAWN sub(b(-6),6);0;0

EDITI -7;45;1

JUMP -8;0;0

this programs doesn't even use the two bold lines

Actually, it does. It copies those lines into the location where the SPAWN command creates a new independent pointer. The latter will take on the life of its own and proceed to bomb its parent. Also, after 9 itterations or so of the main program, the spawned program would land right on top of the parent program if it were alive at that point.

Link to comment
Share on other sites

  • 0

Prime: ah I see your point about #1, cool idea B)) My first thought was that if another program happened to land on the previous line, it would copy onto you, but it would be the same already, so it's no problem. Good improvement!

for #4, yeah I'm sure there's even more ways to do it

DMS: actually those lines AND the next one (the bomb). But they are the lines being copied for the new spawn program. But as Prime pointed out, they will overrun the "parent program"

Other answers to #2:

- even if they bomb the enemy, THEY win, not you

- they'll probably bomb you first anyway

- there were some other structural problems, I don't remember them now :P

so #1 is solved, #2 is solved, #3 is unattempted [even by me so far, haven't had the time], #4 is solved (two ways so far), #5 is unattempted, #6 is not really a problem :P

Good job guys! ;D

Edited by unreality
Link to comment
Share on other sites

  • 0

answer time :P

SHIFT equ(b(70),70,-1,0);equ(b(70),70,0,70);equ(b(70),70,70,0)

or, Prime's tweak makes less of a danger area and is thus a better battler:

SHIFT equ(b(-70),70,1,0);equ(b(-70),70,-70,70);equ(b(-70),70,0,70)

#2 is easy to spot, has multiple flaws, and is almost as much a matter of opinion, so no real spoiler needed anyway :D

#3 - I still haven't gotten around to this ;D Has anyone?

my solution:

SHIFT 1;equ(b(-3),3,-3,-2);0

BOMB 0;0;0

Prime's solution:

SHIFT 3;-3;0

BLANK

BLANK

BOMB 0;0;0

probably many other ways. My solution is guaranteed to get rid of the enemy on its first approach (it doesn't really matter), provided that the enemy is indeed the one described the riddle. The only benefit from this is a quicker match, so in effect both programs do the same thing :D

add up the a, b, and c parameters of the whole array (or some other combination like just a, or just a and b, or only every 3rd line, or whatever you want) and then mod 10. This gives you a single, unpredictable, dare I say it, pseudorandom, digit. While your own program may affect your output, you have no control over the enemy program. Notice how I said "describe" how you could use functions - to actually make such a pointless function would be pretty dull, even with copy-paste

Another solution that just came to me is to use a complex and large nesting of com functions or its derivatives (equ,leq,geq) to basically add up the number of lines until you hit the enemy program. You may have to have all 200 prepared inside but only add +1 for ones until some special com function tells you that you've found the enemy program (whatever method you want to use for detecting it, although some programs leave false alarms behind, or hop, etc, so it may be a dangerous bet) and then +0 from there. Since this distance is based off of a random number calculated before the match, it's pretty decent. Then mod10.

There are probably other ways, all of them involving massive and impractical nested functions :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...