Skip to content

Commit a338123

Browse files
committed
code golf
1 parent 31dcf4f commit a338123

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

input.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
1
2+
4
3+
5
4+
9
15
43
6+
50
7+
51
28
104
39
243
410
401
11+
510
12+
999
13+
1999
514
3277
15+
3999

main.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
3+
4+
def m():
5+
v = [[1], [9, 5, 4, 1], [9, 5, 4, 1], [9, 5, 4, 1]]
6+
s = [['M'], ['CM', 'D', 'CD', 'C'], ['XC', 'L', 'XL', 'X'], ['IX', 'V', 'IV', 'I']]
7+
# Open the file for reading
8+
with open(sys.argv[1], "r") as f:
9+
l = f.readline().strip()
10+
while l != "":
11+
r = ''
12+
for i, c in enumerate(l.zfill(4)):
13+
d = int(c)
14+
if d == 0:
15+
continue
16+
for j in v[i]:
17+
if d >= j:
18+
r += s[i][v[i].index(j)]
19+
d -= j
20+
print(l, r)
21+
l = f.readline().strip()
22+
23+
24+
if __name__ == "__main__":
25+
m()

0 commit comments

Comments
 (0)