Explanation to come ###How it works at the low level
To start we have O R ^ V
this serves to take input on the first loop and works as a no-op all other times.
We then use O
to make a copy of the input for later.
@ A K T
recalls the variable stored in memory position -1 (at the beginning of the program this is 0) and A J
increments it. O @ A K U
Stores the now incremented value back in memory position -1 for our next loop around.
N
calculates the mod of the copy of the input we made a while back and the value just recalled from memory and R
negates it.
Together N R
create a boolean that indicates whether or not the our input is divisible by the TOS.
We store a copy of this boolean to memory space -2 using O @ B K U
and recall the value from memory space -2 using @ A K T
.
We swap the top two elements with Q
to ensure that the boolean is on top and output the value if the boolean is true using ^ X
.
If the boolean was false we have an extra value that needs to be eradicated so we recall the boolean we stored in space -2 with @ B K T
and pop a value if it is false R ^ P
.
We duplicate the input value with O
and subtract the value at memory -1 with @ A K T K
. If this is zero we exit R ^ _
.
Lastly we have @ ^
this skips whatever the next value is. We need this because there is a bunch of junk (actually only a @
symbol) generated by the visible portion of the code.
Once it reaches the end it loops back to the beginnning.
###How it works at the high level
The basic idea is that we have a value primarily stored at memory location -1 that is incremented each time we loop. If that value divides our input we output it and when the two are equal we end execution.