AoC 2018 - Day 2
This commit is contained in:
parent
5d24f6d3e5
commit
1570e6eb44
|
@ -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
|
|
@ -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))
|
|
@ -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
|
Loading…
Reference in New Issue