summaryrefslogtreecommitdiffstats
path: root/prog/aoc/23/7/1.py
blob: e1d66da0b9c74de0aea652affeb0e8d640795997 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python3
from functools import cmp_to_key
hands = []
try:
	while True:
		hands.append(input().split(" "))
except EOFError:
	pass
alphabet = ["A", "K", "Q", "J", "T", "9", "8", "7", "6", "5", "4", "3", "2"];
def level(a):
	if len(set(a)) == 1:
		return 6
	if len(set(a)) == 2:
		if a.count(a[0]) == 1 or a.count(a[0]) == 4:
			return 5
		return 4
	if len(set(a)) == 3:
		if a.count(list(set(a))[0]) == 3 or a.count(list(set(a))[1]) == 3 or a.count(list(set(a))[2]) == 3:
			return 3
		return 2
	if len(set(a)) == 5:
		return 0
	return 1
def compar(a, b):
	a = a[0]
	b = b[0]
	if level(a) > level(b):
		return 1
	if level(b) > level(a):
		return -1
	for i in range(len(a)):
		if alphabet.index(a[i]) < alphabet.index(b[i]):
			return 1
		if alphabet.index(b[i]) < alphabet.index(a[i]):
			return -1
	return 0
hands.sort(key=cmp_to_key(compar))
i = 1
s = 0
for h in hands:
	print(h, level(h[0]))
	s += int(h[1])*i
	i += 1
print(s)
alphabet = ["A", "K", "Q", "T", "9", "8", "7", "6", "5", "4", "3", "2", "J"];
def level(a):
	r = set(a)-set(["J"])
	if len(r) == 0 or len(r) == 1:
		return 6
	if len(r) == 5:
		return 0
	if len(r) == 2:
		c2 = a.count("J")+a.count(list(r)[0])
		c1 = a.count("J")+a.count(list(r)[1])
		if c1 == 4 or c2 == 4:
			return 5
		return 4
	if len(r) == 3:
		l = a.count("J")
		if l+a.count(list(set(r))[0]) == 3 or l+a.count(list(set(r))[1]) == 3 or l+a.count(list(set(r))[2]) == 3:
			return 3
		return 2
	return 1
def compar(a, b):
	a = a[0]
	b = b[0]
	if level(a) > level(b):
		return 1
	if level(b) > level(a):
		return -1
	for i in range(len(a)):
		if alphabet.index(a[i]) < alphabet.index(b[i]):
			return 1
		if alphabet.index(b[i]) < alphabet.index(a[i]):
			return -1
	return 0
hands.sort(key=cmp_to_key(compar))
i = 1
s = 0
for h in hands:
	print(h, level(h[0]))
	s += int(h[1])*i
	i += 1
print(s)