~aperezdc/aoc2022

d496cd3c36471ffe3fb0c76feaa4af145cc818be — Adrian Perez de Castro 2 years ago 99338f8
Day 3, factor out some common code
2 files changed, 12 insertions(+), 5 deletions(-)

R day03/{day03.py => common.py} -rwxr-xr-x => -rw-r--r--
A day03/day03a.py
R day03/day03.py => day03/common.py +0 -5
@@ 21,8 21,3 @@ def item_priority(item):
        return item - ord('A') + 27
    else:
        assert False, "unreachable"

import sys

print(sum((item_priority(item) for item in (find_common_item(line.strip()) for
                                            line in sys.stdin.readlines()))))

A day03/day03a.py => day03/day03a.py +12 -0
@@ 0,0 1,12 @@
#! /usr/bin/env python3
# vim:fenc=utf-8
#
# Copyright © 2022 Adrian Perez de Castro <aperez@igalia.com>
#
# Distributed under terms of the MIT license.

from common import find_common_item, item_priority
import sys

print(sum((item_priority(item) for item in (find_common_item(line.strip()) for
                                            line in sys.stdin.readlines()))))