diff --git a/2022/03/data.txt b/2022/03/data.txt new file mode 100644 index 0000000..d0ad78f --- /dev/null +++ b/2022/03/data.txt @@ -0,0 +1,300 @@ +PcPlnShmrLmBnmcwBhrmcmbHNGFGpwdFFwGNjNbGqNHH +tzQfRJfWZZztWzVtCTfRzFZjpFjNZjGLHbdHLDdjpb +CCQTzRLzvQVVfRzJfMPsnBlglgPmBgPmvSrl +RMfvbbszHTsssFPzDQPggpQJPQ +NSNcqVtLVGgDlpQBClVB +hmStGNNLhjNrpWLGSjWrZssbZTMMvTfMnThbRRTs +fTrTPGTbfftWBBmLjrJL +DqHwVMqVplDslmlZmpHVwNnShWZFdBBdjWBtWtdtWJSSLS +MNslpDvVHlwsmpQRgQgCfTTcvcRQ +pBBhRgDsMsswprBhvgRglZtFGFFRqZtZmRtNqtZPPN +TdmmzzmdZdqdGFtF +nmSccCVmSCpDCswMwl +NptqDsQtDTQzCvlzCpRlRp +jmZcndmjbZcjrmDvFMFFlwCvzFnF +jjgLVLrGcdDBNhWQTgHg +mLVhhfSMSTmMwClHGdpjDHjGdV +zPrZgJCgbsnrPtZzsCsbpRDjBRHnjGDRldRHppcG +JJrbsFrZqrgWbbqbrgWzJPNTwhTNCmmvfWCShhhmwwfm +ftgfljvgfgBTNvtggFDDGLGRDnMDzcQzncGt +VdbpbVdZwdwrsVVLRrMrDLDBGnBGcM +wmpWwWsHWBCCCPPvjvmSqlfTTmSNgN +jSqmzmmSSDRjLMLDwqjNcMMLTTflffWCCsRsTHnHVrfHWTsr +tdbgZpgBPdgGZGGFTHVpCsCVfVsJpnWl +FnPQFvbvhFFFbvBwScjhzcqSLLSzSN +bWdgrWwwFWbgzFWzrmNbdPqttChMSRnmqSPSnqtMRM +lcPJLDDPPfpMBCRJBtQtMh +lGDGjTGLLDHPPGjlPTsswsbHNFsNrFNFsrzr +VmtHfVhBLHVtlhphjZMdnQQZZqZmQDdzQQ +CPFwPWrvWgrfNgFPCMqZzMDDbznFTqqzDQ +NNPsfffPCsBLj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WVLRZLBcsWSZBRWS +FGQlpnJCbqqGGRCjjnlCqGMtdNmmmvdNmmmzvhbrmgMz +TstvBTdgBhqTsdTcPlfCSrNMrNnrCNNSNNgp +HwLQwQDZzDjnDbmMhNSnmm +FZLVzLLQHRRzwWHjdPlJctlJtlsllhRs +fBtPsMDDswHvBmmVdBlSBRcGGnhVhg +LWJbrpFqpTLTTjqqNWlhnRGGSnhrcSdlRlsh +JWNbbpjJzTbNNNJNJMvmvfZHvzDsHDCsZw +LPGnPNLtwGhFFnJPfsqpVVszzpsP +TcWdvlrcWddggrDBDDdDMmWzRJqfVQZqmsfZsRQzZfZzQJ +TldWrMrDdlDCDdMTcwSLVCSShLNSwHjhGF +JGsWWWQsJmPwQWbBPmccbcbqFfMMpFDVCDFVFVCDqqfFwD +ZtLnlvLnNtvLndnCmfMVSmVCClfpVp +zTzZtjnZNLNmZvdtznntHHZJbBRGBRQWcJGbGsbsJRPQWT +MLmlMTPtQtMNlhbqbbqhflBB +rcrvjpSvScbRbBvbDBPG +ZZJzSHpzPrJzHFmMVMFmHCLNtV diff --git a/2022/03/demo.txt b/2022/03/demo.txt new file mode 100644 index 0000000..f17e726 --- /dev/null +++ b/2022/03/demo.txt @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw diff --git a/2022/03/part1.py b/2022/03/part1.py new file mode 100644 index 0000000..f0ebea8 --- /dev/null +++ b/2022/03/part1.py @@ -0,0 +1,55 @@ +def load(filename): + with open(filename) as f: + for l in f: + s = l.rstrip() + n = len(s) + offset = int(n/2) + c1 = s[0:offset] + c2 = s[offset:] + yield c1, c2 + + +def overlap(c1, c2): + return list(set(c1).intersection(set(c2)))[0] + +def priority(c): + n = ord(c) + + if ord("a") <= n <= ord("z"): + return n - ord("a") + 1 + if ord("A") <= n <= ord("Z"): + return n - ord("A") + 27 + + raise Exception() + +def calcsum(l): + l = [overlap(*x) for x in l] + t = sum([priority(*x) for x in l]) + return t + + +l = list(load("demo.txt")) +assert "".join(l[0]) == "vJrwpWtwJgWrhcsFMMfFFhFp" +assert l[0][0] == "vJrwpWtwJgWr" +assert l[0][1] == "hcsFMMfFFhFp" +assert overlap(*l[0]) == "p" + +assert l[1] == ("jqHRNqRjqzjGDLGL", "rsFMfFZSrLrFZsSL") +assert overlap(*l[1]) == "L" + +assert l[2] == ("PmmdzqPrV", "vPwwTWBwg") +assert overlap(*l[2]) == "P" + +assert overlap(*l[3]) == "v" +assert overlap(*l[4]) == "t" +assert overlap(*l[5]) == "s" + +assert priority("a") == 1 +assert priority("z") == 26 +assert priority("A") == 27 +assert priority("Z") == 52 + +assert calcsum(l) == 157 + +l = load("data.txt") +print("Sum is:", calcsum(l)) diff --git a/2022/03/part2.py b/2022/03/part2.py new file mode 100644 index 0000000..f02623f --- /dev/null +++ b/2022/03/part2.py @@ -0,0 +1,50 @@ +from itertools import islice + + +def _load(filename): + with open(filename) as f: + for l in f: + yield l.rstrip() + + +def load(filename): + f = list(_load(filename)) + for j in range(0, int(len(f) / 3)): + i = j*3 + yield f[i], f[i+1], f[i+2] + + +def overlap(c1, c2, c3): + return list(set(c1).intersection(set(c2)).intersection(set(c3)))[0] + +def priority(c): + n = ord(c) + + if ord("a") <= n <= ord("z"): + return n - ord("a") + 1 + if ord("A") <= n <= ord("Z"): + return n - ord("A") + 27 + + raise Exception() + +def calcsum(l): + l = [overlap(*x) for x in l] + t = sum([priority(*x) for x in l]) + return t + +assert priority("a") == 1 +assert priority("z") == 26 +assert priority("A") == 27 +assert priority("Z") == 52 + +l = list(load("demo.txt")) +assert l[0] == ("vJrwpWtwJgWrhcsFMMfFFhFp", "jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL", "PmmdzqPrVvPwwTWBwg") +assert l[1] == ("wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn", "ttgJtRGJQctTZtZT", "CrZsJsPPZsGzwwsLwLmpwMDw") + +assert overlap(*l[0]) == "r" +assert overlap(*l[1]) == "Z" + +assert calcsum(l) == 70 + +l = list(load("data.txt")) +print("Sum is:", calcsum(l))