26 lines
508 B
Lua
26 lines
508 B
Lua
io.input("test")
|
|
io.input("input")
|
|
local s = io.read("a")
|
|
|
|
function endOfMarker( n ) -- n is the window size
|
|
local i=1
|
|
repeat
|
|
local window = string.sub(s,i,i+n-1)
|
|
local repeats = false
|
|
local chars = {}
|
|
for j=1,n do
|
|
local c = string.sub(window,j,j)
|
|
if chars[c] then
|
|
repeats = true
|
|
break
|
|
else chars[c] = true
|
|
end
|
|
end
|
|
i = i + 1
|
|
until not repeats or i>#s
|
|
return i+n-2
|
|
end
|
|
|
|
print("part 1", endOfMarker(4))
|
|
print("part 2", endOfMarker(14))
|