about summary refs log tree commit diff
path: root/aoc/2022/03/part-one.nim
blob: 0f16754a657cf6e0b041c4dd7e658ea0d7e585a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import math
import sequtils
import sets
import strutils

func priority(item: int): int =
  result = item - 96
  if result < 0:
    result += 58

func examine(sack: string): int =
  let
    size = sack.len div 2
    other = to_hash_set sack[0 ..< size]
  for c in sack[size .. ^1]:
    if c in other:
      return priority ord c

echo sum stdin.read_all.strip.split_lines.map examine