wu :: forums
« wu :: forums - roman numerals flow diag »

Welcome, Guest. Please Login or Register.
May 18th, 2024, 7:37am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   medium
(Moderators: Grimbal, Eigenray, SMQ, ThudnBlunder, william wu, Icarus, towr)
   roman numerals flow diag
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: roman numerals flow diag  (Read 2492 times)
Noke Lieu
Uberpuzzler
*****



pen... paper... let's go! (and bit of plastic)

   
WWW

Gender: male
Posts: 1884
roman numerals flow diag  
« on: Jan 28th, 2009, 6:24pm »
Quote Quote Modify Modify

(perhaps it should live over in CS- but I don't go there much...)
 
Using the standard accepted notation of Roman numerals (IV, not IIIII etc) and MMMCMXCIX (3999) being the biggest number that can be written.
 
Construct a flow diagram that allows transliteration from Roman numerals to Hindu-Arabic.
 
(I did to try and find out why people struggled with Roman Numerals. It blows out  and gets messy quite quickly)
IP Logged

a shade of wit and the art of farce.
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: roman numerals flow diag  
« Reply #1 on: Jan 29th, 2009, 12:49am »
Quote Quote Modify Modify

If you don't need a validation, I'd propose the following:
 
static String[] rom[] = { "CM", "M", "CD", "D",  "XC", "C", "XL", "L", "IX", "X", "IV", "V", "I" };
static String[] val[] = { 900, 1000, 400, 500,  90, 100, 40, 50, 9, 10, 4, 5, 1 };
public String roman2int(String roman){
 int value = 0;
 for( int r=0 ; r<rom.length ; r++ ){
  while( roman.startsWith(rom[r]) ){
    value += val[r];
    roman = roman.substring(rom[r].length());
  }
 }
 return "" + value;
}
 
Never compiled, let alone tested!
« Last Edit: Jan 29th, 2009, 12:49am by Grimbal » IP Logged
Noke Lieu
Uberpuzzler
*****



pen... paper... let's go! (and bit of plastic)

   
WWW

Gender: male
Posts: 1884
Re: roman numerals flow diag  
« Reply #2 on: Jan 29th, 2009, 4:01pm »
Quote Quote Modify Modify

possessing perhaps 1/16 ounce of programming ability, that looks like it'd work. Nicely done.
 
However, I was after something a bit more... human. Boxes with one instruction and arrows for "yes" and "no" sort of stuff- if you wanted to slum it...
IP Logged

a shade of wit and the art of farce.
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: roman numerals flow diag  
« Reply #3 on: Jan 30th, 2009, 12:21am »
Quote Quote Modify Modify

Start at the back with a total of zero; take the value of the current numeral (I=1, V=5, X=10, L=50, C=100, D=500, M=1000); if it is smaller than the last numeral subtract it from the total, otherwise add it; move to the next numeral.
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Noke Lieu
Uberpuzzler
*****



pen... paper... let's go! (and bit of plastic)

   
WWW

Gender: male
Posts: 1884
Re: roman numerals flow diag  
« Reply #4 on: Feb 1st, 2009, 6:16pm »
Quote Quote Modify Modify

um. Yes. Lips Sealed
 
The reason I had such a big and billowy set of rules was I was tackling it from the left hand side.
 
Why? I was trying to understand why people who don't understand roman numerals don't understand roman numerals. We're taught to read for left to right, the count left to right... so the jump to doing things right to left seemed to not help for what I was doing, it became an intersting challenge too.
 
But such elegance wins, make no mistake about it.
IP Logged

a shade of wit and the art of farce.
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: roman numerals flow diag  
« Reply #5 on: Feb 2nd, 2009, 12:50am »
Quote Quote Modify Modify

on Feb 1st, 2009, 6:16pm, Noke Lieu wrote:
I was trying to understand why people who don't understand roman numerals don't understand roman numerals.

That's easy.  It is by definition.
 
@towr: excellent insight.
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: roman numerals flow diag  
« Reply #6 on: Feb 2nd, 2009, 1:28am »
Quote Quote Modify Modify

on Feb 1st, 2009, 6:16pm, Noke Lieu wrote:
We're taught to read for left to right, the count left to right...
Euhm. I'm not sure I quite agree. Try 17326493094; don't you start from the right to break it up into thousands? You have no idea of how significant the leftmost digit is, until you counted its position from the right. And for example addition also starts with the least significant digits.
Granted, you can easily write an algorithm to parse it from the left to right (multiply by ten and add the next), but the natural way to understand it, I'd have to say, is right to left; like reading arabic.
« Last Edit: Feb 2nd, 2009, 1:33am by towr » IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Noke Lieu
Uberpuzzler
*****



pen... paper... let's go! (and bit of plastic)

   
WWW

Gender: male
Posts: 1884
Re: roman numerals flow diag  
« Reply #7 on: Feb 2nd, 2009, 3:31pm »
Quote Quote Modify Modify

on Feb 2nd, 2009, 1:28am, towr wrote:

Euhm. I'm not sure I quite agree. Try 17326493094; don't you start from the right to break it up into thousands?

 
Interesting.  
 
I counted in groups for three left to right 173, 264, 930, 94.
Then reorganised the groups, again left to right but starting 17 326....
 
Then to convert it to words, I counted right to left thousands, milliions...
It reminds me strongly of dealing (in another life) with Okazaki fragments
Never really made the connection then.  
 
What about 0.17326493094  Roll Eyes
« Last Edit: Feb 2nd, 2009, 3:32pm by Noke Lieu » IP Logged

a shade of wit and the art of farce.
rmsgrey
Uberpuzzler
*****





134688278 134688278   rmsgrey   rmsgrey


Gender: male
Posts: 2873
Re: roman numerals flow diag  
« Reply #8 on: Feb 3rd, 2009, 10:32am »
Quote Quote Modify Modify

The lesson is to evaluate numbers starting from the decimal point and working outward Tongue
IP Logged
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: roman numerals flow diag  
« Reply #9 on: Feb 3rd, 2009, 10:44am »
Quote Quote Modify Modify

Actually, it is the opposite: you have to start from both ends.
- Start with a=b=0,
- for each digit from the left end to the dot, do a=a*10+digit,
- for each digit from the right end to the dot do b = (b+digit)/10,
- the value is a+b.
 Tongue
« Last Edit: Feb 3rd, 2009, 10:44am by Grimbal » IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board