迷宫,80字节
?::`}:("(!@
perfect:
{:{:;%"}
+puts; "
}zero: "
}else{(:
"negI" _~
""""""{{{"!@
拉丁字符perfect puts zero else neg I
实际上只是注释*。
即,如果输入是完美的,0
则打印a,否则打印-1
。
在线尝试!
*所以这个或这个工作也...
?::`}:("(!@ ?::`}:("(!@
: BEWARE :
{:{:;%"} {:{:;%"}
+ ; " +LAIR; "
} : " } OF : "
} {(: }MINO{(:
" " _~ "TAUR" _~
""""""{{{"!@ """"""{{{"!@
怎么样?
将一个正整数作为输入n
并将一个累加器变量-n
放在辅助堆栈上,然后对每个整数执行从除n-1
到(包括)与1
除法运算的整数的除法测试n
。如果累加器变量非零-1
,则一旦完成,将输出a,否则输出a 0
。
在?::`}:(
执行开始时,仅执行一次:
?::`}:( Main,Aux
? - take an integer from STDIN and place it onto Main [[n],[]]
: - duplicate top of Main [[n,n],[]]
: - duplicate top of Main [[n,n,n],[]]
` - negate top of Main [[n,n,-n],[]]
} - place top of Main onto Aux [[n,n],[-n]]
: - duplicate top of Main [[n,n,n],[-n]]
( - decrement top of Main [[n,n,n-1],[-n]]
下一条指令"
No是空操作,但我们有3条相邻指令,因此我们根据Main顶部的值进行分支,零将我们向前,而非零将我们向右。
如果输入是1
我们,则前进,因为Main的顶部为零:
(!@ Main,Aux
( - decrement top of Main [[1,1,-1],[-1]]
! - print top of Main, a -1
@ - exit the labyrinth
但是,如果输入大于1
我们右转,因为Main的顶部非零:
:} Main,Aux
: - duplicate top of Main [[n,n,n-1,n-1],[-n]]
} - place top of Main onto Aux [[n,n,n-1],[-n,n-1]]
此时,我们有一个三邻分支,但我们知道n-1
它不是零,所以我们右转...
"% Main,Aux
" - no-op [[n,n,n-1],[-n,n-1]]
% - place modulo result onto Main [[n,n%(n-1)],[-n,n-1]]
- ...i.e we've got our first divisibility indicator n%(n-1), an
- accumulator, a=-n, and our potential divisor p=n-1:
- [[n,n%(n-1)],[a,p]]
我们现在在的另一个三邻分支机构%
。
如果的结果为%
非零,我们将减除我们的潜在除数p=p-1
,然后将累加器保留a
为:
;:{(:""}" 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]]
- three-neighbour branch but n-1 is non-zero so we turn left
( - decrement top of Main [[n,n,p-1],[a]]
: - duplicate top of Main [[n,n,p-1,p-1],[a]]
"" - no-ops [[n,n,p-1,p-1],[a]]
} - place top of Main onto Aux [[n,n,p-1],[a,p-1]]
" - no-op [[n,n,p-1],[a,p-1]]
% - place modulo result onto Main [[n,n%(p-1)],[a,p-1]]
- ...and we branch again according to the divisibility
- of n by our new potential divisor, p-1
...但是,如果的结果%
为零(仅当时为第一次通过n=2
),我们直接继续将除数添加到累加器中,然后a=a+p
递减潜在的除数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]]
在这一点上,如果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
...但是如果p-1
为零,我们会直接:
进入迷宫的第二行(您之前已经看过所有说明,所以我不再赘述它们,只是给出效果):
:":}"":({):""}"%;:{:{+}}"""""""{{{ Main,Aux
: - [[n,n,0,0],[a,0]]
" - [[n,n,0,0],[a,0]]
- top of Main is zero so we go straight
- ...but we hit the wall and so turn around
: - [[n,n,0,0,0],[a,0]]
} - [[n,n,0,0],[a,0,0]]
- top of Main is zero so we go straight
"" - [[n,n,0,0],[a,0,0]]
: - [[n,n,0,0,0],[a,0,0]]
( - [[n,n,0,0,-1],[a,0,0]]
{ - [[n,n,0,0,-1,0],[a,0]]
- top of Main is zero so we go straight
- ...but we hit the wall and so turn around
( - [[n,n,0,0,-1,-1],[a,0]]
: - [[n,n,0,0,-1,-1,-1],[a,0]]
"" - [[n,n,0,0,-1,-1,-1],[a,0]]
} - [[n,n,0,0,-1,-1],[a,0,-1]]
- top of Main is non-zero so we turn left
" - [[n,n,0,0,-1,-1],[a,0,-1]]
% - (-1)%(-1)=0 [[n,n,0,0,0],[a,0,-1]]
; - [[n,n,0,0],[a,0,-1]]
: - [[n,n,0,0,0],[a,0,-1]]
{ - [[n,n,0,0,0,-1],[a,0]]
: - [[n,n,0,0,0,-1,-1],[a,0]]
{ - [[n,n,0,0,0,-1,-1,0],[a]]
+ - [[n,n,0,0,0,-1,-1],[a]]
} - [[n,n,0,0,0,-1],[a,-1]]
} - [[n,n,0,0,0],[a,-1,-1]]
""""""" - [[n,n,0,0,0],[a,-1,-1]]
- top of Main is zero so we go straight
{ - [[n,n,0,0,0,-1],[a,-1]]
{ - [[n,n,0,0,0,-1,-1],[a]]
{ - [[n,n,0,0,0,-1,-1,a],[]]
现在,它{
具有三个相邻的指令,所以...
...如果a
为零,那将是完美的n
,那么我们继续:
"!@ 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
...如果a
为非零值(对于非完美值)n
,那么我们向左转:
_~"!@ Main,Aux
_ - place a zero onto Main [[n,n,0,0,0,-1,-1,a,0],[]]
~ - bitwise NOT top of Main (=-1-x) [[n,n,0,0,0,-1,-1,a,-1],[]]
" - [[n,n,0,0,0,-1,-1,a,-1],[]]
- top of Main is NEGATIVE so we turn left
! - print top of Main, which is -1
@ - exit the labyrinth