νƒœκ·Έ 보관물: hexagonal-grid

hexagonal-grid

HexaRegex : λ§ˆν‹΄ μ—”λ”μ—κ²Œ 경의λ₯Ό ν‘œν•©λ‹ˆλ‹€ 6 κ°ν˜•μœΌλ‘œ

Martin EnderλŠ” 졜근 100Kλ₯Ό κΈ°λ‘ν–ˆμœΌλ©° κ½€ λ©‹μ§„ μ–Έμ–΄λ₯Ό 생각해 λƒˆμŠ΅λ‹ˆλ‹€ . μš°λ¦¬λŠ” κ·Έλ“€ 쀑 ν•˜λ‚˜ 인 Hexagony (그리고 Retina에 λŒ€ν•œ μ•½κ°„μ˜ μ •κ·œ ν‘œν˜„μ‹ ) 와 μ•½κ°„μ˜ 재미λ₯Ό κ°€μ§ˆ κ²ƒμž…λ‹ˆλ‹€.

κ°„λ‹¨ν•œ κ°œμš”λ‘œ, Hexagony κ·Έλ¦¬λ“œ λ₯Ό μž…λ ₯ν•˜κ³  ν•΄λ‹Ή κ·Έλ¦¬λ“œμ— ν…μŠ€νŠΈ λ¬Έμžμ—΄κ³Ό μΌμΉ˜ν•˜λŠ” κ²½λ‘œκ°€ μžˆλŠ”μ§€ νŒλ³„ ν•˜λŠ” ν”„λ‘œκ·Έλž¨μ„ μž‘μ„±ν•΄μ•Ό ν•©λ‹ˆλ‹€.

생성

HexagonyλŠ” λ‹€μŒ 단계λ₯Ό μ‚¬μš©ν•˜μ—¬ ν…μŠ€νŠΈ λ¬Έμžμ—΄μ—μ„œ μœ‘κ°ν˜•μ„ μƒμ„±ν•©λ‹ˆλ‹€.

  1. μ΅œμ†Œ μœ‘κ°ν˜• 크기λ₯Ό κ³„μ‚°ν•˜μ‹­μ‹œμ˜€ (끈의 길이λ₯Ό μ·¨ν•˜κ³  κ°€μž₯ κ°€κΉŒμš΄ 16 μ§„μˆ˜λ‘œ λ°˜μ˜¬λ¦Όν•˜μ‹­μ‹œμ˜€ )
  2. μœ„μ˜ 크기의 μœ‘κ°ν˜•μœΌλ‘œ ν…μŠ€νŠΈ 감싸기
  3. 둜 λ‚˜λ¨Έμ§€ μœ„μΉ˜λ₯Ό 채 μ›λ‹ˆλ‹€ ..

예λ₯Ό λ“€μ–΄, ν…μŠ€νŠΈ λ¬Έμžμ—΄μ€ abcdefghijklmμΈ‘λ©΄ 길이 3의 μœ‘κ°ν˜•μ΄ ν•„μš”ν•˜λ―€λ‘œ λ‹€μŒκ³Ό κ°™μ΄λ©λ‹ˆλ‹€.

   a b c
  d e f g
 h i j k l
  m . . .
   . . .

이제 6 κ°ν˜•μœΌλ‘œ μ—¬ν–‰ ν•  μˆ˜μžˆλŠ” 6 κ°€μ§€ λ°©ν–₯이 μžˆμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, μœ„ μœ‘κ°ν˜•μ—μ„œμ€μ— eμΈμ ‘ν•©λ‹ˆλ‹€ abfjid.

μ™Έμž₯

λ˜ν•œ Hexagonyμ—μ„œλŠ” μœ‘κ°ν˜•μ΄ λ‹€μŒκ³Ό 같이 λž©ν•‘λ©λ‹ˆλ‹€.

   . . . .          . a . .          . . f .          . a . .
  a b c d e        . . b . .        . . g . .        . b . . f
 . . . . . .      g . . c . .      . . h . . a      . c . . g .
. . . . . . .    . h . . d . .    . . u . . b .    . d . . h . .
 f g h i j k      . i . . e .      . j . . c .      e . . i . .
  . . . . .        . j . . f        k . . d .        . . j . .
   . . . .          . k . .          . . e .          . k . .

두 λ²ˆμ§Έμ™€ λ„€ 번째 예λ₯Ό 보면 λ‹€λ₯Έ λ°©ν–₯으둜 포μž₯λ˜μ–΄ μžˆμŒμ—λ„ λΆˆκ΅¬ν•˜κ³  같은 μ§€μ μ—μžˆλŠ” 방법 aκ³Ό kμœ„μΉ˜λ₯Ό ν™•μΈν•˜μ‹­μ‹œμ˜€. 이 μ‚¬μ‹€λ‘œ 인해이 지점듀은 5 곳의 λ‹€λ₯Έ μœ„μΉ˜μ—λ§Œ 인접 ν•΄ μžˆμŠ΅λ‹ˆλ‹€ .

이것을 더 λͺ…ν™•ν•˜κ²Œν•˜λ €λ©΄ :

   a b c d
  e f g h i
 j k l m n o
p q r s t u v
 w x y z A B
  C D E F G
   H I J K
  1. κ°€μž₯μžλ¦¬λŠ” λ°˜λŒ€μͺ½ 이웃 ( b->I및 G->j) 으둜 쀄 λ°”κΏˆλ©λ‹ˆλ‹€ .
  2. μœ„ / μ•„λž˜ λͺ¨μ„œλ¦¬λŠ” λ°˜λŒ€μͺ½ κ°€μš΄λ° λͺ¨μ„œλ¦¬μ™€ μœ„ / μ•„λž˜ ( d->K,p및 H->a,v) 둜 λ‘˜λŸ¬μ‹Έ μž…λ‹ˆλ‹€.
  3. κ°€μš΄λ° λͺ¨μ„œλ¦¬λŠ” μœ„μͺ½ 및 μ•„λž˜μͺ½ λͺ¨μ„œλ¦¬ λͺ¨λ‘λ‘œ 쀄 λ°”κΏˆ ( v->a,H)

경둜

λ™μΌν•œ μœ„μΉ˜λ‘œ λŒμ•„ κ°€μ§€ μ•Šκ³  μΈμ ‘ν•œ μœ„μΉ˜μ˜ μ‹œν€€μŠ€κ°€ λ˜λŠ” 경둜 μž…λ‹ˆλ‹€.

   a b c
  d e f g
 h i f k l
  m . . .
   . . .

