# Help please: math or variable problem

**URL:** <https://www.ruby-forum.com/t/help-please-math-or-variable-problem/96093>\
**Category:** Ruby\
**Created:** [June 25, 2006, 9:56pm UTC](https://www.ruby-forum.com/t/help-please-math-or-variable-problem/96093 "2006-06-25T21:56:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 25, 2006, 9:56pm UTC](https://www.ruby-forum.com/t/help-please-math-or-variable-problem/96093/1 "2006-06-25T21:56:39Z")

</div>

Preface- I know there is an easier way , since I’ll be working into the  
thousands.  
Anyway, down below I’m taking a number between 10 and 49 and converting  
to a  
Roman Numeral. I’ve been experimenting with 46, which should return  
XXXXVI  
only it’s returning XXXXVIIIII

For some reason this line rnm = (rnm-vrnm) is not calculating or not  
calculating correctly, though I am doing the raw numbers in IRB and that  
works fine.

Also , as a side note, SCITE is highlight (in a brownish color) from the  
x  
in rnm = (num%x) to the rnm = (rnm-vrnm). Kind of weird, unsure what it  
is.  
by the way, a) I maybe asking too many questions for one day b) I know  
there  
is a simpler way to do this , but hopefully my brain will slowly adapt.

if num \>= 10 && num \<= 49

x = 10  
v = 5  
rn = (num/x)  
rnm = (num%x)  
vrnm = rnm/v

rn.times do  
print “X”

```
end
    vrnm.times do
      print "V"

      end

```

rnm = (rnm-vrnm)  
rnm.times do  
print “I”  
end

```
    end
```

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 25, 2006, 10:06pm UTC](https://www.ruby-forum.com/t/help-please-math-or-variable-problem/96093/2 "2006-06-25T22:06:15Z")

</div>

On 6/25/06, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Anyway, down below I’m taking a number between 10 and 49 and converting to a  
> Roman Numeral. I’ve been experimenting with 46, which should return XXXXVI  
> only it’s returning XXXXVIIIII

No. It should return XLVI [10 to 50, 5, 1].

X, XX, XXX, XL, L, LX, LXX, LXXX, XC etc…

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 25, 2006, 10:12pm UTC](https://www.ruby-forum.com/t/help-please-math-or-variable-problem/96093/3 "2006-06-25T22:12:24Z")

</div>

Ah ha! Well back to the drawing board. 🙂

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 25, 2006, 10:27pm UTC](https://www.ruby-forum.com/t/help-please-math-or-variable-problem/96093/4 "2006-06-25T22:27:44Z")

</div>

Take a lock at Ruby Q. #22 for a bunch of solutions to this problem.  
Why solve something that’s already been done a hundred times? =)

[http://www.rubyquiz.com/quiz22.html](http://www.rubyquiz.com/quiz22.html)

Regards  
Ola B.  
[http://ola-bini.blogspot.com](http://ola-bini.blogspot.com)

----- Original Message -----  
From: Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Sunday, June 25, 2006 10:11 pm  
Subject: Re: help please: math or variable problem  
To: removed\_email\_address@domain.invalid (ruby-talk ML)

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 25, 2006, 10:40pm UTC](https://www.ruby-forum.com/t/help-please-math-or-variable-problem/96093/5 "2006-06-25T22:40:02Z")

</div>

I agree and even found this:  
[http://twt.mpei.ac.ru/MAS/Worksheets/Rim\_Arab\_Number.mcd](http://twt.mpei.ac.ru/MAS/Worksheets/Rim_Arab_Number.mcd)  
which is a arabic → roman numeral calculator.

However I’m learning to program, and in Ruby and this is an assignment  
from  
the book. So, yes, ultimately the only value is in helping me to think  
these types of problems through. I’m afraid to look at rubyquiz as it  
might  
be cheating. I’d like to see first how creative I can get before  
comparing. Regardless thank you for making me aware of it.

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 26, 2006, 9:37am UTC](https://www.ruby-forum.com/t/help-please-math-or-variable-problem/96093/6 "2006-06-26T09:37:58Z")

</div>

Dark A. wrote:

> v = 5
> 
> ```
> end
> 
> ```
> 
> rnm = (rnm-vrnm)  
> Surely this line should be:

rnm = rnm - (v \* vrnm)

?

I mean, besides the XXXX =\> XL problem…
