Skip to content

Commit 3c5d480

Browse files
committed
solved(python): programmers
- PCCP 기출문제 / 아날로그 시계
1 parent dee94a8 commit 3c5d480

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

programmers/PCCP_기출문제/python/아날로그_시계/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def solution(h1: int, m1: int, s1: int, h2: int, m2: int, s2: int) -> int:
2+
h, m, s = (h1 * 30 + m1 / 2 + s1 / 120) % 360, (m1 * 6 + s1 / 10) % 360, (s1 * 6) % 360
3+
4+
count = int(h == m or h == s or m == s)
5+
for idx in range((h2 - h1) * 3600 + (m2 - m1) * 60 + s2 - s1):
6+
nh, nm, ns = round(h + 1 / 120, 5), round(m + 1 / 10, 5), round(s + 6, 5)
7+
8+
if nh == ns or nm == ns:
9+
count += 1
10+
else:
11+
for condition in [
12+
not h == s and (h - s) * (nh - ns) <= 0,
13+
not m == s and (m - s) * (nm - ns) <= 0,
14+
]:
15+
count += int(condition)
16+
17+
h, m, s = nh % 360, nm % 360, ns % 360
18+
19+
return count
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
[
2+
{
3+
"params": [
4+
0,
5+
5,
6+
30,
7+
0,
8+
7,
9+
0
10+
],
11+
"expected": 2
12+
},
13+
{
14+
"params": [
15+
12,
16+
0,
17+
0,
18+
12,
19+
0,
20+
30
21+
],
22+
"expected": 1
23+
},
24+
{
25+
"params": [
26+
0,
27+
6,
28+
1,
29+
0,
30+
6,
31+
6
32+
],
33+
"expected": 0
34+
},
35+
{
36+
"params": [
37+
11,
38+
59,
39+
30,
40+
12,
41+
0,
42+
0
43+
],
44+
"expected": 1
45+
},
46+
{
47+
"params": [
48+
11,
49+
58,
50+
59,
51+
11,
52+
59,
53+
0
54+
],
55+
"expected": 1
56+
},
57+
{
58+
"params": [
59+
1,
60+
5,
61+
5,
62+
1,
63+
5,
64+
6
65+
],
66+
"expected": 2
67+
},
68+
{
69+
"params": [
70+
0,
71+
0,
72+
0,
73+
23,
74+
59,
75+
59
76+
],
77+
"expected": 2852
78+
}
79+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import json
2+
import os
3+
import unittest
4+
5+
from parameterized import parameterized
6+
7+
from .main import solution
8+
9+
10+
def load_sample(filename: str):
11+
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
12+
13+
with open(path, "r") as file:
14+
return [(case["params"], case["expected"]) for case in json.load(file)]
15+
16+
17+
class TestCase(unittest.TestCase):
18+
@parameterized.expand(load_sample("sample.json"))
19+
def test_case(self, params: list, expected: any):
20+
# When
21+
result = solution(*params)
22+
23+
# Then
24+
self.assertEqual(expected, result)
25+
26+
27+
if __name__ == "__main__":
28+
unittest.main()

0 commit comments

Comments
 (0)