about summary refs log tree commit diff
path: root/users/Profpatsch/advent-of-code/2020/04/main.py
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2024-10-05T12·18+0200
committerProfpatsch <mail@profpatsch.de>2024-10-05T13·49+0000
commitc925902015b163706f860b7540148fb6302d98dd (patch)
treeee062bfcfa924abfafaf04aabbec28ff0eb12bd8 /users/Profpatsch/advent-of-code/2020/04/main.py
parent9c8087d705456ab6a0ec12a30a63e54cf3d8b0f2 (diff)
chore(users/Profpatsch): remove AoC stuff r/8771
Change-Id: Ifb134053c0f92dfdb4f2c0a3418c0c6a7a1a8507
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12574
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch/advent-of-code/2020/04/main.py')
-rw-r--r--users/Profpatsch/advent-of-code/2020/04/main.py104
1 files changed, 0 insertions, 104 deletions
diff --git a/users/Profpatsch/advent-of-code/2020/04/main.py b/users/Profpatsch/advent-of-code/2020/04/main.py
deleted file mode 100644
index 36bbed7146d6..000000000000
--- a/users/Profpatsch/advent-of-code/2020/04/main.py
+++ /dev/null
@@ -1,104 +0,0 @@
-import sys
-import itertools
-import re
-import pprint
-
-def get_entry(fd):
-    def to_dict(keyval):
-        res = {}
-        for (k, v) in keyval:
-            assert k not in res
-            res[k] = v
-        return res
-
-    res = []
-    for line in fd:
-        if line == "\n":
-            yield to_dict(res)
-            res = []
-        else:
-            line = line.rstrip()
-            items = line.split(" ")
-            for i in items:
-                res.append(i.split(":", maxsplit=2))
-
-def val_hgt(hgt):
-    m = re.fullmatch(r'([0-9]+)(cm|in)', hgt)
-    if m:
-        (i, what) = m.group(1,2)
-        i = int(i)
-        if what == "cm":
-            return i >= 150 and i <= 193
-        elif what == "in":
-            return i >= 59 and i <= 76
-        else:
-            return False
-
-required_fields = [
-    { "name": "byr",
-      "check": lambda s: int(s) >= 1920 and int(s) <= 2002
-    },
-    { "name": "iyr",
-      "check": lambda s: int(s) >= 2010 and int(s) <= 2020
-    },
-    { "name": "eyr",
-      "check": lambda s: int(s) >= 2020 and int(s) <= 2030,
-    },
-    { "name": "hgt",
-      "check": lambda s: val_hgt(s)
-    },
-    { "name": "hcl",
-      "check": lambda s: re.fullmatch(r'#[0-9a-f]{6}', s)
-    },
-    { "name": "ecl",
-      "check": lambda s: re.fullmatch(r'amb|blu|brn|gry|grn|hzl|oth', s)
-    },
-    { "name": "pid",
-      "check": lambda s: re.fullmatch(r'[0-9]{9}', s)
-    },
-    # we should treat it as not required
-    # "cid"
-]
-
-required_dict = {}
-for f in required_fields:
-    required_dict[f["name"]] = f
-
-def validate(keyval):
-    if keyval[0] not in required_dict:
-        return { "ok": keyval }
-    if required_dict[keyval[0]]["check"](keyval[1]):
-        return { "ok": keyval }
-    else:
-        return { "validation": keyval }
-
-def all_fields(entry):
-    missing = []
-    for r in required_dict:
-        if r not in e:
-            missing.append(r)
-    if missing == []:
-        return { "ok": entry }
-    else:
-        return { "missing": missing }
-
-count=0
-for e in get_entry(sys.stdin):
-    a = all_fields(e)
-    if a.get("ok", False):
-        res = {}
-        bad = False
-        for keyval in e.items():
-            r = validate(keyval)
-            if r.get("validation", False):
-                bad = True
-            res[keyval[0]] = r
-        if bad:
-            pprint.pprint({ "validation": res })
-        else:
-            pprint.pprint({ "ok": e })
-            count = count+1
-    else:
-        pprint.pprint(a)
-
-print(count)