forked from adventofcode/logan_2022
33 lines
864 B
Lua
33 lines
864 B
Lua
|
file = io.open("input")
|
||
|
io.input(file)
|
||
|
|
||
|
score = 0
|
||
|
|
||
|
for line in file:lines() do
|
||
|
local first = string.sub(line, 1, #line/2)
|
||
|
local second = string.sub(line, #line/2 + 1, #line)
|
||
|
print(#first)
|
||
|
print(#second)
|
||
|
for i = 1, #first do
|
||
|
local char = string.sub(first, i, i)
|
||
|
|
||
|
if string.match(second, char) then
|
||
|
print(char)
|
||
|
if char == string.upper(char) then
|
||
|
--print(string.byte(char) - string.byte("A") + 27)
|
||
|
score = score + string.byte(char) - string.byte("A") + 27
|
||
|
goto continue
|
||
|
elseif char == string.lower(char) then
|
||
|
--print(string.byte(char) - string.byte("a"))
|
||
|
score = score + string.byte(char) - string.byte("a") + 1
|
||
|
goto continue
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
::continue::
|
||
|
end
|
||
|
|
||
|
print(score)
|