ํƒœ๊ทธ ๋ณด๊ด€๋ฌผ: 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'
);

๋‹ต๋ณ€