From 3be62b50f80c1d67d9867775242c33e88266fec8 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 3 Dec 2022 06:29:07 +0100 Subject: Add 2022 day 3 solutions --- 2022/03/input | 300 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2022/03/puzzle-1.py | 27 +++++ 2022/03/puzzle-2.py | 31 ++++++ 3 files changed, 358 insertions(+) create mode 100644 2022/03/input create mode 100755 2022/03/puzzle-1.py create mode 100755 2022/03/puzzle-2.py (limited to '2022') diff --git a/2022/03/input b/2022/03/input new file mode 100644 index 0000000..e3223a0 --- /dev/null +++ b/2022/03/input @@ -0,0 +1,300 @@ +hDsDDttbhsmshNNWMNWGbTNqZq +VQfjnlFvnQFRdZWdVtqMGdWW +zvvvRnFFfjjlRBlBPzgQgRvvmtrmhHcptLHCDhcHHmLsBmsB +FrzFvvdTDcTnmTzdDTTzdvWmjhgVPrhSljSQSPwPjPjPjSVC +sMsGbqGsbbRqRbBMBGRMbLpNSSpjhlQljHVClhjgPjjPhlVp +sNbGtJbMfssNtvcnWFVmnvDd +TNfmdFJmfdZMQffVRQVV +jVHBCcDSjWrMZjvg +SShSbCGpcBtBtwtVLJJddmtLmT +CtpNftbNWbtSJDHqGZJFLfLr +dPsHlsRBHcZdqDFDZwwJ +snjVlvTPlPjVlQlHWjpSmzgNNzSmtpSm +qhZtSVqCqThGcGzZnnfZcB +WbddWbDwrBzcpzHpBb +DBBMFWRJDrDFWLWljCqjQjFvtCsqTjqs +vhFTzRzzTmPvbplWFtQttQQZtZhMZqcqSQ +fJVCfDfJNCLDwJNGmssZgwqgZcmtgcms +VmdVNLHGGVDBdfLCHnLGHnbWpTplWbddRTlzplWPpbFp +smwtNVqRjNmZjZBDSvzSzl +FnTJFcTTFccCrJGTLncdCCcPJZfBBDSlSJwZDlggSffvgSSf +FWTFGLFWLCPWrCnFnQWNbQVVwphhmHHbptVsss +BrrgrtgfBpPFhhgMWq +ZGvsvDGClvsSRScpGBhPphWMPhhTNh +S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pRLpbHDNzMMNcmmHNHQJQ +MMqDtnVnBlHtZvtB +WLWrWgdWwdrLCTFCwLlbbsJsJQsbQlQzlvrB +jFSvTdjfnfRmVcRR +ZLGqnvnqLzvbGRMfcRpwMpdV +fgfNNfgHHjVmRcVdgM +HsWDCDfCQCZBBZnvWtLq +bTZjqflqZhcrlczGzppGNgjmFNnp +PmmRSWWDMBQVNpWFznGF +SStRBDSCCSSSwPBwBDBwPmZhZlfZhqHTsTfltHHZfsHH +GbNbsSptQGqsdJCzsddcgzzv +DHRRnmWWmZnmRhllnHnnnMLvvLgcTVvjVhCTvgzcJgLj +RnWMlDZRlnHlmHWBFwGQqNGGPNQzPGqFwz +vSGvHpJnBLbGHBNCgfDzzChDgbCfzT +wFRslqmqTRgggQghPmQf +qjRFMjWqNNMMGHTL +fWGcQGGSRFQZhttZJfSSJflDDrwdClljVrNDdrdCFBCr +MTgvLLPPnHzMbDwdlNbMBwMM +mnTvnnPTcNmmJJWN +qqbbQQnbWrqGgnWqvZpVzMCZjCgfjZCSVM +ldcmDPDhmlFBHPDddLBVFDHLppZpjSCjjNfwNMwCpSMwhCMp +FtDdsHPcHmdHVPLtHsdtBHQnsbvnTRRTRsRRqbqvqWnJ +hhtBtPrgbbhhgjZjjCCHHNpNDHpffHWCvr +LGFLVwswsJMSgFwMMpddSvpHCCdDdvCpvm +sGsFsQLsVsLFnnFTJQthjcjQqhRcBZZtRg diff --git a/2022/03/puzzle-1.py b/2022/03/puzzle-1.py new file mode 100755 index 0000000..713e282 --- /dev/null +++ b/2022/03/puzzle-1.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 + +def cut(s: str) -> (str, str): + n = len(s) // 2 + return s[:n], s[n:] + + +def main() -> None: + with open("input", "r") as f: + data = f.readlines() + + acc = 0 + for line in data: + car, cdr = cut(line) + for c in car: + if cdr.find(c) != -1: + if "a" <= c <= "z": + acc += ord(c) - ord("a") + 1 + else: + acc += ord(c) - ord("A") + 27 + break + + print(acc) + + +if __name__ == "__main__": + main() diff --git a/2022/03/puzzle-2.py b/2022/03/puzzle-2.py new file mode 100755 index 0000000..7be3e84 --- /dev/null +++ b/2022/03/puzzle-2.py @@ -0,0 +1,31 @@ +#!/usr/bin/python3 + +from itertools import zip_longest + + +def grouper(xs: list[str], n: int) -> list[list[str]]: + args = [iter(xs)] * n + return zip_longest(*args) + + +def main() -> None: + with open("input", "r") as f: + data = f.readlines() + + acc = 0 + data = grouper(data, 3) + + for group in data: + for c in group[0]: + if group[1].find(c) != -1 and group[2].find(c) != -1: + if 'a' <= c <= 'z': + acc += ord(c) - ord('a') + 1 + else: + acc += ord(c) - ord('A') + 27 + break + + print(acc) + + +if __name__ == "__main__": + main() -- cgit v1.2.3