add IIII decimal variation

This commit is contained in:
ivan 2023-03-13 16:35:14 +03:00
parent 60545ee3ed
commit a91a41f28c
1 changed files with 39 additions and 15 deletions

View File

@ -137,7 +137,8 @@ function r2a(roma, type) {
else arab = arab - prev * 2 + curr;
}
switch (type) {
case "r10": if (roma == a2r10(arab))
case "r10":
if (roma == a2r10(arab) || roma == a2r10i(arab))
return arab;
case "r8": if (roma == a2r8(arab))
return arab;
@ -189,6 +190,18 @@ function a2r10(n) {
return roman;
}
function a2r10i(n) {
var roman = '';
roman += 'M'.repeat(n / 1000); n %= 1000;
roman += 'D'.repeat(n / 500); n %= 500;
roman += 'C'.repeat(n / 100); n %= 100;
roman += 'L'.repeat(n / 50); n %= 50;
roman += 'X'.repeat(n / 10); n %= 10;
roman += 'V'.repeat(n / 5); n %= 5;
roman += 'I'.repeat(n);
return roman;
}
function a2r8(n) {
var roman = '';
roman += 'M'.repeat(n / 512); n %= 512;
@ -205,14 +218,19 @@ function a2r(arab, type) {
if (arab > 0 && arab < 4000) {
switch (type) {
case "r10": return a2r10(arab);
case "r10i": return a2r10i(arab);
case "r8": return a2r8(arab);
}
} else return "...";
}
function updatea2r() {
document.getElementById("outr10").innerHTML =
a2r(document.getElementById("arin").value, "r10");
var r10 = a2r(document.getElementById("arin").value, "r10");
var r10i = a2r(document.getElementById("arin").value, "r10i");
var resr10 = r10;
if (r10 != r10i) resr10 += "<br><font style='color: gray;'>" + r10i +
"</font>";
document.getElementById("outr10").innerHTML = resr10;
document.getElementById("outr8").innerHTML =
a2r(document.getElementById("arin").value, "r8");
}
@ -257,41 +275,47 @@ function fulltable(type) {
restab += "<tr><td align=right>" + a2r8(num) + "</td>";
restab += "<td align=center style='background: #112222;'>" + num +
"</td>";
restab += "<td align=left>" + a2r10(num) + "</td></tr>";
var r10 = a2r10(num);
var r10i = a2r10i(num);
restab += "<td align=left>" + r10;
if (r10 != r10i)
restab += "<font style='color: gray;'> " + r10i + "</font>";
restab += "</td></tr>";
}
restab += "</table>";
document.getElementById("allnum").innerHTML = restab;
break;
case "roman8":
var restab = "<p align=center>octal coincidence table</p>";
document.getElementById("allnum").innerHTML = restab;
restab += "<table class='allnumtab'><tr><td align=right>arabic" +
"</td><td align=center>octal roman</td><td align=left>" +
"decimal roman value</td>";
var num;
for (num = 1; num < 4000; num++) {
var a2r8num = a2r8(num);
var r8 = a2r8(num);
restab += "<tr><td align=right>" + num + "</td>";
restab += "<td align=center style='background: #112222;'>" +
a2r8num + "</td>";
restab += "<td align=left>" + r2a(a2r8num, "r10") + "</td></tr>";
r8 + "</td>";
restab += "<td align=left>" + r2a(r8, "r10") + "</td></tr>";
}
restab += "</table>";
document.getElementById("allnum").innerHTML = restab;
break;
case "roman10":
var restab = "<p align=center>decimal coincidence table</p>";
document.getElementById("allnum").innerHTML = restab;
restab += "<table class='allnumtab'><tr><td align=right>arabic" +
"</td><td align=center>decimal roman</td><td align=left>" +
"octal roman value</td>";
var num;
for (num = 1; num < 4000; num++) {
var a2r10num = a2r10(num);
var r10 = a2r10(num);
var r10i = a2r10i(num);
restab += "<tr><td align=right>" + num + "</td>";
restab += "<td align=center style='background: #112222;'>" +
a2r10num + "</td>";
var coinc = r2a(a2r10num, "r8");
restab += "<td align=center style='background: #112222;'>" + r10;
if (r10 != r10i)
restab += "<font style='color: gray;'> " + r10i + "</font>";
restab += "</td>";
var coinc = r2a(r10, "r8");
if (coinc == "...") restab += "<td></td></tr>";
else restab += "<td align=left>" + coinc + "</td></tr>";
}
@ -367,7 +391,7 @@ function chbg() {
<input id="roin" class="inp" onchange="updater2a();"
size="7" type="text" style="text-transform: uppercase;"
name="roman" maxlength="16" placeholder="MDCLXVI"
value="V"><br>
value="DCLXVI"><br>
</td>
</tr>
<tr>