#Lua - 506 (not yet golfed) I felt kinda bad that you hadn't received any submission for your well thought out challenge, so I threw this together. It was quit fun inferring what the minimum distinguishable properties the path must have from the information you gave. I hope I got it right... AND correctly implemented it. a=io.read("*l") n=tonumber(string.match(a, "%d+")) m=string.match(a,"[a-z]+") o="" for i=1,n do for k=1,n^2,n do o=o..m:sub(i+k-1,i+k-1) end end q={m,o} for g=1,n^2 do for u=1,2 do l=q[u]:sub(g,g) for r=1,n do i=1 t=0 e=0 while i do s,e=q[u]:find(string.rep(l,r), e+1) if s then if s-(e-s)-i-1==n or t==0 then t=t+1 i=s end else i=nil end end if t*r==n then print(l) os.exit()end end end end It can be tested with: lua divisorPath.lua "input" If a wild challenger appears, I'll look to golf my code for what it's worth.