μœ„μ˜ μœ‘κ°ν˜•μ—μ„œ aefkgmμœ νš¨ν•œ κ²½λ‘œμž…λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜, abfdμœ νš¨ν•œ κ²½λ‘œκ°€ μ•„λ‹Œ ( f와 dμΈμ ‘ν•˜μ§€ μ•Šμ€), 및 abeaμœ νš¨ν•œ (λ°›λŠ” λ¦¬ν„΄μ—†λŠ” aμœ„μΉ˜).

μ΄λŸ¬ν•œ 경둜λ₯Ό μ‚¬μš©ν•˜μ—¬ ν…μŠ€νŠΈμ™€ μΌμΉ˜μ‹œν‚¬ 수 μžˆμŠ΅λ‹ˆλ‹€ (예 : μ •κ·œμ‹) . 영숫자 λ¬ΈμžλŠ” μžμ‹ κ³Ό .μΌμΉ˜ν•˜λ©° λͺ¨λ“  λ¬Έμžμ™€ μΌμΉ˜ν•©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, κ²½λ‘œκ°€ aej..lgmμΌμΉ˜ν•©λ‹ˆλ‹€ aej..lgm, aejAAlgm, aeja.lgm, λ˜λŠ” aej^%gm.

μž…μΆœλ ₯

ν”„λ‘œκ·Έλž¨μ€ μ–΄λ–€ μˆœμ„œλ‘œλ“  두 개의 λ¬Έμžμ—΄μ„ κ°€μ Έμ•Όν•©λ‹ˆλ‹€. 첫 번째 λ¬Έμžμ—΄μ€ λΉ„μ–΄ μžˆμ§€ μ•ŠμœΌλ©° 영숫자둜만 κ΅¬μ„±λ©λ‹ˆλ‹€ [a-zA-Z0-9]. μž‘λ™μ€‘μΈ μœ‘κ°ν˜•μ„ λ‚˜νƒ€λƒ…λ‹ˆλ‹€. 두 번째 λ¬Έμžμ—΄μ€ 인쇄 κ°€λŠ₯ν•œ 문자둜 κ΅¬μ„±λ©λ‹ˆλ‹€.

μ£Όμ–΄μ§„ ν…μŠ€νŠΈ λ¬Έμžμ—΄κ³Ό μΌμΉ˜ν•˜λŠ” μœ‘κ°ν˜• κ²½λ‘œκ°€ 있으면 κ±°μ§“ 값을 λ°˜ν™˜ν•΄μ•Όν•©λ‹ˆλ‹€. κ·Έλ ‡μ§€ μ•ŠμœΌλ©΄ κ±°μ§“ κ°’μž…λ‹ˆλ‹€.

ν…ŒμŠ€νŠΈ 사둀

μ§„μ‹€ν•œ :

"a","a"
"ab","a"
"ab","b"
"ab","ba"
"ab","aba"
"ab","&"
"ab","#7.J!"
"ab","aaaaaa"
"ab","bgjneta"
"ab","cebtmaa"
"abcdefg","dfabcg"
"AbCDeFG","GCbAeFD"
"aaaabbb","aaababb"
"abcdefghijklmnopqrs","alq"
"abcdefghijklmnopqrs","aqnmiedh"
"abcdefghijklmnopqrs","adhcgkorbefjimnqlps"
"11122233344455","12341345123245"
"abcdefgh","h%a"
"abcdefghijklm","a)(@#.*b"
"abcdefghijklm","a)(@#.*i"
"abcdefghij","ja"
"abcdefghijklmno","kgfeia"
"abcdefghijklmno","mmmmmiea"
"abcdefghijklmno","mmmmmlae"
"abcdefghijklmno","ja"
"abcdefghijklmnopqrs","eijfbadhmnokgcsrql"

κ±°μ§“ :

"a","b"
"a","%"
"a","."
"a","aa"
"a","a."
"ab","#7.J!*"
"ab","aaaaaaa"
"ab","aaaabaaa"
"ab","123456"
"abcdefg","bfgedac"
"abcdefg","gecafdb"
"abcdefg","GCbaeFD"
"aaaabbb","aaaaabb"
"abcdefghijklmnopqrs","aqrcgf"
"abcdefghijklmnopqrs","adhlcgknbeifjm"
"abcdefghijklmnopqrs","ja"
"abcdefghijklm","a)(@#.*&"
"abcdefghijklmno","a)(@bfeijk"
"abcdefghijklmno","kgfeic"
"abcdefghijklmno","mmmmmmiea"

이것은 μ΄λ―€λ‘œ μ„ ν˜Έν•˜λŠ” μ–Έμ–΄λ‘œ κ°€λŠ₯ν•œ ν•œ 빨리 λ‹΅λ³€ν•˜μ‹­μ‹œμ˜€.



λ‹΅λ³€

λ ˆν‹° λ‚˜ 744 λ°”μ΄νŠΈ

μ£„μ†‘ν•©λ‹ˆλ‹€. μ΄λ²ˆμ—λŠ” Hexagonyκ°€ μ—†μŠ΅λ‹ˆλ‹€ …

λ°”μ΄νŠΈ μˆ˜λŠ” ISO 8859-1 인코딩을 κ°€μ •ν•©λ‹ˆλ‹€.

.+ΒΆ
$.'$*_ΒΆ$&
^_ΒΆ
ΒΆ
((^_|\2_)*)_\1{5}_+
$2_
^_*
$.&$*Γ—_$&$&$.&$*Γ—
M!&m`(?<=(?=Γ—*(_)+)\A.*)(?<-1>.)+(?(1)!)|^.*$
O$`(_)|.(?=.*$)
$1
G-2`
T`d`Γ€-Γ‰
m`\A(\D*)(?(_)\D*ΒΆ.|(.)\D*ΒΆ\2)((.)(?<=(?<4>_)\D+)?((?<=(?<1>\1.)\4\D*)|(?<=(?<1>\D*)\4(?<=\1)\D*)|(?<=\1(.(.)*ΒΆ\D*))((?<=(?<1>\D*)\4(?>(?<-7>.)*)ΒΆ.*\6)|(?<=(?<1>\D*)(?=\4)(?>(?<-7>.)+)ΒΆ.*\6))|(?<=(Γ—)*ΒΆ.*)((?<=(?<1>\1.(?>(?<-9>ΒΆ.*)*))^\4\D*)|(?<=(?<1>\D*)\4(?>(?<-9>ΒΆ.*)*)(?<=\1)^\D*)|(?<=(?<1>\1\b.*(?(9)!)(?<-9>ΒΆ.*)*)\4Γ—*ΒΆ\D*)|(?<=(?<1>\D*\b)\4.*(?(9)!)(?<-9>ΒΆ.*)*(?<=\1.)\b\D*))|(?<=(?<1>\1.(?>(?<-11>.)*)ΒΆ.*)\4(.)*ΒΆ\D*)|(?<=(?<1>\1(?>(?<-12>.)*)ΒΆ.*)\4(.)*ΒΆ\D*)|(?<=(?<1>\1.(?>(?<-13>.)*ΒΆ\D*))\4(\w)*\W+.+)|(?<=(?<1>.*)\4(?>(?<-14>.)*ΒΆ\D*)(?<=\1.)(\w)*\W+.+))(?<=\1(\D*).+)(?<!\1\15.*(?<-1>.)+))*\Z

