about summary refs log tree commit diff stats
BranchCommit messageAuthorAge
mastercompletions: add support for completing multiple addressesParasrah3 years
 
TagDownloadAuthorAge
0.6.0aerc-0.6.0.tar.gz  Robin Jarry3 years
0.5.2aerc-0.5.2.tar.gz  Reto Brunner4 years
0.5.1aerc-0.5.1.tar.gz  Reto Brunner4 years
0.5.0aerc-0.5.0.tar.gz  Daniel Sockwell4 years
0.4.0aerc-0.4.0.tar.gz  Drew DeVault5 years
0.3.0aerc-0.3.0.tar.gz  Drew DeVault5 years
0.2.1aerc-0.2.1.tar.gz  Drew DeVault6 years
0.2.0aerc-0.2.0.tar.gz  Drew DeVault6 years
0.1.4aerc-0.1.4.tar.gz  Drew DeVault6 years
0.1.3aerc-0.1.3.tar.gz  Drew DeVault6 years
0.1.2aerc-0.1.2.tar.gz  Drew DeVault6 years
0.1.1aerc-0.1.1.tar.gz  Drew DeVault6 years
0.1.0aerc-0.1.0.tar.gz  Drew DeVault6 years
ld } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#
#
#            Nim's Runtime Library
#        (c) Copyright 2011 Philippe Lhoste
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## Module for converting an integer to a Roman numeral.
## See http://en.wikipedia.org/wiki/Roman_numerals for reference.
##
## **Warning:** This module will be moved out of the stdlib and into a
## Nimble package, don't use it.

const
  RomanNumeralDigits* = {'I', 'i', 'V', 'v', 'X', 'x', 'L', 'l', 'C', 'c',
    'D', 'd', 'M', 'm'} ## set of all characters a Roman numeral may consist of

proc romanToDecimal*(romanVal: string): int =
  ## Converts a Roman numeral to its int representation.
  result = 0
  var prevVal = 0
  for i in countdown(romanVal.len - 1, 0):
    var val = 0
    case romanVal[i]
    of 'I', 'i': val = 1
    of 'V', 'v': val = 5
    of 'X', 'x': val = 10
    of 'L', 'l': val = 50
    of 'C', 'c': val = 100
    of 'D', 'd': val = 500
    of 'M', 'm': val = 1000
    else:
      raise newException(EInvalidValue, "invalid roman numeral: " & $romanVal)
    if val >= prevVal:
      inc(result, val)
    else:
      dec(result, val)
    prevVal = val

proc decimalToRoman*(number: range[1..3_999]): string =
  ## Converts a number to a Roman numeral.
  const romanComposites = [
    ("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)]
  result = ""
  var decVal: int = number
  for key, val in items(romanComposites):
    while decVal >= val:
      dec(decVal, val)
      result.add(key)

when isMainModule:
  for i in 1 .. 3_999:
    assert i == i.decimalToRoman.romanToDecimal