Skip to content

Commit

Permalink
python/roman-numerals: 1st iteration - py3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 13, 2024
1 parent cad08c4 commit 77258f7
Show file tree
Hide file tree
Showing 15 changed files with 649 additions and 3 deletions.
1 change: 1 addition & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
- [plane-tickets](./plane-tickets/README.md)
- [raindrops](./raindrops/README.md)
- [reverse-string](./reverse-string/README.md)
- [roman-numerals](./roman-numerals/README.md)
1 change: 1 addition & 0 deletions python/roman-numerals/.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!coverage.py: This is a private format, don't read it directly!{"arcs":{"/home/vpayno/git_vpayno/exercism-workspace/python/roman-numerals/test/__init__.py":[[0,0],[0,-1]],"/home/vpayno/git_vpayno/exercism-workspace/python/roman-numerals/roman_numerals.py":[[0,1],[1,3],[3,5],[5,6],[6,7],[7,10],[10,-1],[10,11],[11,13],[13,14],[14,15],[15,16],[16,17],[17,18],[18,19],[19,20],[20,21],[21,22],[22,23],[23,24],[24,25],[25,26],[26,28],[28,29],[29,30],[30,31],[31,29],[29,28],[28,33],[33,-10]]}}
53 changes: 53 additions & 0 deletions python/roman-numerals/.coverage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" ?>
<coverage branch-rate="1" branches-covered="4" branches-valid="4" complexity="0" line-rate="0.9615" lines-covered="25" lines-valid="26" timestamp="1713022927789" version="4.5.4">
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/home/vpayno/git_vpayno/exercism-workspace/python/roman-numerals</source>
</sources>
<packages>
<package branch-rate="1" complexity="0" line-rate="0.9615" name=".">
<classes>
<class branch-rate="1" complexity="0" filename="roman_numerals.py" line-rate="0.9615" name="roman_numerals.py">
<methods/>
<lines>
<line hits="0" number="0"/>
<line hits="1" number="3"/>
<line hits="1" number="5"/>
<line hits="1" number="6"/>
<line hits="1" number="7"/>
<line hits="1" number="10"/>
<line hits="1" number="11"/>
<line hits="1" number="13"/>
<line hits="1" number="14"/>
<line hits="1" number="15"/>
<line hits="1" number="16"/>
<line hits="1" number="17"/>
<line hits="1" number="18"/>
<line hits="1" number="19"/>
<line hits="1" number="20"/>
<line hits="1" number="21"/>
<line hits="1" number="22"/>
<line hits="1" number="23"/>
<line hits="1" number="24"/>
<line hits="1" number="25"/>
<line hits="1" number="26"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="28"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="29"/>
<line hits="1" number="30"/>
<line hits="1" number="31"/>
<line hits="1" number="33"/>
</lines>
</class>
</classes>
</package>
<package branch-rate="1" complexity="0" line-rate="1" name="test">
<classes>
<class branch-rate="1" complexity="0" filename="test/__init__.py" line-rate="1" name="__init__.py">
<methods/>
<lines/>
</class>
</classes>
</package>
</packages>
</coverage>
2 changes: 2 additions & 0 deletions python/roman-numerals/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = __init__.py, *_test.py
1 change: 1 addition & 0 deletions python/roman-numerals/.pylintrc
7 changes: 6 additions & 1 deletion python/roman-numerals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ Make sure to check out our Deep Dive video at the end to explore the different a

### Based on

The Roman Numeral Kata - https://codingdojo.org/kata/RomanNumerals/
The Roman Numeral Kata - https://codingdojo.org/kata/RomanNumerals/

### My Solution

- [my solution](./roman_numerals.py)
- [run-tests](./run-tests-python.txt)
5 changes: 5 additions & 0 deletions python/roman-numerals/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
pythonpath = .
addopts = --doctest-modules
markers =
task: exercise task/step
34 changes: 32 additions & 2 deletions python/roman-numerals/roman_numerals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
def roman(number):
pass
"""Python Roman Numerals Exercism"""

from collections import OrderedDict

type modern_numeral_t = int # type: ignore[valid-type]
type roman_numeral_t = str # type: ignore[valid-type]
type map_d2r_t = OrderedDict[modern_numeral_t, roman_numeral_t] # type: ignore[valid-type]


def roman(number: modern_numeral_t) -> roman_numeral_t:
rn: roman_numeral_t = ""

d2r: map_d2r_t = OrderedDict()
d2r[1] = "I"
d2r[4] = "IV"
d2r[5] = "V"
d2r[9] = "IX"
d2r[10] = "X"
d2r[40] = "XL"
d2r[50] = "L"
d2r[90] = "XC"
d2r[100] = "C"
d2r[400] = "CD"
d2r[500] = "D"
d2r[900] = "CM"
d2r[1000] = "M"

for d, r in reversed(d2r.items()):
while number >= d:
rn = f"{rn}{r}"
number -= d

return rn
33 changes: 33 additions & 0 deletions python/roman-numerals/roman_numerals.py,cover
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
> """Python Roman Numerals Exercism"""

> from collections import OrderedDict

> type modern_numeral_t = int # type: ignore[valid-type]
> type roman_numeral_t = str # type: ignore[valid-type]
> type map_d2r_t = OrderedDict[modern_numeral_t, roman_numeral_t] # type: ignore[valid-type]


> def roman(number: modern_numeral_t) -> roman_numeral_t:
> rn: roman_numeral_t = ""

> d2r: map_d2r_t = OrderedDict()
> d2r[1] = "I"
> d2r[4] = "IV"
> d2r[5] = "V"
> d2r[9] = "IX"
> d2r[10] = "X"
> d2r[40] = "XL"
> d2r[50] = "L"
> d2r[90] = "XC"
> d2r[100] = "C"
> d2r[400] = "CD"
> d2r[500] = "D"
> d2r[900] = "CM"
> d2r[1000] = "M"

> for d, r in reversed(d2r.items()):
> while number >= d:
> rn = f"{rn}{r}"
> number -= d

> return rn
Loading

0 comments on commit 77258f7

Please sign in to comment.