EntropySink

Technical & Scientific => Programming => Topic started by: Mike on May 01, 2005, 02:44:03 PM

Title: Dec to Roman Numerial
Post by: Mike on May 01, 2005, 02:44:03 PM
Ok here's what I have so far.  Written in PHP of course.  The problem is that the border trick, while working, doesn't look that great.  I need to find another method to put a bar over the symbol.  This craps out at about 100,00 posts but I figure we have time to deal with that.


function decRN($num)
{
$values = array (
100000 => array (
array('C', 1),
),
90000 => array (
array('X', 1),
array('C', 1),
),
50000 => array (
array('L', 1),
),
40000 => array (
array('X', 1),
array('L', 1),
),
10000 => array (
array('X', 1),
),
9000 => array (
array('M', 0),
array('X', 1),
),
5000 => array (
array('V', 1),
),
4000 => array (
array('M', 0),
array('V', 1),
),
1000 => array(
array('M', 0),
),
900 =>  array (
array('C', 0),
array('M', 0),
),
500 =>  array (
array('D', 0),
),
400 =>  array (
array('C', 0),
array('D', 0),
),
100 =>  array (
array('C', 0),
),
90 =>   array (
array('X', 0),
array('C', 0),
),
50 =>   array (
array('L', 0),
),
40 =>   array (
array('X', 0),
array('L', 0),
),
10 =>   array (
array('X', 0),
),
9 =>    array (
array('I', 0),
array('X', 0),
),
5 =>    array (
array('V', 0),
),
4 =>    array (
array('I', 0),
array('V', 0),
),
1 =>    array (
array('I', 0),
),
);
$str = '';
foreach($values as $val => $data )
{
while ( $num >= $val )
{
foreach ($data AS $sym)
$str.= '' . $sym[0] . '';
$num -= $val;
}
}
return $str;
}

So if anyone has any ideas of a better way to get the bar over the symbol please let me know
Title: Dec to Roman Numerial
Post by: jverkoey on May 01, 2005, 03:01:27 PM
We could just add our own symbols.

I uploaded source which is a tad better looking, though written in C.
Title: Dec to Roman Numerial
Post by: Mike on May 01, 2005, 03:07:22 PM
Yes but your code requires more effert.  Since PHP handles arrays very nicely its simpler to do it my way.

Also yours doesn't seem to handle over 4999.  The problem with adding our own is just graphics.  But if someone made up a nice set I could easily manipulate the code to use the graphics.
Title: Dec to Roman Numerial
Post by: jverkoey on May 01, 2005, 03:11:34 PM
Maybe we should just keep normal decimal output.... :dunno:

*stabs self*
Title: Dec to Roman Numerial
Post by: Mike on May 01, 2005, 03:13:55 PM
Thats a discussion for the poll not here.