Sha256: 36acabbea426bfd248016356fadc2343f70de6556a58b27e27cae2d158f700ee

Contents?: true

Size: 531 Bytes

Versions: 203

Compression:

Stored size: 531 Bytes

Contents

class Roman {
  def Roman() {
    Integer.metaClass.toRoman = {->
      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

203 entries across 203 versions & 1 rubygems

Version Path
trackler-2.1.0.48 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.47 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.46 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.45 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.44 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.43 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.42 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.41 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.40 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.39 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.38 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.37 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.36 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.34 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.33 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.32 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.31 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.30 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.29 tracks/groovy/exercises/roman-numerals/Example.groovy
trackler-2.1.0.28 tracks/groovy/exercises/roman-numerals/Example.groovy