From 1570e6eb448749817e346eda717977315c894a8a Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Sun, 2 Dec 2018 10:57:21 -0500 Subject: [PATCH] AoC 2018 - Day 2 --- 2/checksum.py | 65 +++++++++++++ 2/checksum.py~ | 30 ++++++ 2/input | 250 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 345 insertions(+) create mode 100755 2/checksum.py create mode 100755 2/checksum.py~ create mode 100644 2/input diff --git a/2/checksum.py b/2/checksum.py new file mode 100755 index 0000000..6a1a588 --- /dev/null +++ b/2/checksum.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 + +import sys +def checksum(l): + double = 0 + triple = 0 + for item in l: + d, t = count_duplicate(item) + double += d + triple += t + return double * triple + +def count_duplicate(item): + double = 0 + triple = 0 + c = dict() + for i in item: + if i in c: + c[i] += 1 + else: + c[i] = 1 + for k,v in c.items(): + if v == 2: + double = 1 + if v == 3: + triple = 1 + #print(c) + #print("{}: {}, {}".format(item, double, triple)) + return (double, triple) + +def compare(item, l): + for candidate in l: + if candidate == item: + continue + diff = 0 + x = 0 + while x < len(item): + if item[x] != candidate[x]: + diff += 1 + x += 1 + if diff > 1: + break + #if diff > 1: + # print("{} does not match {}: {} different".format(item, candidate, diff)) + if diff == 1: + return candidate + +def common(x, y): + i = 0 + common = "" + while i < len(x): + if x[i] == y[i]: + common += x[i] + i += 1 + return common + +if __name__ == '__main__': + l = sys.stdin.readlines() + print(checksum(l)) + for item in l: + z = compare(item, l) + if z is not None: + print("{} / {}".format(item, z)) + print(common(item, z)) + break diff --git a/2/checksum.py~ b/2/checksum.py~ new file mode 100755 index 0000000..cd9a4cc --- /dev/null +++ b/2/checksum.py~ @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +def checksum(l): + double = 0 + triple = 0 + for item in l: + d, t = count_duplicate(item) + double += d + triple += t + return double * triple + +def count_duplicate(item): + double = 0 + triple = 0 + c = dict() + for i in item: + if i in c: + c[i] += 1 + else: + c[i] = 1 + for k,v in c.items(): + if v == 2: + double =11 + if v == 3: + triple = 1 + return (double, triple) + +if __name__ == '__main__': + l = sys.stdin.readlines() + print(checksum(l)) diff --git a/2/input b/2/input new file mode 100644 index 0000000..5785f74 --- /dev/null +++ b/2/input @@ -0,0 +1,250 @@ +qywzphxoiseldjrbaoagvkmanu +qywzphxeisulpjrbtfcgvkmanu +qywzxhooiseldjrbtfcgvcmanu +qywzphjojseldjubtfcgvkmanu +qtwzphxoieeldjrbtfcgvrmanu +tywzphzoiseldjritfcgvkmanu +qyuzphxoiseldjrbtfcgykbanu +qswzmhxoiseldjrbtfcgvkaanu +qyczqhxoiseldjrbtfcgvkbanu +qybzpqxooseldjrbtfcgvkmanu +qywzpoxoxseldjrbtfcgvpmanu +qywzphxbipeldjrbtfcgvkmaru +qywzpmxoiseldjrutqcgvkmanu +qywzphxoisesdjrrtfchvkmanu +qywzphxoiseldhrbtfcgukyanu +jywzphyoiseldjrbtfclvkmanu +qywzvhxoiselrjrbtfcgvkmanl +qywzplxojseldjrbtfcgvkmamu +qywzphxoiseldjrbtacgvkmvnd +qywpphxoiseldjrbtfcgvkvenu +qqazphxoiselqjrbtfcgvkmanu +qyozvhxoiseldjrbtfcgvkmadu +xywzphxliseldjhbtfcgvkmanu +qdwzphioiseldqrbtfcgvkmanu +qswyphxoiseldjrbtfcgvkmanx +qowzshxoiseldjrbtfigvkmanu +qywzphxoiseldjjbtfcgvkmawq +qyhzphxoiseldjrbtfvgvkmynu +qxwzphxoiselmjrbtfcgvqmanu +qywzphxoiceldjrbtfcgikmgnu +qywephxoiseldjrbthcgvkmane +yywzphxoisejdjrotfcgvkmanu +qywzxhxoisyldyrbtfcgvkmanu +qywzpjxoiseqdjrbtfcgvwmanu +qywzphxoqweldprbtfcgvkmanu +qywzphnoiseldjrbtfcamkmanu +qylgphxoiseldjrbtfcgvkmauu +qysdphxomseldjrbtfcgvkmanu +lywzpoxoikeldjrbtfcgvkmanu +qywzphxgiseldjrbtfeqvkmanu +qywzdhxozseldjcbtfcgvkmanu +qywzphxeiskedjrbtfcgvkmanu +qmwzphxoispldjrbtfcgvkmany +qywzphxoiselzcrbtfcgvkmanz +qywzphxoisxodjrbtscgvkmanu +qywzphxoiseldjrrtfcgmkmaeu +aywzphxoiseldjrbtfmjvkmanu +qywzthxoiiewdjrbtfcgvkmanu +qywzpsxoisrzdjrbtfcgvkmanu +qywzphxoiseldjkbtqcgvkmank +tywzphxoisewdjkbtfcgvkmanu +qywkchxoiseldjrbtfcghkmanu +qywzphxoiseldjoftfrgvkmanu +qywzpixoisehdjrbtfcgvkmacu +qywzchooiseldarbtfcgvkmanu +qywyphtoaseldjrbtfcgvkmanu +qywyphxotsbldjrbtfcgvkmanu +qywzphxoiseldjrbhsggvkmanu +dywzphxoiseldjrktfegvkmanu +qywzphxoiseldjrmtfcgvkcenu +qywcphxjiseldjybtfcgvkmanu +qywzphxoiseldhrbsfogvkmanu +qmwzpheoiseldjrrtfcgvkmanu +qywzrhxoiselpjrbtfcgvemanu +qyezphpoiseldjrbtfcgvdmanu +qywzphxvisewdjrbtfcgvkmdnu +qywzphkoiseldjrbtfcgvkmdnh +qywzehxoiseldfrbtpcgvkmanu +qywzphxoiseldjrrtfcgvrdanu +qpwzphxoizeldjqbtfcgvkmanu +qywzphxojseldjrbtmcgvkmvnu +vywzphxoiseldjrbtfcgvkmaop +sywzphxoiselbjrttfcgvkmanu +qywwphkoiseldjrbtfcivkmanu +qlwkpcxoiseldjrbtfcgvkmanu +qywzphxoiyesdjrbtfcgvkmvnu +qywzphxoiseldjrbofcgrkmrnu +qywzphxyiseldjrstfcgvkmjnu +qywzphaoiseldtrbnfcgvkmanu +qywzphxhisuldurbtfcgvkmanu +qywzphxdiseldjrbtvugvkmanu +qywzpzxbiseldjrbtfcgukmanu +qyrzphxoixeldjrbtfcgvumanu +qywzphxoiberdjrptfcgvkmanu +qywzphxfiskldjrbtfcgvkmdnu +qyxzphxoiseldjrdhfcgvkmanu +qywzphrqiseldjrbtfcgvbmanu +qyezphxviseldjrbtfcgvkmani +qywgphxoiseldgkbtfcgvkmanu +qywzphxoileldjrbtgcgvkdanu +qywzphxoiseldnrbtfcwvkmpnu +qywzphxoiseidjrbmfcqvkmanu +qywzpkxoiselijrbtfcgvlmanu +mywzphxoiveldjrbtfcgvkmunu +qywzphxooseddjrbtfcgpkmanu +qywzphxokseldjritfcyvkmanu +qywzxhxoiseldjrbtfqgvcmanu +qywzphxoisfldjrbpfcgvkmaju +qywuphxgiseldjrbffcgvkmanu +qywzphociseldjrbtfcgvkuanu +qywzphxoiseldvrbtftgckmanu +qywzpbxoisrldjrbtfngvkmanu +qywzphxoiseldjrntfygvdmanu +qywzphxviseldkrbtfcgvkianu +qywpphxgiseldjrbtfctvkmanu +qywzphxoicewdjrbtfcgvsmanu +qywzpcxoiseldjmbtfcgvcmanu +qrwzphxoiseldjrbtfcgjumanu +qywzphxoiselojrbtfcgxkmaau +qywzphxojsbldjrbtfcgykmanu +oywzphxoiseldjrbtfqgvkmvnu +qywfphxpiseldjrbtfckvkmanu +qyyzwhxwiseldjrbtfcgvkmanu +qywzphxgiseldjrbtfchvkmabu +qywzphxfiseldjrbtfcgukoanu +qywzpdxoisyldjrbtfcgvkxanu +dyuzphxoiseldjrbtfcgvkmamu +qywzphxoiseldjrbifcgvkmnnp +qywzpyxoiseldjrbtfcgvklano +dywzphxoiieldjrbtfcgvwmanu +qywzphxoihemdjrbtfcgvdmanu +gywzphxoxseldvrbtfcgvkmanu +qywzqhxoissldjwbtfcgvkmanu +eywzphxoiieldjrbtfcgekmanu +qyizprxciseldjrbtfcgvkmanu +qywjphxoiseldjrbtfcgckmano +qywznhxoiseldjrbrfcgvkmagu +qywzphxoisrldjdbvfcgvkmanu +qyyxphxoiseldjrbtwcgvkmanu +qywzphxoiseldjdbtfcpvkmjnu +qywzvhxqiseldjrbofcgvkmanu +vywzphxoiseldjrbtfcgckwanu +qywzphgbiseldjrbtfcgvkmazu +qcwzphxoiseldjrbqfcgvkmdnu +qywzphxoismldjrbtfcgkkmznu +qywhphxoiseldjrbtccgvkmane +qywzphzoiseldjrbtfcgvqmauu +hywzphxoiseldjrbtfcuvkmanc +qywzphxozsejdgrbtfcgvkmanu +qyszphxoiseldjrntfygvdmanu +qywzphxoisgldjrbtfcgvklaru +qywzhhxoiseldjrbtscgvkmqnu +qywjphxpiqeldjrbtfcgvkmanu +qywzphxoiseldxrptfclvkmanu +qywlphxoisehdjrbtfcgvkmanc +qydzpfxoiseldjrwtfcgvkmanu +qywzphxoiseldjrbtxcgqkfanu +qywophxoiselfjrbtfcgvkmani +qywzyhxoiszldtrbtfcgvkmanu +qywzphxoxseldfrntfcgvkmanu +qywzphloiseldjqbtfcgvkmtnu +qywzpuxoiseldorbtfcgvkeanu +qywzphxoiueldjrwdfcgvkmanu +qgwzphxoiseldjmbtncgvkmanu +qywzphtggseldjrbtfcgvkmanu +qywzphxoisrldjrbtfmgvhmanu +qfszphxoiseldjqbtfcgvkmanu +qywzphxpisjldjrbxfcgvkmanu +qywznhxoisepdjrbtfqgvkmanu +qywzphioiseldjabtfcgxkmanu +qyizphxaiseldjrbtfcgvkmaxu +xywzphxoiqelvjrbtfcgvkmanu +quwzphxoiseldjretfcgvkmaau +bywzphxoiseldjrbtucgckmanu +jywzphxoiseldjrbofcgvkmani +qywzphxoiseltjkbtfcgvkmabu +eywzphxoiselgjrbtfkgvkmanu +qywzphxoisengjrttfcgvkmanu +qywzphzoiseldjrbtfcgvkmknk +quwdphxoiseldjrbtfcxvkmanu +qcwzzhxoiseldjrgtfcgvkmanu +qywgphxdiseldjrbtfcgjkmanu +qywzpdxoivefdjrbtfcgvkmanu +qywzphxoiseldjrbtfdgvjmpnu +qfwzphxoiseydkrbtfcgvkmanu +qywzphxdiqelqjrbtfcgvkmanu +qywzvhxoiseldjrbtfognkmanu +qywzphgoiseldjrbcfcgvtmanu +qywophxoiseldjrbtpcgvkmank +qywzphxoiszldjretfcgvkmabu +qywzphxoiseldjhbtfcgvxmawu +qcgzphxoiselejrbtfcgvkmanu +qywzphxoisepdjrbtfcfvkcanu +qivzphxniseldjrbtfcgvkmanu +qywzhhxoiseldjrftxcgvkmanu +qyazphxciseldjrbtfcgskmanu +qywzphxoisoldgrbtfczvkmanu +qywzmhxoiseldurbwfcgvkmanu +qywzphxoistldjrbwfcgvkranu +qywzphxoistedjrbtfcgokmanu +qywzqhxodsecdjrbtfcgvkmanu +qywzphxtisxldjrbtfcgvkhanu +qywzphxoeseldjrtrfcgvkmanu +qdwzphxoioeldjrbtfigvkmanu +qjwzphxoisbldjrbtfcgvkmanz +qywzphxoiseldbrbtfdgvlmanu +qywzphxoiselddrbhvcgvkmanu +zywzppxoiseldjrdtfcgvkmanu +qywzppxqiselkjrbtfcgvkmanu +qywzphxoihelbjrbtfcgvkmabu +qywzphxoiseldjreyfcgvknanu +qywzphxxrseldjrbtfcgvkmagu +qywhpfxoiseldjrbtfdgvkmanu +qywzphxoisxldjrdtfagvkmanu +oywzphxxiseldjrbtfcgvkmaeu +qywzphxoiselqirbtfvgvkmanu +qywzphxoqseldhrbtfcgvkhanu +qywzphxokseldjrbtfxgvkmaju +qywzphtoiseldurbtfcfvkmanu +qywzphxoiheudjrrtfcgvkmanu +qrwzphxzigeldjrbtfcgvkmanu +qywzphxoiseldorbtfcgvxmvnu +qywzphxoisaldjpbqfcgvkmanu +qywuphxoiselljrbtfchvkmanu +qywzphxoisaldjrbefcgvkmsnu +qywzphxoiteldjrbnfcgvkmanp +qywhphxoiselqjrbtfcgvkmagu +qywzjhxoisejdjrbtfcgvkmanr +qywephaoiseldjrbtfcavkmanu +qywcphxoireldjqbtfcgvkmanu +qywzphxoiseldirbuicgvkmanu +qywzphxoisecvnrbtfcgvkmanu +qcwzphxoiseldjrbtfcgvrmaiu +qywnphxoiseldjrntftgvkmanu +qywzphxhisyldjrbtfcgvkmafu +qyhzphxoiseldjrytfcgvkmanq +vjwzbhxoiseldjrbtfcgvkmanu +qyvzpsxoisuldjrbtfcgvkmanu +qywzphxaiseldcrbefcgvkmanu +qywzphxoiseldjgbtfsgvkfanu +oiwzphxoiseldjrbtfcgvkmcnu +qyezphxoiseldjrbtfcqvkmjnu +tywzphxriseldzrbtfcgvkmanu +yywzphxoiseldjbbtfugvkmanu +qywzpfxviseldjrbttcgvkmanu +qywzphxoiceldcrbtfugvkmanu +qymzphxoiseldjratfcsvkmanu +qywzphxoiselxjrbdfcgvkpanu +qywzphxoiselujrbtfkgvimanu +qywzshyoiseldjrbtfcgpkmanu +qywzphxoiselfjrbtfsgvkmant +qywpphxoiseldjxbtfcyvkmanu +qywzfhxoiselqjrptfcgvkmanu +qewzphxoiseldprbtfcgvkmand +qywfphxoiseldlrbtfcgvkmgnu +qywzphxoiseldjhbtqcovkmanu +fywzphxoiseldlrbtfcgvkjanu +sywzphxoiseldjrbhfccvkmanu +qywzphxoiseldjfbtfcrvkmpnu +sywzphxoisrldjrbtfczvkmanu