ES6(JavaScript), 111,101字节
编辑:将输出值更改为true和false,而不是Y和N,以减少10个字节
打高尔夫球
F=(I,M=[...I],c=0,i)=>(i={j:v=I.search`\n`+1,k:-v,h:-1,l:1,q:i,0:0}[M[c]])?F(I,M,c+i+(M[c]=0),i):i!=0
测试
F=(I,M=[...I],c=0,i)=>(i={j:v=I.search`\n`+1,k:-v,h:-1,l:1,q:i,0:0}[M[c]])?F(I,M,c+i+(M[c]=0),i):i!=0
//Alphabet Map
tr={
'<':'h',
'>':'l',
'^':'k',
'v':'j',
'.':'q',
'\n':'\n'
};
//Test
T=(I,A)=>{
console.log({"Y":"#Halting","N":"#Non-Halting"}[A]);
console.log("I=\n",I,"\nF(I)=",O=F([...I].map(s=>tr[s]).join('')));
console.log('NY'[O*1] == A ? "OK !" : "NOT OK !");
}
//Halting
T(
`>.v
..<`
,'Y');
//Non-Halting
T(
`>....v
..v..<
..>v..
^..<..`
,'N');
//Halting
T(
`.`
,'Y')
//Halting
T(
`v>
>^`
,'Y');
//Halting
T(
`....v....
....>...v
.^..<....
.......v<
.......v.
....^..<.`
,'Y');
//Halting
T(
`v<>v>v^
>v^>^>v
<>>^v<v
v^<>v^<`
,'Y');
//Non-Halting
T(
`>..v
^..<`
,'N');
//Non-Halting
T(
`>v<
v<.
>v.
v<.
>.^`
,'N');
//Non-Halting
T(
`>.>.>.v
.><.<.<`
,'N');
样本输出
#Halting
I=
>.v
..<
F(I)= true
OK !
#Non-Halting
I=
>....v
..v..<
..>v..
^..<..
F(I)= false
OK !
#Halting
I=
.
F(I)= true
OK !
#Halting
I=
v>
>^
F(I)= true
OK !
#Halting
I=
....v....
....>...v
.^..<....
.......v<
.......v.
....^..<.
F(I)= true
OK !
#Halting
I=
v<>v>v^
>v^>^>v
<>>^v<v
v^<>v^<
F(I)= true
OK !
#Non-Halting
I=
>..v
^..<
F(I)= false
OK !
#Non-Halting
I=
>v<
v<.
>v.
v<.
>.^
F(I)= false
OK !
#Non-Halting
I=
>.>.>.v
.><.<.<
F(I)= false
OK !