μž…λ ₯의 첫 번째 ν–‰μ—μ„œ λŒ€μƒ λ¬Έμžμ—΄μ„, 두 번째 ν–‰μ—μ„œ μœ‘κ°ν˜•μ„ μ˜ˆμƒν•©λ‹ˆλ‹€. 인쇄 0ν•˜κ±°λ‚˜ 1그에 따라.

온라인으둜 μ‚¬μš©ν•΄λ³΄μ‹­μ‹œμ˜€! 첫 번째 쀄은 ¦쀄 λ°”κΏˆ λŒ€μ‹  ꡬ뢄 을 μœ„ν•΄ μ‚¬μš©ν•˜λŠ” 각 ν…ŒμŠ€νŠΈ 쀄인 ν…ŒμŠ€νŠΈ μŠ€μœ„νŠΈλ₯Ό ν™œμ„±ν™”ν•©λ‹ˆλ‹€ .

이 문제λ₯Ό ν•΄κ²°ν•˜λŠ” μ˜¬λ°”λ₯Έ 방법은 λ¬Όλ‘  μ •κ·œμ‹μ„ μ‚¬μš©ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. πŸ˜‰ 그리고이 도전이 μœ‘κ°ν˜• 의 μ „κ°œ μ ˆμ°¨μ™€ 관련이 μ—†λ‹€λŠ” 사싀이 μ•„λ‹ˆλΌλ©΄ 이 λŒ€λ‹΅μ€ μ‹€μ œλ‘œ ~ 600 λ°”μ΄νŠΈ 길이의 μ •κ·œ ν‘œν˜„μ‹μœΌλ‘œ κ΅¬μ„±λ©λ‹ˆλ‹€.

이것은 아직 졜적의 κ³¨ν”„λŠ” μ•„λ‹ˆμ§€λ§Œ 결과에 맀우 λ§Œμ‘±ν•©λ‹ˆλ‹€ (이름이 μ§€μ •λœ κ·Έλ£Ήκ³Ό μœ„μƒμ„ μœ„ν•΄ ν•„μš”ν•œ λ‹€λ₯Έ 것듀을 μ œκ±°ν•œ ν›„μ˜ 첫 번째 μž‘μ—… 버전은 μ•½ 1000 λ°”μ΄νŠΈμ˜€μŠ΅λ‹ˆλ‹€). λ¬Έμžμ—΄κ³Ό μœ‘κ°ν˜•μ˜ μˆœμ„œλ₯Ό λ°”κΏˆμœΌλ‘œμ¨ μ•½ 10 λ°”μ΄νŠΈλ₯Ό μ ˆμ•½ ν•  수 μžˆλ‹€κ³  μƒκ°ν•˜μ§€λ§Œ 끝에 μ •κ·œμ‹μ„ μ™„μ „νžˆ λ‹€μ‹œ μž‘μ„±ν•΄μ•Όν•©λ‹ˆλ‹€. μ§€κΈˆ 기뢄이 μ’‹μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. GμŠ€ν…Œμ΄μ§€ λ₯Ό μƒλž΅ν•˜μ—¬ 2 λ°”μ΄νŠΈλ₯Ό μ ˆμ•½ ν•  μˆ˜λ„ μžˆμ§€λ§Œ μ†”λ£¨μ…˜ 속도λ₯Ό μƒλ‹Ήνžˆ 느리게 ν•  수 μžˆμœΌλ―€λ‘œ 골프λ₯Ό ν•  μˆ˜μžˆμ„λΏλ§Œ μ•„λ‹ˆλΌ 골프λ₯Ό μΉ  λ•ŒκΉŒμ§€ 변경을 기닀릴 κ²ƒμž…λ‹ˆλ‹€.

μ„€λͺ…

이 μ†”λ£¨μ…˜μ˜ μ£Όμš” 뢀뢄은 λ°ΈλŸ°μ‹± 그룹을 κ΄‘λ²”μœ„ν•˜κ²Œ μ‚¬μš©ν•˜κΈ° λ•Œλ¬Έμ— 이것이 μ–΄λ–»κ²Œ μž‘λ™ν•˜λŠ”μ§€ μ΄ν•΄ν•˜κ³  μ‹Άλ‹€λ©΄ μ½μ–΄λ³΄μ‹­μ‹œμ˜€. (κ·Έλ ‡μ§€ μ•ŠμœΌλ©΄ 당신을 λΉ„λ‚œν•˜μ§€ μ•Šμ„ κ²ƒμž…λ‹ˆλ‹€.)

μ†”λ£¨μ…˜μ˜ 첫 번째 λΆ€λΆ„ (즉, λ§ˆμ§€λ§‰ 두 쀄을 μ œμ™Έν•œ λͺ¨λ“  것)은 Hexagony μ†ŒμŠ€ μ½”λ“œ ν™•μž₯에 λŒ€ν•œ λ‚΄ λŒ€λ‹΅μ˜ μˆ˜μ • 된 λ²„μ „μž…λ‹ˆλ‹€ . λŒ€μƒ λ¬Έμžμ—΄μ„ κ·ΈλŒ€λ‘œ μœ μ§€ν•˜λ©΄μ„œ μœ‘κ°ν˜•μ„ κ΅¬μ„±ν•˜κ³  μ‹€μ œλ‘œ λŒ€μƒ λ¬Έμžμ—΄ μ•žμ— μœ‘κ°ν˜•μ„ κ΅¬μ„±ν•©λ‹ˆλ‹€. λ°”μ΄νŠΈλ₯Ό μ ˆμ•½ν•˜κΈ° μœ„ν•΄ 이전 μ½”λ“œλ₯Ό μ•½κ°„ λ³€κ²½ν–ˆμŠ΅λ‹ˆλ‹€.

  • λ°°κ²½ λ¬ΈμžλŠ” ×곡백 λŒ€μ‹  μž…λ ₯의 잠재적 곡백과 μΆ©λŒν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
  • no-op / wildcard λ¬ΈμžλŠ” _λŒ€μ‹  .κ·Έλ¦¬λ“œ 셀을 단어 문자둜 ν™•μ‹€ν•˜κ²Œ 식별 ν•  수 μžˆλ„λ‘ν•©λ‹ˆλ‹€.
  • μœ‘κ°ν˜•μ΄ 처음 κ΅¬μ„±λœ 후에 κ³΅λ°±μ΄λ‚˜ λ“€μ—¬ μ“°κΈ°λ₯Ό μ‚½μž…ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. 그것은 경사 μœ‘κ°ν˜•μ„ μ œκ³΅ν•˜μ§€λ§Œ μ‹€μ œλ‘œ μž‘μ—…ν•˜κΈ°κ°€ 훨씬 νŽΈλ¦¬ν•˜λ©° 인접 κ·œμΉ™μ€ 맀우 κ°„λ‹¨ν•©λ‹ˆλ‹€.

