...but if p-1 hit zero we go straight up to the : on the second line of the labyrinth (you've seen all the instructions before, so I'm leaving their descriptions out and just giving their effect):
"!@ Main,Aux
" - [[n,n,0,0,0,-1,-1,a],[]]
- top of Main is a, which is zero, so we go straight
! - print top of Main, which is a, which is a 0
@ - exit the labyrinth
...but if p-1 hit zero we go straight up to the : on the second line of the labyrinth:
"!@ Main,Aux
" - [[n,n,0,0,0,-1,-1,a],[]]
- top of Main is a, which is zero, so we go straight
! - print top of Main, which is a, which is a 0
@ - exit the labyrinth
...but if p-1 hit zero we go straight up to the : on the second line of the labyrinth (you've seen all the instructions before, so I'm leaving their descriptions out and just giving their effect):
"!@ Main,Aux
" - [[n,n,0,0,0,-1,-1,a],[]]
- top of Main is a, which is zero, so we go straight
! - print top of Main, which is a, which is a 0
@ - exit the labyrinth
...but if the result of % was zero (for the first pass only n=2 wherewhen 2%(2-1)=0n=2) we go straight on to BOTH add the divisor to our accumulator, a=a+p, AND decrement our potential divisor, p=p-1:
;:{:{+}}""""""""{(:""} Main,Aux
; - drop top of Main [[n],[a,p]]
: - duplicate top of Main [[n,n],[a,p]]
{ - place top of Aux onto Main [[n,n,p],[a]]
: - duplicate top of Main [[n,n,p,p],[a]]
{ - place top of Aux onto Main [[n,n,p,p,a],[]]
+ - perform addition [[n,n,p,a+p],[]]
} - place top of Main onto Aux [[n,n,p],[a+p]]
} - place top of Main onto Aux [[n,n],[a+p,p]]
""""""" - no-ops [[n,n],[a+p,p]]
- wea branch, but n is non-zero so we turn left
" - no-op [[n,n],[a+p,p]]
{ - place top of Aux onto Main [[n,n,p],[a+p]]
- we branch, but p is non-zero so we turn right
( - decrement top of Main [[n,n,p-1],[a+p]]
: - duplicate top of Main [[n,n,p-1,p-1],[a+p]]
"" - no-ops [[n,n,p-1,p-1],[a+p]]
} - place top of Main onto Aux [[n,n,p-1],[a+p,p-1]]
"% Main,Aux
" - no-op [[n,n,p-1],[a+p,p-1]]
% - modulo [[n,n%(p-1)],[a+p,p-1]]
- ...and we branch again according to the divisibility
- of n by our new potential divisor, p-1
...but if the result of % was zero (for first pass only n=2 where 2%(2-1)=0) we go straight on to BOTH add the divisor to our accumulator, a=a+p, AND decrement our potential divisor, p=p-1:
;:{:{+}}""""""""{(:""} Main,Aux
; - drop top of Main [[n],[a,p]]
: - duplicate top of Main [[n,n],[a,p]]
{ - place top of Aux onto Main [[n,n,p],[a]]
: - duplicate top of Main [[n,n,p,p],[a]]
{ - place top of Aux onto Main [[n,n,p,p,a],[]]
+ - perform addition [[n,n,p,a+p],[]]
} - place top of Main onto Aux [[n,n,p],[a+p]]
} - place top of Main onto Aux [[n,n],[a+p,p]]
""""""" - no-ops [[n,n],[a+p,p]]
- we branch, but n is non-zero so we turn left
" - no-op [[n,n],[a+p,p]]
{ - place top of Aux onto Main [[n,n,p],[a+p]]
- we branch, but p is non-zero so we turn right
( - decrement top of Main [[n,n,p-1],[a+p]]
: - duplicate top of Main [[n,n,p-1,p-1],[a+p]]
"" - no-ops [[n,n,p-1,p-1],[a+p]]
} - place top of Main onto Aux [[n,n,p-1],[a+p,p-1]]
" - no-op [[n,n,p-1],[a+p,p-1]]
% - modulo [[n,n%(p-1)],[a+p,p-1]]
- ...and we branch again according to the divisibility
- of n by our new potential divisor, p-1
...but if the result of % was zero (for the first pass only when n=2) we go straight on to BOTH add the divisor to our accumulator, a=a+p, AND decrement our potential divisor, p=p-1:
;:{:{+}}""""""""{(:""} Main,Aux
; - drop top of Main [[n],[a,p]]
: - duplicate top of Main [[n,n],[a,p]]
{ - place top of Aux onto Main [[n,n,p],[a]]
: - duplicate top of Main [[n,n,p,p],[a]]
{ - place top of Aux onto Main [[n,n,p,p,a],[]]
+ - perform addition [[n,n,p,a+p],[]]
} - place top of Main onto Aux [[n,n,p],[a+p]]
} - place top of Main onto Aux [[n,n],[a+p,p]]
""""""" - no-ops [[n,n],[a+p,p]]
- a branch, but n is non-zero so we turn left
" - no-op [[n,n],[a+p,p]]
{ - place top of Aux onto Main [[n,n,p],[a+p]]
- we branch, but p is non-zero so we turn right
( - decrement top of Main [[n,n,p-1],[a+p]]
: - duplicate top of Main [[n,n,p-1,p-1],[a+p]]
"" - no-ops [[n,n,p-1,p-1],[a+p]]
} - place top of Main onto Aux [[n,n,p-1],[a+p,p-1]]
"% Main,Aux
" - no-op [[n,n,p-1],[a+p,p-1]]
% - modulo [[n,n%(p-1)],[a+p,p-1]]
- ...and we branch again according to the divisibility
- of n by our new potential divisor, p-1