I =INPUT
D =SIZE(I)
N P =P + 1
EQ(P,1) :S(S)
EQ(P,D) :S(E)
I POS(P - 2) LEN(2) . L
I POS(P - 1) LEN(2) . R
T Y =IDENT(L,R) Y 0 :S(C)
Y =Y 1
C EQ(P,D) :S(O)F(N)
S I LEN(1) . L
I POS(1) LEN(1) . R :(T)
E I RPOS(2) LEN(1) . L
I RPOS(1) LEN(1) . R :(T)
O OUTPUT =Y
END
在线尝试!
I =INPUT ;* read input
D =SIZE(I) ;* get the string length
N P =P + 1 ;* iNcrement step; all variables initialize to 0/null string
EQ(P,1) :S(S) ;* if P == 1 goto S (for Start of string)
EQ(P,D) :S(E) ;* if P == D goto E (for End of string)
I POS(P - 2) LEN(2) . L ;* otherwise get the first two characters starting at n-1
I POS(P - 1) LEN(2) . R ;* and the first two starting at n
T Y =IDENT(L,R) Y 0 :S(C) ;* Test if L and R are equal; if so, append 0 to Y and goto C
Y =Y 1 ;* otherwise, append 1
C EQ(P,D) :S(O)F(N) ;* test if P==D, if so, goto O (for output), otherwise, goto N
S I LEN(1) . L ;* if at start of string, L = first character
I POS(1) LEN(1) . R :(T) ;* R = second character; goto T
E I RPOS(2) LEN(1) . L ;* if at end of string, L = second to last character
I RPOS(1) LEN(1) . R :(T) ;* R = last character; goto T
O OUTPUT =Y ;* output
END