λ‹€μŒμ€ μ˜ˆμž…λ‹ˆλ‹€. λ‹€μŒ ν…ŒμŠ€νŠΈ μ‚¬λ‘€μ˜ 경우 :

ja
abcdefghij

μš°λ¦¬λŠ” μ–»λŠ”λ‹€ :

Γ—Γ—abc
Γ—defg
hij__
____Γ—
___Γ—Γ—
ja

이것을 일반적인 μœ‘κ°ν˜• λ ˆμ΄μ•„μ›ƒκ³Ό λΉ„κ΅ν•˜μ‹­μ‹œμ˜€.

  a b c
 d e f g
h i j _ _
 _ _ _ _
  _ _ _

μš°λ¦¬λŠ” 이웃이 이제 λΆμ„œμͺ½κ³Ό 남동μͺ½ 이웃을 μ œμ™Έν•˜κ³  일반적인 8 개의 무어 이웃 λͺ¨λ‘μž„을 μ•Œ 수 μžˆμŠ΅λ‹ˆλ‹€. λ”°λΌμ„œ μˆ˜ν‰, 수직 및 λ‚¨μ„œ / 뢁동 인접성을 ν™•μΈν•΄μ•Όν•©λ‹ˆλ‹€ (잘 κ°μ‹ΈλŠ” κ°€μž₯μžλ¦¬κ°€ μžˆμŠ΅λ‹ˆλ‹€). 이보닀 μž‘μ€ λ ˆμ΄μ•„μ›ƒμ„ μ‚¬μš© Γ—Γ—ν•˜λ©΄ ν•„μš”ν•  λ•Œ μ¦‰μ‹œ μœ‘κ°ν˜•μ˜ 크기λ₯Ό κ²°μ •ν•˜κΈ° μœ„ν•΄ 끝에 μžˆλŠ” λ ˆμ΄μ•„μ›ƒμ„ μ‚¬μš©ν•  수 μžˆλ‹€λŠ” λ³΄λ„ˆμŠ€ κ°€ μžˆμŠ΅λ‹ˆλ‹€.

이 폼이 κ΅¬μ„±λ˜λ©΄ 전체 λ¬Έμžμ—΄μ„ ν•œ 번 더 λ³€κ²½ν•©λ‹ˆλ‹€.

T`d`Γ€-Γ‰

이것은 숫자λ₯Ό ν™•μž₯ ASCII 문자둜 λŒ€μ²΄ν•©λ‹ˆλ‹€

Γ€ΓΓ‚ΓƒΓ„Γ…Γ†Γ‡ΓˆΓ‰

그것듀은 μœ‘κ°ν˜•κ³Ό λŒ€μƒ λ¬Έμžμ—΄ λͺ¨λ‘μ—μ„œ ꡐ체되기 λ•Œλ¬Έμ— λ¬Έμžμ—΄μ˜ 일치 여뢀에 영ν–₯을 λ―ΈμΉ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. λ˜ν•œ, 그듀은 λ¬ΈμžλΆ€ν„°μž…λ‹ˆλ‹€ \w그리고 \bμ—¬μ „νžˆ μœ‘κ°ν˜• μ„Έν¬λ‘œλ₯Ό μ‹λ³„ν•©λ‹ˆλ‹€. 이 λŒ€μ²΄ μž‘μ—…μ˜ 이점은 이제 \Dλ‹€μŒ μ •κ·œμ‹μ—μ„œ λͺ¨λ“  문자 (특히 쀄 λ°”κΏˆ 및 비쀄 λ°”κΏˆ 문자) λ₯Ό μΌμΉ˜μ‹œν‚€κΈ° μœ„ν•΄ μ‚¬μš©ν•  수 μžˆλ‹€λŠ” 것 μž…λ‹ˆλ‹€. μ—¬λŸ¬ μœ„μΉ˜μ—μ„œ 쀄 λ°”κΏˆλ˜μ§€ μ•Šμ€ 문자λ₯Ό 일치 sμ‹œμΌœμ•Ό .ν•˜κΈ° λ•Œλ¬Έμ—μ΄ μ˜΅μ…˜μ„ μ‚¬μš©ν•  수 μ—†μŠ΅λ‹ˆλ‹€ .

이제 λ§ˆμ§€λ§‰ λΉ„νŠΈ : κ²½λ‘œκ°€ μ£Όμ–΄μ§„ λ¬Έμžμ—΄κ³Ό μΌμΉ˜ν•˜λŠ”μ§€ μ—¬λΆ€λ₯Ό κ²°μ •ν•©λ‹ˆλ‹€. 이것은 단일 κ΄΄λ¬Ό μ •κ·œμ‹μœΌλ‘œ μˆ˜ν–‰λ©λ‹ˆλ‹€. μ™œ κ·ΈλŸ°μ§€ 물어봐도 λ κΉŒμš”?!?! κΈ€μŽ„, 이것은 근본적으둜 μ—­ 좔적 λ¬Έμ œμž…λ‹ˆλ‹€. μ–΄λ”˜κ°€μ—μ„œ μ‹œμž‘ν•˜μ—¬ λ¬Έμžμ—΄κ³Ό μΌμΉ˜ν•˜λŠ” ν•œ 경둜λ₯Ό μ‹œλ„ν•˜κ³  일단 경둜λ₯Ό μΆ”μ ν•˜μ§€ μ•ŠμœΌλ©΄ λ§ˆμ§€λ§‰μœΌλ‘œ μž‘λ™ ν•œ λ§ˆμ§€λ§‰ λ¬Έμžμ™€ λ‹€λ₯Έ 이웃을 μ‹œλ„ν•˜μ‹­μ‹œμ˜€. ν•œ κ°€μ§€μ •κ·œμ‹μœΌλ‘œ μž‘μ—… ν•  λ•Œ 무료둜 μ–»λŠ” 것은 μ—­ μΆ”μ μž…λ‹ˆλ‹€. 그것은 문자 κ·ΈλŒ€λ‘œ μ •κ·œμ‹ μ—”μ§„μ΄ν•˜λŠ” μœ μΌν•œ μΌμž…λ‹ˆλ‹€. λ”°λΌμ„œ μœ νš¨ν•œ 경둜λ₯Ό μ„€λͺ…ν•˜λŠ” 방법을 찾으면 (μ΄λŸ¬ν•œ μ’…λ₯˜μ˜ λ¬Έμ œμ—λŠ” μΆ©λΆ„νžˆ κΉŒλ‹€ λ‘­μ§€ 만 κ·Έλ£Ή λ°ΈλŸ°μ‹±μœΌλ‘œ κ°€λŠ₯ν•  수 μžˆμŠ΅λ‹ˆλ‹€) μ •κ·œμ‹ 엔진은 κ°€λŠ₯ν•œ λͺ¨λ“  경둜 μ€‘μ—μ„œ ν•΄λ‹Ή 경둜λ₯Ό μ°ΎλŠ” 것을 λΆ„λ₯˜ν•©λ‹ˆλ‹€. μ—¬λŸ¬ 단계λ₯Ό μ‚¬μš©ν•˜μ—¬ μˆ˜λ™μœΌλ‘œ 검색을 κ΅¬ν˜„ν•˜λŠ” 것이 κ°€λŠ₯ν•  κ²ƒμž…λ‹ˆλ‹€ ( κ³Όκ±°μ—λŠ” κ·Έλ ‡κ²Œ ν–ˆμŒ ).이 νŠΉλ³„ν•œ κ²½μš°μ—λŠ” 더 짧을 κ²ƒμž…λ‹ˆλ‹€.

