#[Sesos][1], <s>67</s> 66 bytes
Edit: Saved a byte by using another `get` instead of a loop.
[**Try it online**][2]
The hexdump:
0000000: 16f8be 76ca83 e653e3 b472f0 750ef0 af9f1f fcebbb ...v...S..r.u........
0000015: 7f7ec6 777dc3 777e83 ee53c2 e05f3f 3ff8d7 77ffdc .~.w}.w~..S.._??..w..
000002a: 8e7f80 27de3b 4741f7 79efd8 8fefdc 367ee7 70afd4 ...'.;GA.y.....6~.p..
000003f: 38cd7c 8.|
**This is the Sesos assembly code that I wrote**, which is assembled into the above binary to be executed:
set numin
set numout
get
jmp ; n += (n==2)
sub 1
fwd 1
add 1
fwd 1
add 1
rwd 2
jnz
add 2
fwd 1
jmp
sub 1
rwd 1
sub 1
fwd 1
jnz
add 1
rwd 1
jmp
fwd 1
sub 1
rwd 1
get
jnz
fwd 1
jmp
sub 1
fwd 1
add 1
rwd 1
jnz
fwd 1
jmp ; list from n to 1
jmp
sub 1
fwd 3
add 1
rwd 3
jnz
fwd 3
jmp
sub 1
fwd 3
add 1
rwd 6
add 1
fwd 3
jnz
fwd 3
sub 1
jnz
rwd 6 ; List [n, n-1, ..., 2, 2]. We don't want n%1.
add 1
rwd 6
jmp
rwd 6
jnz
fwd 6
jmp ; move n one cell to the left
sub 1
rwd 1
add 1
fwd 1
jnz
add 2 ; copy the n's
jmp
rwd 1
jmp
sub 1
fwd 3
add 1
rwd 3
jnz
fwd 3
jmp
sub 1
fwd 3
add 1
rwd 6
add 1
fwd 3
jnz
fwd 4
jnz
rwd 7
jmp ; compute each divmod, only the n%d results will be used
jmp
sub 1
fwd 1
sub 1
jmp
fwd 1
add 1
fwd 2
jnz
fwd 1
jmp
add 1
jmp
sub 1
rwd 1
add 1
fwd 1
jnz
fwd 1
add 1
fwd 2
jnz
rwd 5
jnz
rwd 6
jnz
fwd 8
jmp ; go to first modulus of zero, or past end of list
fwd 6
jnz
fwd 1 ; negate cell to the right
jmp
rwd 1
add 1
fwd 1
jmp
sub 1
jnz
jnz
add 1
rwd 1
jmp
fwd 1
sub 1
rwd 1
sub 1
jnz
fwd 1 ; output
put
---
###Explanation (In BF, since I actually wrote it in BF first)
Sesos and BF are closely related, so I will write the explanation in BF to take less space (it won't be on as many lines):
> fwd 1
< rwd 1
+ add 1
- sub 1
, get
. put
[ jmp
] jnz
First, Sesos is basically BF, but there is some I/O help, using the assembler directives `set numin` and `set numout`. These allow me to take an unbounded integer as input, into a single cell, or output that cell as an integer. I decided this was the easiest way to write the program for all positive integers.
My explanation is of each section from the above code, with sub-explanations showing the manipulations of the tape, in an attempt to help you understand the process and algorithm. I put the tape in curly braces, and use `>` to denote the pointer's location on the tape.
**Section 1, the bug-fix / edge case:**
It should be noted that before I fixed this, my code was only **54 bytes**. Because of how I determine if a number is prime later, I had to add one to `n` if `n==2`, so I do that first. I use a `,` here (`get`) to zero a cell instead of looping with `[-]`.
[->+>+<<]++>[-<->]+<[>-<,]>[->+<]>
n += (n==2):
goal 1: { 2 n n }
goal 2: { 0 n==2 n }
goal 3: { 0 0 n* }
{ n 0 0 }
[->+>+<<]++>
{ 2 >n n }
[-<->]+<[>-<,]>
{ 0 >n==2 n }
[->+<]>
{ 0 0 >n* }
**Section 2, the list and my ultimate goal:**
The way I check if `n` is prime is to check `n` modulo every number from `n-1` to `2`, which I figured would be simplest. My main goal was to reach the following data structure:
0 >{n n-1 0 0 0 0, n n-2 0 0 0 0, ..., n 2 0 0 0 0}
This facilitates the [DivMod algorithm][3] I planned to use, which requires `n d 0 0 0 0` on the tape.
So I create a list from n-1 to 0, with the necessary spacing. I copy the first marked cell to the second, then copy that temp cell back into the original and into the next. Then subtract one. This repeats until I hit zero.
0 { 0 >n }
[[->>>+<<<]>>>[->>>+<<<<<<+>>>]>>>-]
0 {0 n 0 0 0 0, 0 n-1 0 0 0 0, ..., 0 2 0 0 0 0, 0 1 0 0 0 0, 0 >0 0 0 0 0}
^ ^ ^
Then, make the last section find `n%2`, since `n%1` would cause a result of `0` for every `n`. Changing it to a zero instead of a two produces the wrong answer for `n=1`. After that, move back to `n`.
<<<<<<+
<<<<<<[<<<<<<]>>>>>>
0 {0 >n 0 0 0 0, 0 n-1 0 0 0 0, ..., 0 2 0 0 0 0}
Move n left one cell, preparing to copy it across the list:
[-<+>]
0 {n >0 0 0 0 0, 0 n-1 0 0 0 0, ..., 0 2 0 0 0 0}
**Section 3, copy the n's**
I copy `n` to the correct position for each entry in the list, so that I'll be ready to use the DivMod algorithm for each entry. I first add two here, so that we find another `n%2`, rather than `n%0`. This is nearly the same code as in section 2, except that I compare to the cell on the right each time, in order to stop upon completing the length of the list.
++[<[->>>+<<<]>>>[->>>+<<<<<<+>>>]>>>>]
0 {n 2 0 0 0 0, n n-1 0 0 0 0, ..., n 2 0 0 0 0, n >0 ...}
^ ^ ^
**Section 4, compute each DivMod**
I go through the list, doing the algorithm for each, after which only the `n%d` results are used. Though the algorithm only lists 4 cells on the site, it relies on the 5th and 6th cells being zero for its magic to work. I used the version which does not preserve `n`, since I won't need it anymore.
[The algorithm][3]:
# >n d 0 0 0 0
[->-[>+>>]>[+[-<+>]>+>>]<<<<<]
# >0 d-n%d n%d n/d 0 0
As applied across the list (`x` marks stuff I don't *really* need, but do make use of later):
[
[->-[>+>>]>[+[-<+>]>+>>]<<<<<]
<<<<<<
]>>>>>>>>
0 {0 x >n%(n-1) x 0 0, 0 x n%(n-2) x 0 0, ..., 0 x n%2 x 0 0}
**Section 5, if any n%d == 0**
I check the list from left to right.
{0 x >n%(n-1) x 0 0, ...}
[>]
What? You expected more? Well it really is that simple. This stops at the first occurrence of `0`, which is either *in* this list, meaning the number is *not* prime, since it has a divisor, or we went past the list, and the number is therefore prime.
**Section 6, negate the cell to the right and output**
Uses [this algorithm][4]:
temp0[-]
x[temp0+x[-]]+
temp0[x-temp0-]
I don't need the first line, since my `temp` is already zero. I also use `get` to zero a cell instead of a loop. The last line prints the resulting number, a one if prime, or a zero if not.
>[<+>,]+
<[>-<-]
>.
**Concluding remarks**
Overall, this was a fun challenge. I found the mapping to BF pretty quickly with trail and error using the interpreter and the documentation. I completed it with something like 8 hours of effort. Much of the writing occurred in Notepad++ in BF that I then converted to Sesos with a Python program, tested, and debugged.
[**Convert BF to Sesos**][5]
[1]: https://github.com/DennisMitchell/sesos
[2]: http://sesos.tryitonline.net/#code=c2V0IG51bWluCnNldCBudW1vdXQKZ2V0CgpqbXAJOyBuICs9IChuPT0yKQpzdWIgMQpmd2QgMQphZGQgMQpmd2QgMQphZGQgMQpyd2QgMgpqbnoKYWRkIDIKZndkIDEKam1wCnN1YiAxCnJ3ZCAxCnN1YiAxCmZ3ZCAxCmpuegphZGQgMQpyd2QgMQpqbXAKZndkIDEKc3ViIDEKcndkIDEKZ2V0Cmpuegpmd2QgMQpqbXAKc3ViIDEKZndkIDEKYWRkIDEKcndkIDEKam56CmZ3ZCAxCgpqbXAJOyBsaXN0IGZyb20gbiB0byAxCmptcApzdWIgMQpmd2QgMwphZGQgMQpyd2QgMwpqbnoKZndkIDMKam1wCnN1YiAxCmZ3ZCAzCmFkZCAxCnJ3ZCA2CmFkZCAxCmZ3ZCAzCmpuegpmd2QgMwpzdWIgMQpqbnoKCnJ3ZCA2CTsgTGlzdCBbbiwgbi0xLCAuLi4sIDIsIDJdLiBXZSBkb24ndCB3YW50IG4lMS4KYWRkIDEKcndkIDYKam1wCnJ3ZCA2Cmpuegpmd2QgNgoKam1wCTsgbW92ZSBuIG9uZSBjZWxsIHRvIHRoZSBsZWZ0CnN1YiAxCnJ3ZCAxCmFkZCAxCmZ3ZCAxCmpuegoKYWRkIDIJOyBjb3B5IHRoZSBuJ3MKam1wCnJ3ZCAxCmptcApzdWIgMQpmd2QgMwphZGQgMQpyd2QgMwpqbnoKZndkIDMKam1wCnN1YiAxCmZ3ZCAzCmFkZCAxCnJ3ZCA2CmFkZCAxCmZ3ZCAzCmpuegpmd2QgNApqbnoKcndkIDcKCmptcAk7IGNvbXB1dGUgZWFjaCBkaXZtb2QsIG9ubHkgdGhlIG4lZCByZXN1bHRzIHdpbGwg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