Compare commits

..

No commits in common. "5d6ae754779b84340da8f4b679abbe2c556c5668" and "7c9ef891ae7c65aa04800af378efe00f7bab73ca" have entirely different histories.

4 changed files with 0 additions and 108 deletions

View File

@ -1,57 +0,0 @@
import sys
from pprint import pp
from collections import Counter
input_f = sys.argv[1]
cards = {}
with open(input_f) as file:
for line in file:
tmp = line.split()
cards[tmp[0]] = int(tmp[1])
def value(card,p2):
return 'AKQJT98765432'.index(card) if not p2 else 'AKQT98765432J'.index(card)
def score(card,p2):
tmp = sorted(list(Counter(card).values()),reverse=True)
if p2 and (j := card.count('J')) and j < 5:
tmp.remove(j)
tmp[0] += j
tmp = sorted(tmp,reverse=True)
if tmp == [5]:
return 1
elif tmp == [4,1]:
return 2
elif tmp == [3,2]:
return 3
elif tmp == [3,1,1]:
return 4
elif tmp == [2,2,1]:
return 5
elif tmp == [2,1,1,1]:
return 6
elif tmp == [1,1,1,1,1]:
return 7
else:
print('ERROR')
def play(cards,p2):
scores = []
tmp = []
for i in cards:
tmp.append(tuple((score(i,p2),tuple(value(c,p2) for c in i),i)))
return sorted(tmp, key=lambda x: (x[0], x[1]),reverse=True)
tmp = play(cards,False)
result = 0
for idx,i in enumerate(tmp):
result += cards[i[2]]*(idx+1)
print('Part 1: ' + str(result))
tmp = play(cards,True)
result = 0
for idx,i in enumerate(tmp):
result += cards[i[2]]*(idx+1)
print('Part 2: ' + str(result))

View File

@ -1,19 +0,0 @@
2345A 1
Q2KJJ 13
Q2Q2Q 19
T3T3J 17
T3Q33 11
2345J 3
J345A 2
32T3K 5
T55J5 29
KK677 7
KTJJT 34
QQQJA 31
JJJJJ 37
JAAAA 43
AAAAJ 59
AAAAA 61
2AAAA 23
2JJJJ 53
JJJJ2 41

View File

@ -1,23 +0,0 @@
J2566 131
K7KK7 272
AA222 222
222AA 123
44T55 467
4K339 546
42TT2 174
TQTTT 710
84766 682
K22KK 607
77595 922
26778 768
JJ667 198
JJ2JJ 123
44Q9A 821
T6682 851
3A232 890
5Q5J4 691
79789 305
KK666 138
TT9TT 742
Q4276 489
6T48J 921

View File

@ -1,9 +0,0 @@
2J345 213
22345 425
2JJ34 654
22234 234
2JJJ3 623
22223 658
J2JJJ 987
2JJJJ 456
22222 604