μ •κ·œμ‹μœΌλ‘œ 이것을 κ΅¬ν˜„ν•  λ•Œμ˜ ν•œ κ°€μ§€ λ¬Έμ œλŠ” μ—­ 좔적 쀑에 경둜λ₯Ό 톡해 μ •κ·œμ‹ μ—”μ§„μ˜ μ»€μ„œλ₯Ό μž„μ˜λ‘œ μ•žλ’€λ‘œ 움직일 수 μ—†λ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€ (κ²½λ‘œκ°€ μ˜¬λΌκ°€κ±°λ‚˜ λ‚΄λ €κ°ˆ 수 있기 λ•Œλ¬Έμ— ν•„μš”ν•©λ‹ˆλ‹€). λŒ€μ‹  캑처 κ·Έλ£Ήμ—μ„œ 자체 β€œμ»€μ„œβ€λ₯Ό μΆ”μ ν•˜κ³  λͺ¨λ“  λ‹¨κ³„μ—μ„œ μ—…λ°μ΄νŠΈν•©λ‹ˆλ‹€ (μΌμ‹œμ μœΌλ‘œ μ»€μ„œ μœ„μΉ˜λ‘œ μΌμ‹œμ μœΌλ‘œ 이동할 수 있음). λ˜ν•œ 이전에 ν˜„μž¬ μœ„μΉ˜λ₯Ό λ°©λ¬Έν•˜μ§€ μ•Šμ•˜λŠ”μ§€ ν™•μΈν•˜λŠ” 데 μ‚¬μš©ν•  λͺ¨λ“  κ³Όκ±° μœ„μΉ˜λ₯Ό μ €μž₯ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

이제 μ‹œμž‘ν•˜κ² μŠ΅λ‹ˆλ‹€. λ‹€μŒμ€ 이름이 μ§€μ •λœ κ·Έλ£Ή, λ“€μ—¬ μ“°κΈ°, μ΄μ›ƒμ˜ λ¬΄μž‘μœ„ μˆœμ„œκ°€ 적고 일뢀 μ£Όμ„μ΄μžˆλŠ” μ•½κ°„ 더 정식 λ²„μ „μ˜ μ •κ·œ ν‘œν˜„μ‹μž…λ‹ˆλ‹€.

\A
# Store initial cursor position in <pos>
(?<pos>\D*)
(?(_)
  # If we start on a wildcard, just skip to the first character of the target.
  \D*ΒΆ.
|
  # Otherwise, make sure that the target starts with this character.
  (?<first>.)\D*ΒΆ\k<first>
)
(?:
  # Match 0 or more subsequent characters by moving the cursor along the path.
  # First, we store the character to be matched in <next>.
  (?<next>.)
  # Now we optionally push an underscore on top (if one exists in the string).
  # Depending on whether this done or not (both of which are attempted by
  # the engine's backtracking), either the exact character, or an underscore
  # will respond to the match. So when we now use the backreference \k<next>
  # further down, it will automatically handle wildcards correctly.
  (?<=(?<next>_)\D+)?
  # This alternation now simply covers all 6 possible neighbours as well as
  # all 6 possible wrapped edges.
  # Each option needs to go into a separate lookbehind, because otherwise
  # the engine would not backtrack through all possible neighbours once it
  # has found a valid one (lookarounds are atomic).
  # In any case, if the new character is found in the given direction, <pos>
  # will have been updated with the new cursor position.
  (?:
    # Try moving east.
    (?<=(?<pos>\k<pos>.)\k<next>\D*)
  |
    # Try moving west.
    (?<=(?<pos>\D*)\k<next>(?<=\k<pos>)\D*)
  |
    # Store the horizontal position of the cursor in <x> and remember where
    # it is (because we'll need this for the next two options).
    (?<=\k<pos>(?<skip>.(?<x>.)*ΒΆ\D*))
    (?:
      # Try moving north.
      (?<=(?<pos>\D*)\k<next>(?>(?<-x>.)*)ΒΆ.*\k<skip>)
    |
      # Try moving north-east.
      (?<=(?<pos>\D*)(?=\k<next>)(?>(?<-x>.)+)ΒΆ.*\k<skip>)
    )
  |
    # Try moving south.
    (?<=(?<pos>\k<pos>.(?>(?<-x>.)*)ΒΆ.*)\k<next>(?<x>.)*ΒΆ\D*)
  |
    # Try moving south-east.
    (?<=(?<pos>\k<pos>(?>(?<-x>.)*)ΒΆ.*)\k<next>(?<x>.)*ΒΆ\D*)
  |
    # Store the number of 'Γ—' at the end in <w>, which is one less than the
    # the side-length of the hexagon. This happens to be the number of lines
    # we need to skip when wrapping around certain edges.
    (?<=(?<w>Γ—)*ΒΆ.*)
    (?:
      # Try wrapping around the east edge.
      (?<=(?<pos>\k<pos>.(?>(?<-w>ΒΆ.*)*))^\k<next>\D*)
    |
      # Try wrapping around the west edge.
      (?<=(?<pos>\D*)\k<next>(?>(?<-w>ΒΆ.*)*)(?<=\k<pos>)^\D*)
    |
      # Try wrapping around the south-east edge.
      (?<=(?<pos>\k<pos>\b.*(?(w)!)(?<-w>ΒΆ.*)*)\k<next>Γ—*ΒΆ\D*)
    |
      # Try wrapping around the north-west edge.
      (?<=(?<pos>\D*\b)\k<next>.*(?(w)!)(?<-w>ΒΆ.*)*(?<=\k<pos>.)\b\D*)
    )
  |
    # Try wrapping around the south edge.
    (?<=(?<pos>\k<pos>.(?>(?<-x>.)*ΒΆ\D*))\k<next>(?<x>\w)*\W+.+)
  |
    # Try wrapping around the north edge.
    (?<=(?<pos>.*)\k<next>(?>(?<-x>.)*ΒΆ\D*)(?<=\k<pos>.)(?<x>\w)*\W+.+)
  )
  # Copy the current cursor position into <current>.
  (?<=\k<pos>(?<current>\D*).+)
  # Make sure that no matter how many strings we pop from our stack of previous
  # cursor positions, none are equal to the current one (to ensure that we use
  # each cell at most once).
  (?<!\k<pos>\k<current>.*(?<-pos>.)+)
)*
# Finally make sure that we've reached the end of the string, so that we've
# successfully matched all characters in the target string.
\Z

