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.180 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.179 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.178 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.177 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.176 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.175 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.174 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.173 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.172 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.171 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.170 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.169 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.167 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.166 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.165 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.164 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.163 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.162 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.161 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.2.1.160 tracks/groovy/exercises/roman-numerals/Example.groovy