1
+ # 2024 KAKAO WINTER INTERNSHIP
2
+ # https://school.programmers.co.kr/learn/courses/30/lessons/258707
3
+
4
+
5
+ def solution (coin , cards ):
6
+ n = len (cards )
7
+ target = n + 1
8
+ hands = set ([cards .pop (0 ) for _ in range (n // 3 )])
9
+ coin_cards = set ()
10
+ max_round = 1
11
+
12
+ while len (cards ) > 0 :
13
+ coin_cards .add (cards .pop (0 ))
14
+ coin_cards .add (cards .pop (0 ))
15
+
16
+ max_round += 1
17
+ is_play = False
18
+ # coin 0
19
+ for i in list (hands ):
20
+ other = target - i
21
+
22
+ if i != other and other in hands :
23
+ is_play = True
24
+ hands .remove (i )
25
+ hands .remove (other )
26
+ break
27
+
28
+ if is_play is True :
29
+ continue
30
+
31
+ # coin 1
32
+ if coin > 0 :
33
+ for i in list (hands ):
34
+ other = target - i
35
+
36
+ if i != other and other in coin_cards :
37
+ is_play = True
38
+ hands .remove (i )
39
+ coin_cards .remove (other )
40
+ coin -= 1
41
+ break
42
+
43
+ if is_play is True :
44
+ continue
45
+
46
+ # coin 2
47
+ if coin > 1 :
48
+ for i in list (coin_cards ):
49
+ other = target - i
50
+
51
+ if i != other and other in coin_cards :
52
+ is_play = True
53
+ coin_cards .remove (i )
54
+ coin_cards .remove (other )
55
+ coin -= 2
56
+ break
57
+
58
+ if is_play is True :
59
+ continue
60
+
61
+ max_round -= 1
62
+ break
63
+
64
+ return max_round
65
+
66
+
67
+ coin = [4 , 3 , 2 , 10 ]
68
+ cards = [
69
+ [3 , 6 , 7 , 2 , 1 , 10 , 5 , 9 , 8 , 12 , 11 , 4 ],
70
+ [1 , 2 , 3 , 4 , 5 , 8 , 6 , 7 , 9 , 10 , 11 , 12 ],
71
+ [5 , 8 , 1 , 2 , 9 , 4 , 12 , 11 , 3 , 10 , 6 , 7 ],
72
+ [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 ]
73
+ ]
74
+ result = [5 ,2 ,4 ,1 ]
75
+
76
+
77
+ for q in [0 ,1 ,2 ,3 ]:
78
+ qid = solution (coin [q ], cards [q ])
79
+ if qid == result [q ]:
80
+ print (f'correct { qid } ' )
81
+ else :
82
+ print (f'incorrect { qid } ' )
0 commit comments