λ‚˜λŠ” 일반적인 아이디어가 μ΄κ²ƒμœΌλ‘œλΆ€ν„° λŒ€λž΅ λͺ…ν™•ν•˜κΈ°λ₯Ό λ°”λžλ‹ˆλ‹€. 경둜λ₯Ό 따라 μ›€μ§μ΄λŠ” λ™μž‘ 쀑 ν•˜λ‚˜μ˜ μž‘λ™ 방식에 λŒ€ν•œ 예λ₯Ό λ“€μ–΄ μ»€μ„œλ₯Ό 남μͺ½μœΌλ‘œ μ›€μ§μ΄λŠ” λΉ„νŠΈλ₯Ό μ‚΄νŽ΄ λ³΄κ² μŠ΅λ‹ˆλ‹€.

(?<=(?<pos>\k<pos>.(?>(?<-x>.)*)ΒΆ.*)\k<next>(?<x>.)*ΒΆ\D*)

lookbehindsλŠ” 였λ₯Έμͺ½μ—μ„œ μ™Όμͺ½μœΌλ‘œ (λ˜λŠ” μœ„μ—μ„œ μ•„λž˜λ‘œ) μ½μ–΄μ•Όν•©λ‹ˆλ‹€. μˆœμ„œλŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

(?<=
  (?<pos>
    \k<pos>       # Check that this is the old cursor position.
    .             # Match the character directly on top of the new one.
    (?>(?<-x>.)*) # Match the same amount of characters as before.
    ΒΆ.*           # Skip to the next line (the line, the old cursor is on).
  )               # We will store everything left of here as the new
                  # cursor position.
  \k<next>        # ...up to a match of our current target character.
  (?<x>.)*        # Count how many characters there are...
  ΒΆ\D*            # Skip to the end of some line (this will be the line below
                  # the current cursor, which the regex engine's backtracking
                  # will determine for us).
)

\k<pos>μ‹€μ œλ‘œ λ¬Έμžμ—΄μ˜ μ‹œμž‘ 뢀뢄에 λ„λ‹¬ν•˜λ„λ‘ 액컀λ₯Ό μ•žμ— 배치 ν•  ν•„μš”λŠ” μ—†μŠ΅λ‹ˆλ‹€ . <pos>항상 Γ—λ‹€λ₯Έ κ³³μ—μ„œλŠ” 찾을 μˆ˜μ—†λŠ” μ–‘μœΌλ‘œ μ‹œμž‘ ν•˜λ―€λ‘œ 이미 μ•”μ‹œ 적 액컀 μ—­ν• μ„ν•©λ‹ˆλ‹€.

이 κ²Œμ‹œλ¬Όμ„ ν•„μš” μ΄μƒμœΌλ‘œ 늘리고 μ‹Άμ§€ μ•ŠμœΌλ―€λ‘œ λ‹€λ₯Έ 11 κ°€μ§€ 사둀에 λŒ€ν•΄μ„œλŠ” μžμ„Ένžˆ μ„€λͺ…ν•˜μ§€ μ•Šμ§€λ§Œ μ›μΉ™μ μœΌλ‘œ λͺ¨λ‘ λΉ„μŠ·ν•˜κ²Œ μž‘λ™ν•©λ‹ˆλ‹€. <next>λ°ΈλŸ°μ‹± 그룹을 μ‚¬μš©ν•˜μ—¬ 이전 μ»€μ„œ μœ„μΉ˜μ—μ„œ νŠΉμ • (ν—ˆμš© κ°€λŠ₯ν•œ) λ°©ν–₯으둜 찾을 수 μžˆλŠ”μ§€ ν™•μΈν•œ λ‹€μŒ μΌμΉ˜ν•˜λŠ” λ¬Έμžμ—΄μ„μ—μ„œ μƒˆ μ»€μ„œ μœ„μΉ˜λ‘œ μ €μž₯ <pos>ν•©λ‹ˆλ‹€.


λ‹΅λ³€

파이썬 3, 990 943 770 709 λ°”μ΄νŠΈ

첫 번째 λŒ€λ‹΅μž…λ‹ˆλ‹€.

νŽΈμ§‘ : 골프 인접 λͺ©λ‘ λ§Œλ“€κΈ°. λ‚˜λŠ” 이제 μ•½κ°„ λ‹€λ₯Έ 곡식을 μ‚¬μš©ν•©λ‹ˆλ‹€

νŽΈμ§‘ 2 : λΆˆν•„μš”ν•œ 보풀을 μ œκ±°ν•˜κ³  훨씬 더 골프λ₯Ό μ³€λ‹€.

νŽΈμ§‘ 3 : λͺ©λ‘μ˜ μƒ‰μΈμ—μ„œ μ’Œν‘œλ‘œ λ³€ν™˜ν•˜κΈ°μœ„ν•œ μ½”λ“œκ°€ λ‹¨μΆ•λ˜μ–΄ λͺ‡ κ°€μ§€ 사항이 μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

