diff options
| author | Alex Pickering <alex@cogarr.net> | 2025-02-07 12:49:48 -0600 |
|---|---|---|
| committer | Alex Pickering <alex@cogarr.net> | 2025-02-07 12:49:48 -0600 |
| commit | 3555be54c2abb8d5ece008a60dbdfbde0ffbddd7 (patch) | |
| tree | 278876284d07118ecdea5c48cb6453f3122887f0 /06/1.lua | |
| download | advent_of_code_2022-master.tar.gz advent_of_code_2022-master.tar.bz2 advent_of_code_2022-master.zip | |
Diffstat (limited to '06/1.lua')
| -rw-r--r-- | 06/1.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/06/1.lua b/06/1.lua new file mode 100644 index 0000000..68ea3e2 --- /dev/null +++ b/06/1.lua @@ -0,0 +1,28 @@ +require("ext") +local line = io.read("*a") + +local buf = {} +for i = 1,14 do + table.insert(buf, line:sub(i,i)) +end +function checkbuf() + local s,u = {},0 + for _,v in pairs(buf) do + if not s[v] then + s[v] = true + u = u + 1 + end + end + if u == 14 then + return true + end +end +if checkbuf() then print(14) end +for i = 15,#line do + table.remove(buf,1) + table.insert(buf,line:sub(i,i)) + if checkbuf() then + print(i) + break + end +end |
