배시 펄 231 229 218 178 164 166 138 106 74 바이트
/^(((.*).*)\2+)\3$/;$_.=$1x2;$.--,die$+[1]if/^(.*)(.)(.*)
.*\1(?!\2).\3/
스크립트는 -n스위치를 사용해야하며 ,이 중 2 바이트를 설명합니다.
패턴의 전체 반복의 두 복사본을 추가한다는 아이디어는 MT0의 답변 에서 가져 왔습니다 .
다른 모든 답변과 달리이 방법은 각 반복에서 현재 입력 라인의 패턴을 추출하려고 시도합니다. 홀수 문자를 포함하는 행에서 실패하고 대신 이전 행의 패턴을 사용합니다. 이것은 루프에 패턴 추출을 포함하기 위해 수행되며 몇 바이트를 절약합니다.
언 골프 버전
#!/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.
이것은 명백히 남용 으로 인해 자유 주의적 출력 형식을 이용합니다.
종료하기 전에 Perl의 특수 변수 내용은 다음과 같습니다.
$_ = lfcodegolfcodegoff\ncodegolfcodegolfcodegolfcodegolf
$1 = lfcodegolfcodego
$2 = f
$3 = f
( $n역 참조를 통해 액세스 할 수있는 서브 패턴의 경기를 포함 \n.)