Advertisement
icarussiano

day 19 part 1

Dec 19th, 2023 (edited)
755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. workflows, ratings = open("input").read().split('\n\n')
  2. workflows = {name: rules[:-1].split(',') for name, rules in (line.split('{') for line in workflows.splitlines())}
  3. ratings= [x[1:-1].split(",") for x in ratings.splitlines()]
  4. accepted = 0
  5. for rating in ratings:
  6.     name = 'in'
  7.     for _ in rating:
  8.         exec(_)
  9.     while name not in 'AR':
  10.         for rule in workflows[name][:-1]:
  11.             if eval(rule.split(':')[0]):
  12.                 name = rule.split(':')[1]
  13.                 break
  14.         else:
  15.             name = workflows[name][-1]
  16.     accepted += x+m+a+s if name == 'A' else 0
  17. print(accepted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement