পার্ল, 647
কোড-গল্ফে এটি আমার প্রথম চেষ্টা, এবং আমি কিছুটা বিব্রত বোধ করি এমনকি আমি সি # স্কোরকেও পরাজিত করতে পারি নি, তবে আমি ভেবেছিলাম পুরো জিনিসটি একটি হিসাবে পুরোপুরি করা আকর্ষণীয় (বা মজাদার, বা কেবল মস্কোবাদী) হবে I রেজেক্স বিকল্পের সিরিজ (আমিও ভেবেছিলাম আমার পার্লটি ঘেঁটে ফেলা মজাদার হবে তবে শেষ পর্যন্ত আমি রুবি বা পাইথনে এটি প্রয়োগ না করার জন্য গভীরভাবে অনুশোচনা করছি।)
আমি প্রচুর পরীক্ষা করিনি, তবে আমি মনে করি এটি প্রতিটি ক্ষেত্রে পরিচালনা করা উচিত।
গ্রিডটি STDIN এর মাধ্যমে ইনপুট। ইনপুটটিতে কমপক্ষে একটি নতুন লাইন থাকতে হবে (অর্থাত্ একটি নতুন সারি ছাড়াই একটি সারি কাজ করবে না)।
%s=(d,'[|+#$vk%ZX]',u,'[|+#$^W%KX]',r,'[-G+#>k%KX]',l,'[-G+#<W%ZX]');%o=(d,'[-.*G/k\\\\Z',u,'[-.*G/W\\\\K',r,'[|.*$\\\\/kK',l,'[|.*$\\\\/ZW');for$d(d,u,r,l){$o{$d}.='123456789qwertyuio]'}%u=(d,'.|-+*$G#/Wk%\KZX',u,'.|-+*$G#/kW%\ZKX',r,'.-|+*G$#/Wk%\ZKX',l,'.-|+*G$#/kW%\KZX');@q=split//,"qwertyuio";local$/;$_=<STDIN>;for$i(1..9){$m{$i}=$q[$i-1];$m{$m{$i}}=$i;s/$i/$m{$i}/e}/.*?\n/;$l='.'x((length$&)-1);do{$c=0;for$d(d,u,r,l){%p=(d,"(?<=$s{d}$l)$o{d}",u,"$o{u}(?=$l$s{u})",r,"(?<=$s{r})$o{r}",l,"$o{l}(?=$s{l})");%h=split//,$u{$d};$c+=s!$p{$d}!$h{$&}||($v=$&,($o{$d}=~s/$v// && $s{$d}=~s/]/$m{$v}]/),$v)!es}}while($c);print/\*/?"False\n":"True\n"
ব্যাখ্যা: লেজারগুলি এর মধ্য দিয়ে যাওয়ার সাথে সাথে কোডটি পুনরাবৃত্তভাবে গ্রিড স্ট্রিং আপডেট করে। -একটি অনুভূমিক লেজার প্রতিনিধিত্ব |একটি উল্লম্ব লেজার, +অতিক্রম লেজার, Kএকটি \একটি লেজার শীর্ষ, বন্ধ প্রাণচঞ্চল সঙ্গে আয়না kএকটি /একটি লেজার নীচে, বন্ধ প্রাণচঞ্চল সঙ্গে আয়না Zএকটি \একটি লেজার নীচে বন্ধ প্রাণচঞ্চল সঙ্গে আয়না, এবং Wএকটি /আয়না একটি লেজার বন্ধ প্রাণচঞ্চল সঙ্গে শীর্ষ. উভয় পক্ষের লেজার সহ %একটি /আয়না, যখন উভয় পক্ষের লেজারগুলির সাথে Xএকটি \আয়না। (এটি কেস সংবেদনশীল। আমি এমন চিঠিগুলি বেছে নেওয়ার চেষ্টা করেছি যা কিছুটা উপযুক্ত মনে হয় - উদাহরণস্বরূপ, kএবংKকিছুটা সুস্পষ্ট পছন্দ - তবে দুর্ভাগ্যক্রমে প্রভাবটি আসলে তেমন সহায়ক নয়। আমার এই তথ্যটি একটি টেবিলের মধ্যে রাখা উচিত, তবে আমি এখনই ক্লান্ত হয়ে পড়েছি))
একইভাবে পোর্টালগুলি হ্যান্ডলিং করা (যেমন প্রতিটি অঙ্ককে সম্ভাব্য ইনপুট / আউটপুট লেজার পজিশনের উপর ভিত্তি করে অতিরিক্ত অক্ষরের একটি সেট নির্ধারণের জন্য) 144 টি অক্ষর (মূল 9 সহ) প্রয়োজন হবে, সুতরাং পরিবর্তে, যখন কোনও লেজার একটি "ইনপুট" পোর্টালে আঘাত করে, আমি অক্ষরের সেটগুলিতে "আউটপুট" পোর্টাল অক্ষর যুক্ত করি যা সঠিক দিকটিতে একটি লেজার নির্গত করে। (এটির জন্য ইনপুট এবং আউটপুট পোর্টালগুলির মধ্যে পার্থক্য প্রয়োজন; আমি এর qwertyuioজন্য চিঠিগুলি ব্যবহার করেছি))
কিছুটা অন-গল্ফযুক্ত, মুদ্রণ বিবৃতি সহ যাতে আপনি প্রতিস্থাপনাগুলি ঘটতে পারেন (প্রতিটি প্রতিস্থাপন লেজার-অগ্রগতির একটি "গোলাকার" উপস্থাপন করে) এবং মূলটিতে gপতাকাটি যুক্ত করা হয় s///যাতে এটি এত বেশি পুনরাবৃত্তি না নেয়:
# Throughout, d,u,r,l represents lasers going down, up, left, or right
# `sources` are the character classes representing laser "sources" (i.e. any
# character that can, on the next round, cause a laser to enter the space
# immediately adjacent to it in the proper direction)
%sources=(d,'[|+#$vk%ZX]',u,'[|+#$^W%KX]',r,'[-G+#>k%KX]',l,'[-G+#<W%ZX]');
# `open` characters will not block a laser
%open=(d,'[-.*G/k\\\\Z',u,'[-.*G/W\\\\K',r,'[|.*$\\\\/kK',l,'[|.*$\\\\/ZW');
# One of each portal is changed into the corresponding letter in `qwertyuio`.
# At the start, each portal is 'open' and none of them is a source.
for$d(d,u,r,l){$open{$d}.='123456789qwertyuio]'}
# A mapping of 'open' characters to the characters they become when a laser
# goes through them. (This is used like a hash of hashes; see the assignment
# of `%h` below.)
%update=(d,'.|-+*$G#/Wk%\KZX',
u,'.|-+*$G#/kW%\ZKX',
r,'.-|+*G$#/Wk%\ZKX',
l,'.-|+*G$#/kW%\KZX');
@q=split//,"qwertyuio";
local$/;$_=<STDIN>;
for$i(1..9){
$m{$i}=$q[$i-1];
$m{$m{$i}}=$i;
s/$i/$m{$i}/e}
print "After substituting portals:\n";
print;
print "\n";
# Find the number of characters in each line and create a string of `.`'s,
# which will be used to correlate characters above/below one another in the
# grid with each other.
/.*?\n/;
$l='.'x((length$&)-1);
do{
$changes=0;
for$d(d,u,r,l){
# `patterns` is a mapping from each direction to the regex representing
# an update that must occur (i.e. a place where a laser must progress).
# Each pattern is either a lookahead or lookbehind plus the necessary
# "open" character class.
%patterns=(d,"(?<=$sources{d}$l)$open{d}",
u,"$open{u}(?=$l$sources{u})",
r,"(?<=$sources{r})$open{r}",
l,"$open{l}(?=$sources{l})");
%h=split//,$update{$d};
# Match against the pattern for each direction. Note whether any
# matches were found.
$changes+=s!$patterns{$d}!
# If the "open" character for a map is in the `update` map, return
# the corresponding value. Otherwise, the "open" character is a
# portal.
$h{$&} || ($v=$&,
# For portals, remove the input portal from the
# proper "open" list and add the output portal to
# the proper "source" list.
($open{$d}=~s/$v// && $sources{$d}=~s/]/$m{$v}]/),
$v)
# This whole substitution should allow `.` to match
# newlines (see the definition of `$l` above), and the
# replacement must be an expression rather than a string
# to facilitate the portal logic. The `g` allows multiple
# updates per "frame"; it is left out of the golfed code.
!egs
}
# Print the next "frame".
print;
print "\n";
# Continue updating until no "open" spaces are found.
}while($changes);
# Print whether `*` is still present in the input.
print/\*/?"False\n":"True\n"