λ°”μ΄νŠΈμ˜ λŒ€λΆ€λΆ„μ€ 인접 λͺ©λ‘μ„ λ§Œλ“œλŠ” 것과 관련이 μžˆμŠ΅λ‹ˆλ‹€ (골프 κ°€λŠ₯성이 κ°€μž₯ λ†’μŠ΅λ‹ˆλ‹€). κ·Έλ•ŒλΆ€ν„°λŠ” μ†”λ£¨μ…˜μ„ κ°•μ œλ‘œ μ²˜λ¦¬ν•˜λŠ” κ°„λ‹¨ν•œ λ¬Έμ œμž…λ‹ˆλ‹€ (더 적은 λ°”μ΄νŠΈλ‘œ μˆ˜ν–‰ ν•  수 있음).

골프 :

from math import*
b=abs
c=max
e=range
f=len
A=input()
B=input()
C=ceil(sqrt((f(A)-.25)/3)+.5)
D=3*C*~-C+1
E=2*C-1
F=C-1
A+='.'*(D-f(A))
G=[set()for x in e(D)]
I=lambda H:sum(E+.5-b(t-F+.5)for t in e(int(H+F)))
for x in e(D):
 r=sum([[J-F]*(E-b(J-F))for J in e(E)],[])[x];q=x-I(r);s=-q-r;a=lambda q,r:G[x].add(int(q+I(r)));m=c(map(b,[q,r,s]))
 if m==F:
  if q in(m,-m):a(-q,-s)
  if r in(m,-m):a(-s,-r)
  if s in(m,-m):a(-r,-q)
 for K,L in zip([1,0,-1,-1,0,1],[0,1,1,0,-1,-1]):
  M,H=q+K,r+L
  if c(map(b,[M,H,-M-H]))<C:a(M,H)
def N(i,O,P):
 Q=O and O[0]==A[i]or'.'==A[i];R=0
 if(2>f(O))*Q:R=1
 elif Q:R=c([(x not in P)*N(x,O[1:],P+[i])for x in G[i]]+[0])
 return R
print(c([N(x,B,[])for x in e(D)])*(f(B)<=D))

Ungolfed w / μ„€λͺ… :

from math import*

#Rundown of the formula:
# * Get data about the size of the hexagon
# * Create lookup tables for index <-> coordinate conversion
#   * q=0, r=0 is the center of the hexagon
#   * I chose to measure in a mix of cubic and axial coordinates,
#     as that allows for easy oob checks and easy retrevial
# * Create the adjacency list using the lookup tables, while
#   checking for wrapping
# * Brute-force check if a path in the hexagon matches the
#   expression

# shorten functions used a lot
b=abs
c=max
e=range

# Get input

prog=input()
expr=input()

# sdln = Side length
# hxln = Closest hexagonal number
# nmrw = Number of rows in the hexagon
# usdl = one less than the side length. I use it a lot later

sdln=ceil(sqrt((len(prog)-.25)/3)+.5)
hxln=3*sdln*~-sdln+1
nmrw=2*sdln-1
usdl=sdln-1

# Pad prog with dots

prog+='.'*(hxln-len(prog))

# nmbf = Number of elements before in each row
# in2q = index to collum
# in2r = index to row

nmbf=[0]*nmrw
in2q=[0]*hxln
in2r=[0]*hxln

#  4    5
#   \  /
# 3 -- -- 0
#   /  \
#  2    1

# dirs contains the q,r and s values needed to move a point
# in the direction refrenced by the index

qdir=[1,0,-1,-1,0,1]
rdir=[0,1,1,0,-1,-1]

# generate nmbf using a summation formula I made

for r in e(nmrw-1):
    nmbf[r+1]=int(nmbf[r]+nmrw+.5-b(r-sdln+1.5))

# generate in2q and in2r using more formulas
# cntr = running counter

cntr=0
for r in e(nmrw):
    bgnq=c(-r,1-sdln)
    for q in e(nmrw-b(r-sdln+1)):
        in2q[cntr]=bgnq+q
        in2r[cntr]=r-usdl
        cntr+=1

# adjn = Adjacency sets

adjn=[set()for x in e(hxln)]

# Generate adjacency sets

for x in e(hxln):
    #Get the q,r,s coords
    q,r=in2q[x],in2r[x]
    s=-q-r
    # a = function to add q,r to the adjacency list
    a=lambda q,r:adjn[x].add(q+nmbf[r+usdl])
    # m = absolute value distance away from the center
    m=c(map(b,[q,r,s]))
    # if we are on the edge (includes corners)...
    if m==usdl:
        # add the only other point it wraps to
        if q in(m,-m):
            a(-q,-s)
        if r in(m,-m):
            a(-s,-r)
        if s in(m,-m):
            a(-r,-q)
    # for all the directions...
    for d in e(6):
        # tmp{q,r,s} = moving in direction d from q,r,s
        tmpq,tmpr=q+qdir[d],r+rdir[d]
        # if the point we moved to is in bounds...
        if c(map(b,[tmpq,tmpr,-tmpq-tmpr]))<sdln:
            # add it
            a(tmpq,tmpr)

# Recursive path checking function
def mtch(i,mtst,past):
    # dmch = Does the place we are on in the hexagon match
    #        the place we are in the expression?
    # out = the value to return
    dmch=mtst and mtst[0]==prog[i]or'.'==prog[i]
    out=0
    # if we are at the end, and it matches...
    if(2>len(mtst))*dmch:
        out=1
    # otherwise...
    elif dmch:
        # Recur in all directions that we haven't visited yet
        # replace '*' with 'and' to speed up the recursion
        out=c([(x not in past)*mtch(x,mtst[1:],past+[i])for x in adjn[i]]+[0])
    return out

# Start function at all the locations in the hexagon
# Automatically return false if the expression is longer
# than the entire hexagon
print(c([mtch(x,expr,[])for x in e(hxln)])*(len(expr)<=hxln))

λ ˆν‹° λ‚˜μ— λ„ˆλ¬΄ κ°€κΉŒμ΄! πŸ™ 예, λ ˆν‹° λ‚˜λ₯Ό 이겼닀!


λ‹΅λ³€

μžλ°” 슀크립트 (ES6), 511 500 496 λ°”μ΄νŠΈ

(H,N)=>{C=(x,y)=>(c[x]=c[x]||[])[y]=y;S=d=>(C(x,y=x+d),C(y,x),C(s-x,s-y),C(s-y,s-x));r=(x,p,v)=>{p<N.length?(v[x]=1,c[x].map(n=>!v[n]&&(H[n]==N[p]||H[n]=='.')&&r(n,p+1,v.slice()))):K=1};for(e=x=K=0;(s=3*e*++e)<(l=H.length)-1;);H+='.'.repeat(s+1-l);for(a=[],b=[],c=[[]],w=e;w<e*2;){a[w-e]=x;b[e*2-w-1]=s-x;for(p=w;p--;x++){w-e||S(s-e+1);w<e*2-1&&(S(w),S(w+1));p&&S(1)}a[w]=x-1;b[e*3-++w]=s-x+1}a.map((v,i)=>S(b[i]-(x=v)));[N[0],'.'].map(y=>{for(x=-1;(x=H.indexOf(y,x+1))>-1;r(x,1,[]));});return K}

