Old Russian measure of length: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Phix}}: syntax coloured, made p2js compatible) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 22:
:<code>commandname <value> <unit></code>
<
‘fut’ = 0.3048, ‘kilometer’ = 1000.0, ‘liniya’ = 0.00254,
‘meter’ = 1.0, ‘milia’ = 7467.6, ‘piad’ = 0.1778,
Line 40:
print(‘#. #. to:’.format(value, unit))
L(unt, mlt) sorted(unit2mult.items())
print(‘ #10: #.’.format(unt, value * unit2mult[unit] / mlt))</
{{out}}
Line 62:
=={{header|Action!}}==
{{libheader|Action! Real Math}}
<
DEFINE PTR="CARD"
Line 140:
PrintResult(value,unit)
OD
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Old_Russian_measure_of_length.png Screenshot from Atari 8-bit computer]
Line 172:
===Vanilla===
<
on convertLinear(inputNumber, inputUnitRecord, outputUnitRecord)
set {inputType, outputType} to {inputUnitRecord's type, outputUnitRecord's type}
Line 248:
end demo
return demo()</
{{output}}
<
1000 metres; 100000 centimetres; 1 kilometre; 2.249718785152E+4 vershoks; 1406.07424072 arshins; 468.69141357 sazhens; 0.93738283 verstas
1 versta is:
1066.8 metres; 106680 centimetres; 1.0668 kilometres; 24000 vershoks; 1500 arshins; 500 sazhens; 1 versta"</
===AppleScriptObjC===
<
use framework "Foundation"
use scripting additions
Line 333:
end demo
return demo()</
{{output}}
<
1,000 metres; 100,000 centimetres; 1 kilometre; 22,497.188 vershoks; 1,406.074 arshins; 468.691 sazhens; 0.937 verstas
1 versta is:
1,066.8 metres; 106,680 centimetres; 1.067 kilometres; 24,000 vershoks; 1,500 arshins; 500 sazhens; 1 versta"</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f OLD_RUSSIAN_MEASURE_OF_LENGTH.AWK
BEGIN {
Line 373:
printf("error: invalid measure; choose from: %s\n\n",units)
}
</syntaxhighlight>
{{out}}
<pre>
Line 409:
=={{header|BBC BASIC}}==
<
@% = &90E
PROColdrus(1, "meter")
Line 434:
NEXT
ENDIF
ENDPROC</
{{out}}
<pre>1 meter =
Line 466:
=={{header|C}}==
Accepts length and unit as input, prints out length in all other units. Usage printed on incorrect invocation.
<syntaxhighlight lang="c">
#include<string.h>
#include<stdlib.h>
Line 504:
return 0;
}
</syntaxhighlight>
Output :
<pre>
Line 540:
=={{header|C++}}==
<
#include <iostream>
#include <iomanip>
Line 602:
}
//-------------------------------------------------------------------------------------------
</syntaxhighlight>
Output:
<pre>
Line 640:
=={{header|D}}==
{{trans|Raku}}
<
void main(in string[] args) {
Line 665:
foreach (immutable key; factor.keys.schwartzSort!(k => factor[k]))
writefln("%10s: %s", key, meters / factor[key]);
}</
{{out}}
<pre>1 meter to:
Line 701:
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
program Old_Russian_measure_of_length;
Line 776:
readln(yn);
until yn.toLower = 'n';
end.</
=={{header|Elena}}==
{{trans|Julia}}
ELENA 5.2:
<
import system'routines;
import extensions;
Line 821:
console.printPaddingLeft(30, u, ":").printLine(value * unit2mult[unit] / mlt)
}
}</
{{out}}
<pre>2.3 meter to:
Line 841:
=={{header|Factor}}==
This solution makes use of Factor's rather robust <code>units</code> vocabulary. Units may be defined in terms of any unit and converted to any unit through the power of inverse functions (via the <code>inverse</code> vocabulary). This means that we also have access to a variety of units defined in <code>units.si</code>, <code>units.imperial</code>, etc.
<
sequences units.imperial units.si vocabs ;
IN: rosetta-code.units.russian
Line 872:
PRIVATE>
MAIN: main</
{{out}}
<pre>
Line 931:
=={{header|Fortran}}==
<
IMPLICIT NONE
REAL, PARAMETER:: E_m = 1.
Line 981:
WRITE (*, '(F20.3, " ", A)') RD_V / wert(J), nam(J)
END DO
END PROGRAM RUS</
{{out}}
<pre>m mm km cm arshin fut piad vershok dyuim liniya tochka ladon lokot sazhen versta milya
Line 1,022:
=={{header|FreeBASIC}}==
<
Dim units(1 To 13) As String = {"tochka", "liniya", "dyuim", "vershok", "piad", "fut", _
Line 1,065:
Loop Until yn = "n"
End</
Sample input/output:
{{out}}
Line 1,107:
=={{header|Forth}}==
Tested with GForth.
<
create values 1000.0e f, 1.0e f, 0.01e f, 0.000254e f, 0.00254e f, 0.0254e f, 0.04445e f, 0.1778e f, 0.3048e f, 0.7112e f, 2.1336e f, 1066.8e f, 7467.6e f,
: unit ( u1 -- caddr u1 )
Line 1,132:
1e s" meter" show
20e s" versta" show
10e s" milia" show</
{{out}}
<pre>
Line 1,188:
=={{header|Frink}}==
One of Frink's unique features is tracking units of measure through all calculations. It is easy to add new units of measure and allow them to be automatically converted between any existing units. Frink's standard data file contains 642 units of length (not including prefixes) that this program can convert between.
<
vershok := 1/16 arshin
sazhen := 3 arshin
Line 1,210:
println[" " + (val -> "meters")]
println[" " + (val -> "centimeters")]
println[" " + (val -> "kilometers")]</
{{out}}
<pre>
Line 1,227:
=={{header|Go}}==
{{trans|Kotlin}}
<
import (
Line 1,294:
}
}
}</
{{out}}
Line 1,336:
=={{header|Haskell}}==
<
import Text.Printf (printf)
Line 1,370:
(_) -> do
name <- getProgName
printf "Arguments were wrong - please use ./%s <number> <unit>\n" name</
Output:
Line 1,421:
=={{header|J}}==
Translation of python.
<syntaxhighlight lang="j">
NB. Use, linux.
NB. $ /usr/local/j64-801/bin/jconsole j.ijs 8 meter
Line 1,443:
end.
)
</syntaxhighlight>
<pre>
$ /usr/local/j64-801/bin/jconsole j.ijs 8 meter
Line 1,478:
=={{header|Java}}==
<
final static String[] keys = {"tochka", "liniya", "centimeter", "diuym",
Line 1,510:
return Double.NaN;
}
}</
<pre>1 meter to:
Line 1,548:
{{trans|Python}}
<
const unit2mult = Dict(
Line 1,570:
for (unt, mlt) in sort(unit2mult)
@printf(" %10s: %g\n", unt, value * unit2mult[unit] / mlt)
end</
{{out}}
Line 1,591:
=={{header|Kotlin}}==
{{trans|FreeBASIC}}
<
/* clears console on Windows 10 */
Line 1,635:
}
while (yn == "y")
}</
Sample input/output
{{out}}
Line 1,677:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
These units are built-in to Wolfram Language:
<
units = {"RussianVershoks", "RussianArshins", "RussianSazhens", "RussianVerstas", "Centimeters", "Meters", "Kilometers"};
ConvertRussianQuantities[q_Quantity] := UnitConvert[q, #] & /@ Select[units, QuantityUnit[q] != # &]
ConvertRussianQuantities[Quantity[1, "Vershoks"]]
ConvertRussianQuantities[Quantity[1, "Arshins"]]</
{{out}}
<pre>{1/16 Russian arshins, 1/48 Russian sazhens, 1/24000 Russian versts, 889/200 cm, 889/20000 m, 889/20000000 km}
Line 1,688:
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">П7 1 0 0 * П8 1 ВП 5 /
П9 ИП7 1 0 6 7 / П0 5 0
0 * ПC 3 * ПA 1 6 * ПB
С/П ПB 1 6 / ПA 3 / ПC 5
0 0 / П0 1 0 6 7 / БП
00</
''Instruction:''
Line 1,704:
=={{header|Nim}}==
{{trans|Python}}
<
const Unit2Mult = {"arshin": 0.7112, "centimeter": 0.01, "diuym": 0.0254,
Line 1,726:
echo value, ' ', unit, " to:"
for (key, mult) in Unit2Mult.pairs:
echo key.align(10), ": ", formatFloat(value * Unit2Mult[unit] / mult, ffDecimal, 5)</
{{out}}
Line 1,748:
Displaying converted values to 5 significant digits.
{{trans|Raku}}
<
my($magnitude, $unit) = @_;
my %factor = (
Line 1,789:
print convert(1,'meter'), "\n\n";
print convert(1,'milia'), "\n";</
{{out}}
<pre> tochka: 3937.0
Line 1,819:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">units</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #008000;">"-- metric ---"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">},</span>
Line 1,887:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000080;font-style:italic;">--end while</span>
<!--</
{{out}}
<pre>
Line 1,914:
:<code>commandname <value> <unit></code>
<
unit2mult = {"arshin": 0.7112, "centimeter": 0.01, "diuym": 0.0254,
Line 1,935:
print("%g %s to:" % (value, unit))
for unt, mlt in sorted(unit2mult.items()):
print(' %10s: %g' % (unt, value * unit2mult[unit] / mlt))</
{{out}}
Line 1,986:
=={{header|Racket}}==
Follows the Raku solution, produces similar output.
<
#lang racket
Line 2,014:
(show 'meter)
(show 'milia)
</syntaxhighlight>
=={{header|Raku}}==
Line 2,021:
Fairly straightfoward. Define a hash of conversion factors then apply them. Makes no attempt to do correct pluralization because I have no idea what the correct plurals are and little interest in researching them. Conversion factors from Wikipedia: [[wp:Obsolete_Russian_units_of_measurement#Length|Obsolete Russian units of measurement]].
<syntaxhighlight lang="raku"
say '*' x 40, "\n";
Line 2,051:
for %factor.keys.sort:{ +%factor{$_} }
}
</syntaxhighlight>
<pre>
Line 2,095:
::* uses the correct length unit names when not plural
::* columnarized the output (instead of a horizontal stream).
<
numeric digits 200 /*lots of digits. */
/*──translation───*/
Line 2,225:
err: say center(' error ', sw % 2, "*"); do j=1 to arg(); say arg(j); end; exit 13
s: if arg(1)=1 then return arg(3); return word( arg(2) 's', 1) /*plurals.*/
tell: parse arg $; numeric digits 8; $= $ / 1; say right($, 40) arg(2)s($); return</
This REXX program makes use of '''LINESIZE''' REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console).
Line 2,286:
=={{header|Ring}}==
<
# Project : Old Russian measure of length
Line 2,327:
end
end
</syntaxhighlight>
Output:
<pre>
Line 2,364:
=={{header|Ruby}}==
<
RATIOS =
Line 2,392:
# 13*13 = 169 methods supported, but not:
p Distances.mile2piad(1)
</syntaxhighlight>
{{out}}
<pre>2 meter =
Line 2,419:
:<code>commandname <value> <unit></code>
<
use std::process;
use std::collections::HashMap;
Line 2,456:
}
</syntaxhighlight>
<pre>
$ ./oldrus test
Line 2,495:
=={{header|Scala}}==
<
object OldRussianLengths extends App {
Line 2,516:
} else println("Please provide a number and unit on the command line.")
}</
=={{header|Sidef}}==
{{trans|Raku}}
<
var factor = Hash(
tochka => 0.000254,
Line 2,547:
convert(1, 'meter')
say('')
convert(1, 'milia')</
{{out}}
<pre>1 meter to:
Line 2,583:
Tcllib already has a [http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/units/units.html units] package which knows about a lot of things, and can be taught more. Since the other examples in this page provide a nicely tabulated conversions for 1 meter, we can copy that directly to get started ...
<syntaxhighlight lang="tcl">
package require units
Line 2,622:
add_russian_units
demo
</syntaxhighlight>
{{out}}
Line 2,659:
One nice side effect of this implementation is that units can work with more complex dimensions:
<syntaxhighlight lang="tcl">
% units::convert "1 piad^2" "hectare"
3.1612805858160454e-6
% units::convert "100 km/h" "versta/minute"
1.562305
</syntaxhighlight>
=={{header|Wren}}==
Line 2,670:
{{libheader|Wren-fmt}}
{{libheader|Wren-str}}
<
import "/fmt" for Fmt
import "/str" for Str
Line 2,723:
if (yn == "n") break
System.print()
}</
{{out}}
|