বাশ পার্ল, 231 229 218 178 164 166 138 106 74 বাইট
/^(((.*).*)\2+)\3$/;$_.=$1x2;$.--,die$+[1]if/^(.*)(.)(.*)
.*\1(?!\2).\3/
স্ক্রিপ্টটির জন্য -n
স্যুইচটি ব্যবহার করা দরকার , যা দুটি বাইটের জন্য দায়ী।
এমটি 0 এর উত্তর থেকে প্যাটার্নের সমস্ত সম্পূর্ণ পুনরাবৃত্তির দুটি অনুলিপি যুক্ত করার ধারণা নেওয়া হয়েছে ।
অন্যান্য সমস্ত উত্তরের বিপরীতে, এই পদ্ধতির প্রতিটি পুনরাবৃত্তির মধ্যে বর্তমান ইনপুট লাইনের ধরণটি বের করার চেষ্টা করা হয়; এটি বিজোড় অক্ষরযুক্ত লাইনে ব্যর্থ হবে (এবং এর পরিবর্তে পূর্ববর্তী লাইনের প্যাটার্নটি ব্যবহার করবে)। লুপের মধ্যে প্যাটার্ন নিষ্কাশন অন্তর্ভুক্ত করার জন্য এটি করা হয়, যা কয়েকটি বাইট সংরক্ষণ করতে সক্ষম হয়।
উদার সংস্করণ
#!/usr/bin/perl -n
# The `-n' switch makes Perl execute the entire script once for each input line, just like
# wrapping `while(<>){…}' around the script would do.
/^(((.*).*)\2+)\3$/;
# This regular expression matches if `((.*).*)' - accessible via the backreference `\2' -
# is repeated at least once, followed by a single repetition of `\3" - zero or more of the
# leftmost characters of `\2' - followed by the end of line. This means `\1' will contain
# all full repetitions of the pattern. Even in the next loop, the contents of `\1' will be
# available in the variable `$1'.
$_.=$1x2;
# Append two copies of `$1' to the current line. For the line, containing the odd
# character, the regular expression will not have matched and the pattern of the previous
# line will get appended.
#
# Since the pattern is repeated at least two full times, the partial pattern repetition at
# the end of the previous line will be shorter than the string before it. This means that
# the entire line will the shorter than 1.5 times the full repetitions of the pattern,
# making the two copies of the full repetitions of the pattern at least three times as
# long as the input lines.
$.-- , die $+[1] if
# If the regular expression below matches, do the following:
#
# 1. Decrement the variable `$.', which contains the input line number.
#
# This is done to obtain zero-based coordinates.
#
# 2. Print `$+[1]' - the position of the last character of the first subpattern of the
# regular expression - plus some additional information to STDERR and exit.
#
# Notably, `die' prints the (decremented) current line number.
/^(.*)(.)(.*)
.*\1(?!\2).\3/;
# `(.*)(.)(.*)', enclosed by `^' and a newline, divides the current input line into three
# parts, which will be accesible via the backreferences `\1' to `\3'. Note that `\2'
# contains a single character.
#
# `.*\1(?!\2).\3' matches the current input line, except for the single character between
# `\1' and `\3' which has to be different from that in `\2', at any position of the line
# containing the pattern repetitions. Since this line is at least thrice as long as
# `\1(?!\2).\3', it will be matched regardless of by how many characters the line has been
# rotated.
উদাহরণ
পরীক্ষার ক্ষেত্রে
codegolfcodegolfco
egolfcodegolfcodeg
lfcodegolfcodegoff
odegolfcodegolfcod
golfcodegolfcodego
fcodegolfcodegolfc
গল্ফ সংস্করণ আউটপুট হয়
16 at script.pl line 1, <> line 2.
অর্থাত্ বিজোড় চরিত্রের সমন্বয় রয়েছে 16,2
।
এই নির্মম অপব্যবহারগুলি উদার আউটপুট ফর্ম্যাটটির সুবিধা নেয়।
প্রস্থান করার ঠিক আগে, পার্লের কিছু বিশেষ ভেরিয়েবলের বিষয়বস্তু হ'ল:
$_ = lfcodegolfcodegoff\ncodegolfcodegolfcodegolfcodegolf
$1 = lfcodegolfcodego
$2 = f
$3 = f
( $n
ব্যাকরেফারেন্সের মাধ্যমে অ্যাক্সেসযোগ্য সাব-প্যাটার্নগুলির মিল রয়েছে \n
))