Skip to content

Commit

Permalink
exemplo de closure read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
ramalho committed Dec 17, 2011
1 parent 00541c2 commit cd29bdc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions funcional/roman_closure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

def to_roman():

romanNumeralMap = (
('M', 1000), ('CM', 900), ('D', 500), ('CD', 400), ('C', 100), ('XC', 90),
('L', 50), ('XL', 40), ('X', 10), ('IX', 9), ('V', 5), ('IV', 4), ('I', 1))

def _to_roman(n):
result = ''
for numeral, integer in romanNumeralMap:
while n >= integer:
result += numeral
n -= integer
return result
return _to_roman

to_roman = to_roman()
for i in range(1, 21):
print to_roman(i)

0 comments on commit cd29bdc

Please sign in to comment.