Old Russian measure of length: Difference between revisions

Content added Content deleted
(→‎{{header|D}}: added D)
(Small changes in D entry)
Line 23: Line 23:
<lang d>import std.stdio, std.string, std.algorithm, std.conv;
<lang d>import std.stdio, std.string, std.algorithm, std.conv;


void main(string[] a) {
void main(in string[] args) {
auto factor = ["arshin": 0.7112,
if (a.length == 3 && isNumeric(a[1])) {
"centimeter": 0.01,
double[string] factor = [
"tochka" : 0.000254,
"diuym": 0.0254,
"liniya" : 0.00254,
"fut": 0.3048,
"diuym" : 0.0254,
"kilometer": 1_000.0,
"vershok" : 0.04445,
"liniya": 0.00254,
"piad" : 0.1778,
"meter": 1.0,
"fut" : 0.3048,
"milia": 7_467.6,
"arshin" : 0.7112,
"piad": 0.1778,
"sazhen" : 2.1336,
"sazhen": 2.1336,
"versta" : 1066.8,
"tochka": 0.000254,
"milia" : 7467.6,
"vershok": 0.04445,
"centimeter" : 0.01,
"versta": 1_066.8];

"meter" : 1.0,
if (args.length != 3 || !isNumeric(args[1]) || args[2] !in factor)
"kilometer" : 1000.0,
return writeln("Please provide args Value and Unit.");
];

if (auto p = a[2] in factor) {
immutable magnitude = to!double(a[1]);
immutable magnitude = to!double(args[1]);
immutable meters = magnitude * (*p);
immutable meters = magnitude * factor[args[2]];
writefln("%s %s to: \n", a[1], a[2]);
writefln("%s %s to:\n", args[1], args[2]);
auto keys = factor.keys;
auto keys = factor.keys;
schwartzSort!(k => factor[k], "a < b")(keys);
keys.schwartzSort!(k => factor[k], "a < b");
foreach (key; keys)
foreach (key; keys)
writefln("%10s: %s", key, meters / factor[key]);
writefln("%10s: %s", key, meters / factor[key]);
return;
}
}
writeln("Please provide a number and unit");
}</lang>
}</lang>
{{out}}
{{out}}