Sha256: 484c1ec04030261f4eedf2b8d19c5954152bdd87e6788bcbf9c1cebaf8ef0691

Contents?: true

Size: 539 Bytes

Versions: 168

Compression:

Stored size: 539 Bytes

Contents

class RomanNumerals {
  def RomanNumerals() {
    Integer.metaClass.getRoman = {->
      def romanMappings = [
        1000:"M",
        900:"CM",
        500:"D",
        400:"CD",
        100:"C",
        90:"XC",
        50:"L",
        40:"XL",
        10:"X",
        9:"IX",
        5:"V",
        4:"IV",
        1:"I"
      ]

      def roman = new String()
      def num = delegate

      romanMappings.each() { k, v ->
        while (num >= k) {
          roman += v
          num -= k
        }
      }

      roman
    }
  }
}

Version data entries

168 entries across 168 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.158 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.157 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.156 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.155 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.154 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.153 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.152 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.151 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.150 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.149 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.148 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.147 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.146 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.145 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.144 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.143 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.142 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.141 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.140 tracks/groovy/exercises/roman-numerals/Example.groovy