Goals
- Programmatically evaluate Arabic numbers into sets
- Encode Arabic numbers into roman equiliventl
- (bonus) interactively using the terminal framework in the code
Starting point
<main>
<section id="stdout"></section>
<form onsubmit="javascript:checkForm();">
<input type="text" name="stdin">
</form>
</main>
<style>
.color0, .black { color: rgb(0, 0, 0); }
.color1, .red { color: rgb(227, 30, 96); }
.color2, .darkblue { color: rgb(96, 78, 189); }
.color3, .purple { color: rgb(255, 68, 253); }
.color4, .darkgreen { color: rgb(0, 163, 96); }
.color5, .grey { color: rgb(156, 156, 156); }
.color6, .medblue { color: rgb(20, 207, 253); }
.color7, .lightblue { color: rgb(208, 195, 255); }
.color8, .brown { color: rgb(96, 114, 3); }
.color9, .orange { color: rgb(255, 106, 60); }
.color10, .lightgrey { color: rgb(156, 156, 156); }
.color11, .pink { color: rgb(255, 160, 208); }
.color12, .lightgreen { color: rgb(20, 245, 60); }
.color13, .yellow { color: rgb(208, 221, 141); }
.color14, .aqua { color: rgb(114, 255, 208); }
.color15, .white { color: rgb(255, 255, 255); }
.bgcolor0, .bgblack { color: rgb(0, 0, 0); }
.bgcolor1, .bgred { color: rgb(227, 30, 96); }
.bgcolor2, .bgdarkblue { color: rgb(96, 78, 189); }
.bgcolor3, .bgpurple { color: rgb(255, 68, 253); }
.bgcolor4, .bgdarkgreen { color: rgb(0, 163, 96); }
.bgcolor5, .bggrey { color: rgb(156, 156, 156); }
.bgcolor6, .bgmedblue { color: rgb(20, 207, 253); }
.bgcolor7, .bglightblue { color: rgb(208, 195, 255); }
.bgcolor8, .bgbrown { color: rgb(96, 114, 3); }
.bgcolor9, .bgorange { color: rgb(255, 106, 60); }
.bgcolor10, .bglightgrey { color: rgb(156, 156, 156); }
.bgcolor11, .bgpink { color: rgb(255, 160, 208); }
.bgcolor12, .bglightgreen { color: rgb(20, 245, 60); }
.bgcolor13, .bgyellow { color: rgb(208, 221, 141); }
.bgcolor14, .bgaqua { color: rgb(114, 255, 208); }
.bgcolor15, .bgwhite { color: rgb(255, 255, 255); }
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font: inherit;
font-size: 100%;
vertical-align: baseline;
background-color: black;
color: rgb(107, 107, 107);
}
main {
font-weight: normal;
font-family: monospace;
font-size: 18px;
}
input {
width: 640px;
color: rgb(255, 68, 90);
background-color: black;
}
#stdout {
height: 480px;
width: 680px;
color: rgb(107, 107, 107);
background: black;
}
</style>
<script>
// libc
let stdio = {
out: () => document.querySelector('#stdout'),
in: () => document.querySelector('input[name="stdin"]'),
put: (str) => stdio.out().innerHTML += str,
putln: (str) => stdio.out().innerHTML += (str + stdio.newline()),
get: (str) => stdio.in().value,
newline: () => "<br>"
};
// main
let M = (x) => Math.floor(x % 10000 / 1000),
C = (x) => Math.floor(x / 100 % 10),
V = (x) => Math.floor(x % 10 / 5),
I = (x) => Math.floor(x % 10),
L = (x) => Math.floor(x % 50 / 10),
X = (x) => Math.floor(x / 10 % 10);
let f = (x) => {
if (x == 0) return ".";
if (M(x)) return "M".repeat(M(x));
if (C(x)) return "C".repeat(C(x));
if (V(x)) return "V";
if (I(x)) return "I".repeat(I(x));
if (L(x)) return "L".repeat(L(x));
if (X(x)) return "X".repeat(X(x));
};
let setup = () => {
stdio.out().classList.add("color8");
stdio.out().classList.add("bgblack");
stdio.in().classList.add("color14");
stdio.in().classList.add("bgcolor0");
stdio.in().value = "128";
}
function checkForm(n) {
let input = n || stdio.in().value;
stdio.putln(`${input}: ${f(input)}`);
}
setup();
stdio.putln("Roman numeral converter challenge by Dwight Spencer@1:124/5017");
stdio.putln("");
checkForm();
checkForm(7);
checkForm(33);
checkForm(6);
</script>
Reward
Name entered into the quarterly drawing for prizes that include gift cards, tees, and more.