μ–Έ 골프 및 λŒ“κΈ€

// Entry point
//   H = haystack (the string the hexagon is filled with)
//   N = needle (the substring we're looking for)
(H, N) => {
  // C(x, y) - Helper function to save a connection between two locations.
  //   x = source location
  //   y = target location
  C = (x, y) => (c[x] = c[x] || [])[y] = y;

  // S(d) - Helper function to save reciprocal connections between two locations
  //        and their symmetric counterparts.
  //   d = distance between source location (x) and target location
  S = d => (C(x, y = x + d), C(y, x), C(s - x, s - y), C(s - y, s - x));

  // r(x, p, v) - Recursive path search.
  //   x = current location in hexagon
  //   p = current position in needle
  //   v = array of visited locations
  r = (x, p, v) => {
    p < N.length ?
      (v[x] = 1, c[x].map(n => !v[n] && (H[n] == N[p] || H[n] == '.') &&
      r(n, p + 1, v.slice())))
    :
      K = 1
  };

  // Compute e = the minimum required edge width of the hexagon to store the haystack.
  // Also initialize:
  //   x = current location in hexagon
  //   l = length of haystack
  //   s = size of hexagon (number of locations - 1)
  //   K = fail/success flag
  for(e = x = K = 0; (s = 3 * e * ++e) < (l = H.length) - 1;);

  // Pad haystack with '.'
  H += '.'.repeat(s + 1 - l);

  // Build connections c[] between locations, using:
  //   x = current location
  //   w = width of current row
  //   p = position in current row
  // Also initialize:
  //   a[] = list of locations on top left and top right edges
  //   b[] = list of locations on bottom left and bottom right edges
  for(a = [], b = [], c = [[]], w = e; w < e * 2;) {
    a[w - e] = x;
    b[e * 2 - w - 1] = s - x;

    for(p = w; p--; x++) {
      // connection between top and bottom edges
      w - e || S(s - e + 1);
      // connections between current location and locations below it
      w < e * 2 - 1 && (S(w), S(w + 1));
      // connection between current location and next location
      p && S(1)
    }
    a[w] = x - 1;
    b[e * 3 - ++w] = s - x + 1
  }

  // Save connections between top left/right edges and bottom left/right edges.
  a.map((v, i) => S(b[i] - (x = v)));

  // Look for either the first character of the needle or a '.' in the haystack,
  // and use it as the starting point for the recursive search. All candidate
  // locations are tried out.
  [N[0], '.'].map(y => {
    for(x = -1; (x = H.indexOf(y, x + 1)) > -1; r(x, 1, []));
  });

  // Return fail/success flag.
  return K
}

ν…ŒμŠ€νŠΈ 사둀

μ•„λž˜ 슀 λ‹ˆνŽ«μ€ λͺ¨λ“  μ§„μ‹€λ˜κ³  ν—ˆμœ„ ν…ŒμŠ€νŠΈ 사둀λ₯Ό μ•ˆλ‚΄ν•©λ‹ˆλ‹€.

let f =
(H,N)=>{C=(x,y)=>(c[x]=c[x]||[])[y]=y;S=d=>(C(x,y=x+d),C(y,x),C(s-x,s-y),C(s-y,s-x));r=(x,p,v)=>{p<N.length?(v[x]=1,c[x].map(n=>!v[n]&&(H[n]==N[p]||H[n]=='.')&&r(n,p+1,v.slice()))):K=1};for(e=x=K=0;(s=3*e*++e)<(l=H.length)-1;);H+='.'.repeat(s+1-l);for(a=[],b=[],c=[[]],w=e;w<e*2;){a[w-e]=x;b[e*2-w-1]=s-x;for(p=w;p--;x++){w-e||S(s-e+1);w<e*2-1&&(S(w),S(w+1));p&&S(1)}a[w]=x-1;b[e*3-++w]=s-x+1}a.map((v,i)=>S(b[i]-(x=v)));[N[0],'.'].map(y=>{for(x=-1;(x=H.indexOf(y,x+1))>-1;r(x,1,[]));});return K}

let truthy = [
  ["a","a"],
  ["ab","a"],
  ["ab","b"],
  ["ab","ba"],
  ["ab","aba"],
  ["ab","&"],
  ["ab","#7.J!"],
  ["ab","aaaaaa"],
  ["ab","bgjneta"],
  ["ab","cebtmaa"],
  ["abcdefg","dfabcg"],
  ["AbCDeFG","GCbAeFD"],
  ["aaaabbb","aaababb"],
  ["abcdefghijklmnopqrs","alq"],
  ["abcdefghijklmnopqrs","aqnmiedh"],
  ["abcdefghijklmnopqrs","adhcgkorbefjimnqlps"],
  ["11122233344455","12341345123245"],
  ["abcdefgh","h%a"],
  ["abcdefghijklm","a)(@#.*b"],
  ["abcdefghijklm","a)(@#.*i"],
  ["abcdefghij","ja"],
  ["abcdefghijklmno","kgfeia"],
  ["abcdefghijklmno","mmmmmiea"],
  ["abcdefghijklmno","mmmmmlae"],
  ["abcdefghijklmno","ja"],
  ["abcdefghijklmnopqrs","eijfbadhmnokgcsrql"]
];

let falsy = [
  ["a","b"],
  ["a","%"],
  ["a","."],
  ["a","aa"],
  ["a","a."],
  ["ab","#7.J!*"],
  ["ab","aaaaaaa"],
  ["ab","aaaabaaa"],
  ["ab","123456"],
  ["abcdefg","bfgedac"],
  ["abcdefg","gecafdb"],
  ["abcdefg","GCbaeFD"],
  ["aaaabbb","aaaaabb"],
  ["abcdefghijklmnopqrs","aqrcgf"],
  ["abcdefghijklmnopqrs","adhlcgknbeifjm"],
  ["abcdefghijklmnopqrs","ja"],
  ["abcdefghijklm","a)(@#.*&"],
  ["abcdefghijklmno","a)(@bfeijk"],
  ["abcdefghijklmno","kgfeic"],
  ["abcdefghijklmno","mmmmmmiea"]
];

console.log(
  'Testing truthy test cases:',
  truthy.every(v => f(v[0], v[1])) ? 'passed' : 'failed'
);
console.log(
  'Testing falsy test cases:',
  falsy.every(v => !f(v[0], v[1])) ? 'passed' : 'failed'
);

λ‹΅λ³€