রুবি, 217
->a{r=''
z=a.index ?@
a.tr!('<^>v',b='awds').scan(/\w/){c=0
e,n=[a[z,c+=1][?\n]?p: c,d=c*a[/.*
/].size,a[z-c,c][?\n]?p: -c,-d].zip(b.chars).reject{|i,k|!i||a[v=i+z]!=k||0>v}.max_by{|q|q&[a[z]]}until n
z+=e
r=n*c+r}
r}
এটি শুরু হয় @ পিছনের দিকে চলে যায়, প্রতিবেশীদের সন্ধান করে যা বর্তমান অবস্থানে ( z) নির্দেশ করে। 4-রাস্তার মোড়ে সঠিক পথটি বেছে নেওয়ার জন্য, এটি প্রতিবেশীদের একই দিকে ( max_by{...}) নির্দেশ করে poin যদি আশেপাশের কোনও প্রতিবেশী না পাওয়া যায় তবে এটি ধরে নেওয়া হয় যে অবশ্যই একটি ক্রস-ওভার হয়েছে এবং এটি এক ( until nএবং c+=1) না পাওয়া পর্যন্ত এক পর্যায়ে এক পর্যায়ে পৌঁছেছে । এই প্রক্রিয়াটি শরীরের বিভাগগুলির সংখ্যা (মাথা সহ নয়) এর পুনরাবৃত্তি করে .scan(/\w/){...}।
আমি ধাঁধাতে যুক্ত টেস্ট কেসটি আমাকে আরও ট্রিপ করে চলেছি, তাই আমি 182 চর হয়ে 218 এ রূপ নিয়েছি Those অতিরিক্ত অক্ষরগুলিই নিশ্চিত করেছিল যে আমার অনুভূমিক পদক্ষেপগুলি পরবর্তী / পূর্ববর্তী লাইনে যাবে না। আমি যদি আরও ভালভাবে এটি মোকাবেলা করতে পারি তবে আমি ভাবছি।
Ungolfed:
f=->a{
result=''
position=a.index ?@ # start at the @
a.tr!('<^>v',b='awds') # translate arrows to letters
a.scan(/\w/){ # for each letter found...
search_distance=0
until distance
search_distance+=1
neighbors = [
a[position,search_distance][?\n]?p: search_distance, # look right by search_distance unless there's a newline
width=search_distance*a[/.*\n/].size, # look down (+width)
a[position-search_distance,search_distance][?\n]?p: -search_distance, # look left unless there's a newline
-width # look up (-width)
]
distance,letter = neighbors.zip(b.chars).reject{ |distance, letter_to_find|
!distance || # eliminate nulls
a[new_position=distance+position]!=letter_to_find || # only look for the letter that "points" at me
0>new_position # and make sure we're not going into negative indices
}.max_by{ |q|
# if there are two valid neighbors, we're at a 4-way intersection
# this will make sure we prefer the neighbor who points in the same
# direction we're pointing in. E.g., when position is in the middle of
# the below, the non-rejected array includes both the top and left.
# v
# >>>
# v
# We want to prefer left.
q & [a[position]]
# ['>',x] & ['>'] == ['>']
# ['v',x] & ['>'] == []
# ['>'] > [], so we select '>'.
}
end
position+=distance
result=(letter*search_distance)+result # prepend result
}
result # if anyone has a better way of returning result, I'm all ears
}