/ 3.py
3.py
 1  #!/usr/bin/python3
 2  
 3  # run it as
 4  # ./3.py [ --one | --two ] < inputs/3
 5  
 6  import sys
 7  
 8  
 9  def value(value):
10      return ord(value) - 96 if value.islower() else ord(value) - 38
11  
12  if '--one' in sys.argv:
13      total = 0
14      for line in sys.stdin:
15          half_length = len(line) // 2
16          half1, half2 = line[:half_length], line[half_length:]
17          # I guess the idea here was to utilize the fact that exactly one item is mismatched
18          # So I could have used less computationally-intensive code than next line
19          common = (set(half1) & set(half2)).pop()
20          total += value(common)
21      print(total)
22  elif '--two' in sys.argv:
23      total = 0
24      while True:
25          three_packs = [sys.stdin.readline() for x in range(3)]
26          if len(three_packs[0]) == 0:
27              break
28          sets = [set(line.strip()) for line in three_packs]
29          total += value((sets[0] & sets[1] & sets[2]).pop())
30      print(total)