<?php
function roman2number($roman){
array("letter" => 'I', "number" => 1), array("letter" => 'V', "number" => 5), array("letter" => 'X', "number" => 10), array("letter" => 'L', "number" => 50), array("letter" => 'C', "number" => 100), array("letter" => 'D', "number" => 500), array("letter" => 'M', "number" => 1000), array("letter" => 0, "number" => 0) );
$arabic = 0;
$state = 0;
$sidx = 0;
while ($len >= 0) {
$i = 0;
$sidx = $len;
while ($conv[$i]['number'] > 0) {
if (strtoupper(@$roman[$sidx]) == $conv[$i]['letter']) { if ($state > $conv[$i]['number']) {
$arabic -= $conv[$i]['number'];
} else {
$arabic += $conv[$i]['number'];
$state = $conv[$i]['number'];
}
}
$i++;
}
$len--;
}
return($arabic);
}
echo roman2number('IV');
PD9waHAKCmZ1bmN0aW9uIHJvbWFuMm51bWJlcigkcm9tYW4pewogICAgJGNvbnYgPSBhcnJheSgKICAgICAgICBhcnJheSgibGV0dGVyIiA9PiAnSScsICJudW1iZXIiID0+IDEpLAogICAgICAgIGFycmF5KCJsZXR0ZXIiID0+ICdWJywgIm51bWJlciIgPT4gNSksCiAgICAgICAgYXJyYXkoImxldHRlciIgPT4gJ1gnLCAibnVtYmVyIiA9PiAxMCksCiAgICAgICAgYXJyYXkoImxldHRlciIgPT4gJ0wnLCAibnVtYmVyIiA9PiA1MCksCiAgICAgICAgYXJyYXkoImxldHRlciIgPT4gJ0MnLCAibnVtYmVyIiA9PiAxMDApLAogICAgICAgIGFycmF5KCJsZXR0ZXIiID0+ICdEJywgIm51bWJlciIgPT4gNTAwKSwKICAgICAgICBhcnJheSgibGV0dGVyIiA9PiAnTScsICJudW1iZXIiID0+IDEwMDApLAogICAgICAgIGFycmF5KCJsZXR0ZXIiID0+IDAsICJudW1iZXIiID0+IDApCiAgICApOwogICAgJGFyYWJpYyA9IDA7CiAgICAkc3RhdGUgPSAwOwogICAgJHNpZHggPSAwOwogICAgJGxlbiA9IHN0cmxlbigkcm9tYW4pOwoKICAgIHdoaWxlICgkbGVuID49IDApIHsKICAgICAgICAkaSA9IDA7CiAgICAgICAgJHNpZHggPSAkbGVuOwoKICAgICAgICB3aGlsZSAoJGNvbnZbJGldWydudW1iZXInXSA+IDApIHsKICAgICAgICAgICAgaWYgKHN0cnRvdXBwZXIoQCRyb21hblskc2lkeF0pID09ICRjb252WyRpXVsnbGV0dGVyJ10pIHsKICAgICAgICAgICAgICAgIGlmICgkc3RhdGUgPiAkY29udlskaV1bJ251bWJlciddKSB7CiAgICAgICAgICAgICAgICAgICAgJGFyYWJpYyAtPSAkY29udlskaV1bJ251bWJlciddOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAkYXJhYmljICs9ICRjb252WyRpXVsnbnVtYmVyJ107CiAgICAgICAgICAgICAgICAgICAgJHN0YXRlID0gJGNvbnZbJGldWydudW1iZXInXTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICAkaSsrOwogICAgICAgIH0KCiAgICAgICAgJGxlbi0tOwogICAgfQoKICAgIHJldHVybigkYXJhYmljKTsKfQoKZWNobyByb21hbjJudW1iZXIoJ0lWJyk7Cg==