First, sorry about the formatting issues. Use `~~~`

on the line above and below the code snippet that you want to be formatted.

Second, I hope you are writing your own solutions rather than just focusing on mine! No amount of reading code can make up for a lack of writing code. :-)

So, to answer your question:

```
roman = ''
roman = roman + 'M' * (self / 1000)
roman = roman + 'D' * (self % 1000 / 500)
roman = roman + 'C' * (self % 500 / 100)
roman = roman + 'L' * (self % 100 / 50)
roman = roman + 'X' * (self % 50 / 10)
roman = roman + 'V' * (self % 10 / 5)
roman = roman + 'I' * (self % 5 / 1)
roman
```

The entire method is building up a single string, stored in `roman`

. So it first starts as an empty string. Then, on each line, we reset roman to point to the string containing all of the stuff we’ve built so far, *plus* whatever new letters we need (which we’ll talk more about in a bit). Finally, we return the string `roman`

.

With me so far? I just want to make sure you get the large-scale feel of what this method does before delving into the specifics.

OK. For each of the middle lines, we add all of the appropriate letter. You can see that the first line is for adding all of the `'M'`

s, the second line then adds all of the `'D'`

s, and so on. (When I say “all of the `'M'`

s”, that might be none if there are no `'M'`

s in this number.) We do this by multiplying the string of the letter we are considering on that line by the number of times we should include it.

So far so good?

All that’s left is to understand why the expressions in parentheses give us the numbers that we want. Remember that `/`

is integer division (since these are all integers), which means that we throw away the remainder. And `%`

is the modulus operator, which is like division except that it throws away the answer and gives us *only* the remainder.

Let’s work through a few examples. Let’s first try `3`

:

`3 / 1000`

-> `0`

, so no M’s.
`3 % 1000 / 500`

-> `3 / 500`

-> `0`

, so no D’s.
`3 % 500 / 100`

-> `3 / 100`

-> `0`

, so no C’s.
`3 % 100 / 50`

-> `3 / 50`

-> `0`

, so no L’s.
`3 % 50 / 10`

-> `3 / 10`

-> `0`

, so no X’s.
`3 % 10 / 5`

-> `3 / 5`

-> `0`

, so no V’s.
`3 % 5 / 1`

-> `3 / 1`

-> `3`

, so we finally get three I’s!

So you see how the small value of 3 passed all the way down to the bottom line. Let’s try again, with `2000`

:

`2000 / 1000`

-> `2`

, so we start with two M’s.
`2000 % 1000 / 500`

-> `0 / 500`

-> `0`

, so no D’s.
`2000 % 500 / 100`

-> `0 / 100`

-> `0`

, so no C’s.
`2000 % 100 / 50`

-> `0 / 50`

-> `0`

, so no L’s.
`2000 % 50 / 10`

-> `0 / 10`

-> `0`

, so no X’s.
`2000 % 10 / 5`

-> `0 / 5`

-> `0`

, so no V’s.
`2000 % 5 / 1`

-> `0 / 1`

-> `0`

, so no I’s.

So the M’s were pulled off right at the beginning. Finally, let’s look at `2014`

:

`2014 / 1000`

-> `2`

, so we start with two M’s.
`2014 % 1000 / 500`

-> `14 / 500`

-> `0`

, so no D’s.
`2014 % 500 / 100`

-> `14 / 100`

-> `0`

, so no C’s.
`2014 % 100 / 50`

-> `14 / 50`

-> `0`

, so no L’s.
`2014 % 50 / 10`

-> `14 / 10`

-> `1`

, so one X.
`2014 % 10 / 5`

-> `4 / 5`

-> `0`

, so no V’s.
`2014 % 5 / 1`

-> `4 / 1`

-> `4`

, so four I’s.

*Whew!* Hope that made sense. :-)

Chris