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 /03/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 '03/1.lua')
| -rw-r--r-- | 03/1.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/03/1.lua b/03/1.lua new file mode 100644 index 0000000..b9a97a3 --- /dev/null +++ b/03/1.lua @@ -0,0 +1,26 @@ +#!/usr/bin/env lua +require("ext") +local sacks = {} +local common = {} +for line in io.lines() do + local compart_1 = {} + for i = 1,(#line/2) do + compart_1[line:sub(i,i)] = true + end + for i = (#line/2+1), #line do + local sb = line:sub(i,i) + if compart_1[sb] then + table.insert(common,sb) + break + end + end +end +local sum = 0 +for _, p in pairs(common) do + if p >= 'a' and p <= 'z' then + sum = sum + (p:byte() - ('a'):byte() + 1) + elseif p >= 'A' and p <= 'Z' then + sum = sum + (p:byte() - ('A'):byte() + 1) + 26 + end +end +print(sum) |
