Old Russian measure of length: Difference between revisions

m
m (→‎{{header|REXX}}: changed/add whitespace and comments, aligned statements.)
imported>Arakov
 
(30 intermediate revisions by 20 users not shown)
Line 22:
:<code>commandname <value> <unit></code>
 
<langsyntaxhighlight lang="11l">V unit2mult = [‘arshin’ = 0.7112, ‘centimeter’ = 0.01, ‘diuym’ = 0.0254,
‘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))</langsyntaxhighlight>
 
{{out}}
Line 59:
versta: 0.000937383
</pre>
 
=={{header|Action!}}==
{{libheader|Action! Real Math}}
<syntaxhighlight lang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
DEFINE PTR="CARD"
DEFINE UNIT_COUNT="10"
 
PTR ARRAY
names(UNIT_COUNT),
values(UNIT_COUNT)
BYTE count=[0]
 
PROC Append(CHAR ARRAY name REAL POINTER value)
names(count)=name
values(count)=value
count==+1
RETURN
 
PROC Init()
REAL
arshin,centimeter,kilometer,meter,
sazhen,vershok,versta
 
ValR("0.7112",arshin) Append("arshins",arshin)
ValR("0.01",centimeter) Append("centimeters",centimeter)
ValR("1000",kilometer) Append("kilometers",kilometer)
ValR("1",meter) Append("meters",meter)
ValR("2.1336",sazhen) Append("sazhens",sazhen)
ValR("0.04445",vershok) Append("vershoks",vershok)
ValR("1066.8",versta) Append("versts",versta)
RETURN
 
BYTE FUNC GetUnit()
BYTE i,res
 
FOR i=1 TO count
DO
PrintF("%B-%S",i,names(i-1))
IF i<count THEN Put(32) FI
OD
PutE()
DO
PrintF("Get unit (1-%B): ",count)
res=InputB()
UNTIL res>=1 AND res<=count
OD
RETURN (res-1)
 
PROC PrintResult(REAL POINTER value BYTE unit)
BYTE i
REAL res,tmp
 
PutE()
FOR i=0 TO count-1
DO
IF i=unit THEN
RealAssign(value,res)
ELSE
RealMult(value,values(unit),tmp)
RealDiv(tmp,values(i),res)
FI
Print(" ") PrintR(res)
PrintF(" %S%E",names(i))
OD
PutE()
RETURN
 
PROC Main()
BYTE unit
REAL value
 
Put(125) PutE() ;clear screen
Init()
 
DO
Print("Get value: ")
InputR(value)
unit=GetUnit()
PrintResult(value,unit)
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Old_Russian_measure_of_length.png Screenshot from Atari 8-bit computer]
<pre>
Get value: 1
1-arshins 2-centimeters 3-kilometers 4-meters 5-sazhens 6-vershoks 7-versts
Get unit (1-7): 4
 
1.40607424 arshins
100 centimeters
1.0E-03 kilometers
1 meters
.4686914135 sazhens
22.49718785 vershoks
9.37382827E-04 versts
 
Get value: 10
1-arshins 2-centimeters 3-kilometers 4-meters 5-sazhens 6-vershoks 7-versts
Get unit (1-7): 7
 
15000 arshins
1066800 centimeters
10.668 kilometers
10668 meters
5000 sazhens
240000 vershoks
10 versts
</pre>
 
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68">
BEGIN # convert Old Russian units to/from metric #
# mode to hold details of the units - value is in meters #
MODE UNIT = STRUCT( STRING name, REAL value );
# gets a UNIT from the standard input #
PROC read unit = UNIT:
BEGIN
UNIT r;
read( ( value OF r, name OF r, newline ) );
# trim leading and trailing spaces from the name #
INT f pos := LWB name OF r;
WHILE IF f pos <= UPB name OF r THEN ( name OF r )[ f pos ] = " " ELSE FALSE FI
DO
f pos +:= 1
OD;
INT b pos := UPB name OF r;
WHILE IF b pos >= LWB name OF r THEN ( name OF r )[ b pos ] = " " ELSE FALSE FI
DO
b pos -:= 1
OD;
IF f pos > b pos THEN
# no name #
name OF r := ""
ELIF ( name OF r )[ b pos ] = "s" THEN
# the user entered a plural - remove the "S" #
name OF r := ( name OF r )[ f pos : b pos - 1 ]
ELSE
# non-blank, non-plural name #
name OF r := ( name OF r )[ f pos : b pos ]
FI;
r
END # read unit # ;
# units and their value in meters #
[]UNIT units = ( ( "arshin", 0.7112 ), ( "centimeter", 0.01 ), ( "diuym", 0.0254 )
, ( "fut", 0.3048 ), ( "kilometer", 1000.0 ), ( "liniya", 0.00254 )
, ( "meter", 1.0 ), ( "milia", 7467.6 ), ( "piad", 0.1778 )
, ( "sazhen", 2.1336 ), ( "tochka", 0.000254 ), ( "vershok", 0.04445 )
, ( "versta", 1066.8 )
);
WHILE # prompt for units and show their conversions #
print( ( "Enter the unit to convert - value followed by unit name (or 0 to quit): " ) );
UNIT r := read unit;
value OF r /= 0
DO
# find the unit name in the table of valid units #
INT u pos := LWB units - 1;
FOR i FROM LWB units TO UPB units WHILE u pos < LWB units DO
IF name OF r = name OF units[ i ] THEN
u pos := i
FI
OD;
IF u pos < LWB units THEN
# didn't find the units #
print( ( "Unknown units - please enter one of:", newline, " " ) );
FOR i FROM LWB units TO UPB units DO
print( ( name OF units[ i ], IF i = UPB units THEN newline ELSE ", " FI ) )
OD
ELSE
# found the units - show the values in the other units #
UNIT u = units[ u pos ];
print( ( fixed( value OF r, -12, 6 ), " ", name OF u, " is:", newline ) );
FOR i FROM LWB units TO UPB units DO
IF i /= u pos THEN
print( ( fixed( ( value OF r * value OF u )/ value OF units[ i ], -16, 6 )
, " ", name OF units[ i ], newline
)
)
FI
OD
FI
OD
END
</syntaxhighlight>
{{out}}
<pre>
Enter the unit to convert - value followed by unit name (or 0 to quit): 1 meter
1.000000 meter is:
1.406074 arshin
100.000000 centimeter
39.370079 diuym
3.280840 fut
0.001000 kilometer
393.700787 liniya
0.000134 milia
5.624297 piad
0.468691 sazhen
3937.007874 tochka
22.497188 vershok
0.000937 versta
Enter the unit to convert - value followed by unit name (or 0 to quit): 3 arshin
3.000000 arshin is:
213.360000 centimeter
84.000000 diuym
7.000000 fut
0.002134 kilometer
840.000000 liniya
2.133600 meter
0.000286 milia
12.000000 piad
1.000000 sazhen
8400.000000 tochka
48.000000 vershok
0.002000 versta
Enter the unit to convert - value followed by unit name (or 0 to quit): 0
</pre>
 
=={{header|AppleScript}}==
===Vanilla===
 
<syntaxhighlight lang="applescript">-- General purpose linear measurement converter.
on convertLinear(inputNumber, inputUnitRecord, outputUnitRecord)
set {inputType, outputType} to {inputUnitRecord's type, outputUnitRecord's type}
if (inputType is not outputType) then error "Unit type mismatch: " & inputType & ", " & outputType
-- The |offset| values are only relevant to temperature conversions and default to zero.
set inputUnit to inputUnitRecord & {|offset|:0}
set outputUnit to outputUnitRecord & {|offset|:0}
return (inputNumber - (inputUnit's |offset|)) * (inputUnit's coefficient) / (outputUnit's coefficient) ¬
+ (outputUnit's |offset|)
end convertLinear
 
on program(inputNumber, inputUnitName)
-- The task description only specifies these seven units, but more can be added if wished.
-- The coefficients are the equivalent lengths in metres.
set unitRecords to {{|name|:"metre", type:"length", coefficient:1.0}, ¬
{|name|:"centimetre", type:"length", coefficient:0.01}, {|name|:"kilometre", type:"length", coefficient:1000.0}, ¬
{|name|:"vershok", type:"length", coefficient:0.04445}, {|name|:"arshin", type:"length", coefficient:0.7112}, ¬
{|name|:"sazhen", type:"length", coefficient:2.1336}, {|name|:"versta", type:"length", coefficient:1066.8}}
-- Massage the given input unit name if necessary.
if (inputUnitName ends with "s") then set inputUnitName to text 1 thru -2 of inputUnitName
if (inputUnitName ends with "meter") then set inputUnitName to (text 1 thru -3 of inputUnitName) & "re"
-- Get the record with the input unit name from 'unitRecords'.
set inputUnitRecord to missing value
repeat with thisRecord in unitRecords
if (thisRecord's |name| is inputUnitName) then
set inputUnitRecord to thisRecord's contents
exit repeat
end if
end repeat
if (inputUnitRecord is missing value) then error "Unrecognised unit name: " & inputUnitName
-- Guess the user's spelling preference from the short-date order configured on their machine.
tell (current date) to set {Feb1, its day, its month, its year} to {it, 1, 2, 3333}
set USSpelling to (Feb1's short date string's first word as integer is 2)
-- Convert the input number to its equivalents in all the specified units, rounding to eight decimal
-- places and getting integer values as AS integers where possible. Pair the results with the unit names.
set output to {}
repeat with thisRecord in unitRecords
set outputNumber to convertLinear(inputNumber, inputUnitRecord, thisRecord)
set outputNumber to outputNumber div 1 + ((outputNumber * 100000000 mod 100000000) as integer) / 100000000
if (outputNumber mod 1 is 0) then set outputNumber to outputNumber div 1
set outputUnitName to thisRecord's |name|
if ((outputUnitName ends with "metre") and (USSpelling)) then ¬
set outputUnitName to (text 1 thru -3 of outputUnitName) & "er"
if (outputNumber is not 1) then set outputUnitName to outputUnitName & "s"
set end of output to {outputNumber, outputUnitName}
end repeat
return output -- {{number, unit name}, … }
end program
 
on demo()
set output to {}
set astid to AppleScript's text item delimiters
repeat with input in {{1, "kilometre"}, {1, "versta"}}
set {inputNumber, inputUnitName} to input
set end of output to (inputNumber as text) & space & inputUnitName & " is:"
set conversions to program(inputNumber, inputUnitName)
set AppleScript's text item delimiters to space
repeat with thisConversion in conversions
set thisConversion's contents to thisConversion as text
end repeat
set AppleScript's text item delimiters to "; "
set end of output to conversions as text
end repeat
set AppleScript's text item delimiters to linefeed
set output to output as text
set AppleScript's text item delimiters to astid
return output
end demo
 
return demo()</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"1 kilometre is:
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"</syntaxhighlight>
 
===AppleScriptObjC===
 
<syntaxhighlight lang="applescript">use AppleScript version "2.5" -- macOS 10.12 (Sierra) or later. Not 10.11 (El Capitan).
use framework "Foundation"
use scripting additions
 
property |⌘| : current application
 
-- Return a custom NSUnit with a linear converter.
on customNSUnit(unitClassName, symbol, coefficient, |offset|)
set converter to |⌘|'s class "NSUnitConverterLinear"'s alloc()'s initWithCoefficient:(coefficient) |constant|:(|offset|)
return |⌘|'s class unitClassName's alloc()'s initWithSymbol:(symbol) converter:(converter)
end customNSUnit
 
on program(inputNumber, inputUnitName)
-- The task description only specifies these seven units, but more can be added if wished.
-- The base unit of the NSUnitLength class is 'meters'.
set unitRecords to {{|name|:"metre", NSUnit:|⌘|'s class "NSUnitLength"'s |meters|()}, ¬
{|name|:"centimetre", NSUnit:|⌘|'s class "NSUnitLength"'s |centimeters|()}, ¬
{|name|:"kilometre", NSUnit:|⌘|'s class "NSUnitLength"'s |kilometers|()}, ¬
{|name|:"vershok", NSUnit:customNSUnit("NSUnitLength", "vershok", 0.04445, 0)}, ¬
{|name|:"arshin", NSUnit:customNSUnit("NSUnitLength", "arshin", 0.7112, 0)}, ¬
{|name|:"sazhen", NSUnit:customNSUnit("NSUnitLength", "sazhen", 2.1336, 0)}, ¬
{|name|:"versta", NSUnit:customNSUnit("NSUnitLength", "versta", 1066.8, 0)}}
-- Massage the given input unit name if necessary.
if (inputUnitName ends with "s") then set inputUnitName to text 1 thru -2 of inputUnitName
if (inputUnitName ends with "meter") then set inputUnitName to (text 1 thru -3 of inputUnitName) & "re"
-- Get the record with the input unit name from 'unitRecords'.
set filter to |⌘|'s class "NSPredicate"'s predicateWithFormat_("name == %@", inputUnitName)
set filteredList to ((|⌘|'s class "NSArray"'s arrayWithArray:(unitRecords))'s filteredArrayUsingPredicate:(filter)) as list
if (filteredList is {}) then error "Unrecognised unit name: " & inputUnitName
set inputUnitRecord to beginning of filteredList
-- Set up an NSMeasurement using the input number and the NSUnit from the record.
set inputMeasurement to |⌘|'s class "NSMeasurement"'s alloc()'s ¬
initWithDoubleValue:(inputNumber) unit:(inputUnitRecord's NSUnit)
-- Get equivalent NSMeasurements in all the specified units and format them as text using an NSMeasurementFormatter
-- configured to use the measurements' own units instead of local equivalents and, in the case of the three preset units,
-- to include the full words, localised and pluralised as appropriate, instead of the symbols "m", "cm", or "km".
set output to {}
set measurementFormatter to |⌘|'s class "NSMeasurementFormatter"'s new()
tell measurementFormatter to setUnitOptions:(|⌘|'s NSMeasurementFormatterUnitOptionsProvidedUnit)
tell measurementFormatter to setUnitStyle:(|⌘|'s NSFormattingUnitStyleLong)
repeat with thisRecord in unitRecords
set outputMeasurement to (inputMeasurement's measurementByConvertingToUnit:(thisRecord's NSUnit))
set formattedMeasurement to (measurementFormatter's stringFromMeasurement:(outputMeasurement)) as text
if not ((outputMeasurement's doubleValue() is 1) or (thisRecord's |name| ends with "metre")) then ¬
set formattedMeasurement to formattedMeasurement & "s"
set end of output to formattedMeasurement
end repeat
return output -- {formatted text, … }
end program
 
on demo()
considering numeric strings
if ((system info)'s system version < "10.12") then ¬
error "El Capitan doesn't support the Foundation framework's Units and Measurement system"
end considering
set output to {}
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "; "
repeat with input in {{1, "kilometre"}, {1, "versta"}}
set {inputNumber, inputUnitName} to input
set end of output to (inputNumber as text) & space & inputUnitName & " is:"
set end of output to program(inputNumber, inputUnitName) as text
end repeat
set AppleScript's text item delimiters to linefeed
set output to output as text
set AppleScript's text item delimiters to astid
return output
end demo
 
return demo()</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"1 kilometre is:
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"</syntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f OLD_RUSSIAN_MEASURE_OF_LENGTH.AWK
BEGIN {
Line 92 ⟶ 480:
printf("error: invalid measure; choose from: %s\n\n",units)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 127 ⟶ 515:
</pre>
 
=={{header|BBC BASIC}}==
==={{header|BASIC256}}===
<lang bbcbasic>REM >oldrussian
<syntaxhighlight lang="basic">arraybase 1
dim units = {"tochka", "liniya", "dyuim", "vershok", "piad", "fut", "arshin", "sazhen", "versta", "milia", "centimeter", "meter", "kilometer"}
# all expressed in centimeters
dim convs = {0.0254, 0.254, 2.54, 4.445, 17.78, 30.48, 71.12, 213.36, 10668, 74676, 1, 100, 10000}
 
do
cls
print
for i = 1 to units[?]
print rjust(string(i),2); " "; units[i]
next
print
do
input "Please choose a unit 1 to 13 : ", unit
until unit >= 1 and unit <= 13
print
do
input "Now enter a value in that unit : ", value
until value >= 0
print
print "The equivalent in the remaining units is : "
print
for i = 1 to units[?]
if i = unit then continue for
print " "; units[i], " : "; value * convs[unit] / convs[i]
next
print
do
input "Do another one y/n : ", yn
yn = lower(yn)
until yn = "y" or yn = "n"
until yn = "n"</syntaxhighlight>
{{out}}
<pre>Same as Run BASIC entry.</pre>
 
==={{header|BBC BASIC}}===
<syntaxhighlight lang="bbcbasic">REM >oldrussian
@% = &90E
PROColdrus(1, "meter")
Line 153 ⟶ 578:
NEXT
ENDIF
ENDPROC</langsyntaxhighlight>
{{out}}
<pre>1 meter =
Line 182 ⟶ 607:
2800 liniya
28000 tochka</pre>
 
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Dim units(1 To 13) As String = {"tochka", "liniya", "dyuim", "vershok", "piad", "fut", _
"arshin", "sazhen", "versta", "milia", _
"centimeter", "meter", "kilometer"}
 
' all expressed in centimeters
Dim convs(1 To 13) As Single = {0.0254, 0.254, 2.54, 4.445, 17.78, 30.48, _
71.12, 213.36, 10668, 74676, _
1, 100, 10000}
Dim unit As Integer
Dim value As Single
Dim yn As String
 
Do
Shell("cls")
Print
For i As Integer = 1 To 13
Print Using "##"; i;
Print " "; units(i)
Next
Print
Do
Input "Please choose a unit 1 to 13 : "; unit
Loop Until unit >= 1 AndAlso unit <= 13
Print
Do
Input "Now enter a value in that unit : "; value
Loop Until value >= 0
Print
Print "The equivalent in the remaining units is : "
Print
For i As Integer = 1 To 13
If i = unit Then Continue For
Print " "; units(i), " : "; value * convs(unit) / convs(i)
Next
Print
Do
Input "Do another one y/n : "; yn
yn = LCase(yn)
Loop Until yn = "y" OrElse yn = "n"
Loop Until yn = "n"
End</syntaxhighlight>
Sample input/output:
{{out}}
<pre>
 
1 tochka
2 liniya
3 dyuim
4 vershok
5 piad
6 fut
7 arshin
8 sazhen
9 versta
10 milia
11 centimeter
12 meter
13 kilometer
 
Please choose a unit 1 to 13 : ? 13
 
Now enter a value in that unit : ? 1
 
The equivalent in the remaining units is :
 
tochka : 393700.8
liniya : 39370.08
dyuim : 3937.008
vershok : 2249.719
piad : 562.4297
fut : 328.084
arshin : 140.6074
sazhen : 46.86914
versta : 0.9373828
milia : 0.1339118
centimeter : 10000
meter : 100
 
Do another one y/n : ? n
</pre>
 
==={{header|Gambas}}===
<syntaxhighlight lang="vbnet">Public Sub Main()
Dim units As String[] = ["tochka", "liniya", "dyuim", "vershok", "piad", "fut", "arshin", "sazhen", "versta", "milia", "centimeter", "meter", "kilometer"]
' all expressed in centimeters
Dim convs As Single[] = [0.254, 0.254, 2.54, 4.445, 17.78, 30.48, 71.12, 213.36, 10668, 74676, 1, 100, 10000]
Dim i, unit As Integer
Dim value As Single
Dim yn As String
Do
Shell("clear")
Print
For i = 1 To units.count
Print Format$(i, "##"); " "; units[i - 1]
Next
Print "\nPlease choose a unit 1 to 13 : "
Do
Input unit
Loop Until unit >= 1 And unit <= 13
Print "\nNow enter a value in that unit : "
Do
Input value
Loop Until value >= 0
Print "\nThe equivalent in the remaining units is : \n"
For i = 0 To units.count - 1
If i = unit - 1 Then Continue 'For
Print units[i]; Space$(10 - Len(units[i]));
Print " : "; value * convs[unit - 1] / convs[i]
Next
Print "\nDo another one y/n : "
Do
Input yn
yn = LCase(yn)
Loop Until yn = "y" Or yn = "n"
Loop Until yn = "n"
End</syntaxhighlight>
{{out}}
<pre>Similar as FreeBASIC entry.</pre>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">DIM units(1 TO 13) AS STRING
FOR i = LBOUND(units) TO UBOUND(units)
READ units(i)
NEXT i
DATA "tochka", "liniya", "dyuim", "vershok", "piad", "fut", "arshin", "sazhen", "versta", "milia", "centimeter", "meter", "kilometer"
 
' all expressed in centimeters
DIM convs(1 TO 13) AS SINGLE
FOR i = 1 TO 13
READ convs(i)
NEXT i
DATA 0.0254, 0.254, 2.54, 4.445, 17.78, 30.48, 71.12, 213.36, 10668, 74676, 1, 100, 10000
DIM unit AS INTEGER
DIM value AS SINGLE
DIM yn AS STRING
 
DO
CLS
PRINT
FOR i = 1 TO 13
PRINT USING "## "; i;
PRINT units(i)
NEXT i
PRINT
DO
INPUT "Please choose a unit 1 to 13 : ", unit
LOOP UNTIL unit >= 1 AND unit <= 13
PRINT
DO
INPUT "Now enter a value in that unit : ", value
LOOP UNTIL value >= 0
PRINT
PRINT "The equivalent in the remaining units is : "
PRINT
FOR i = 1 TO 13
IF i <> unit THEN PRINT " "; units(i), " : "; value * convs(unit) / convs(i)
NEXT i
PRINT
DO
INPUT "Do another one y/n : ", yn
yn = LCASE$(yn)
LOOP UNTIL yn = "y" OR yn = "n"
LOOP UNTIL yn = "n"</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">DIM units$(1 TO 13)
FOR i = LBOUND(units$) TO UBOUND(units$)
READ units$(i)
NEXT i
DATA "tochka", "liniya", "dyuim", "vershok", "piad", "fut", "arshin", "sazhen", "versta", "milia", "centimeter", "meter", "kilometer"
 
! all expressed in centimeters
DIM convs(1 TO 13)
FOR i = 1 TO 13
READ convs(i)
NEXT i
DATA 0.0254, 0.254, 2.54, 4.445, 17.78, 30.48, 71.12, 213.36, 10668, 74676, 1, 100, 10000
 
DO
CLEAR
PRINT
FOR i = 1 TO 13
PRINT USING "## ": i;
PRINT units$(i)
NEXT i
PRINT
DO
INPUT prompt "Please choose a unit 1 to 13 : ": unit
LOOP UNTIL unit >= 1 AND unit <= 13
PRINT
DO
INPUT prompt "Now enter a value! in that unit : ": value
LOOP UNTIL value >= 0
PRINT
PRINT "The equivalent in the remaining units is : "
PRINT
FOR i = 1 TO 13
IF i <> unit THEN PRINT " "; units$(i), " : "; value*convs(unit)/convs(i)
NEXT i
PRINT
DO
INPUT prompt "Do another one y/n : ": yn$
LET yn$ = LCASE$(yn$)
LOOP UNTIL yn$ = "y" OR yn$ = "n"
LOOP UNTIL yn$ = "n"
END</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "progname"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
 
DIM units$[14]
units$[1] = "tochka " : units$[2] = "liniya " : units$[3] = "dyuim "
units$[4] = "vershok " : units$[5] = "piad " : units$[6] = "fut "
units$[7] = "arshin " : units$[8] = "sazhen " : units$[9] = "versta "
units$[10] = "milia " : units$[11] = "centimeter" : units$[12] = "meter "
units$[13] = "kilometer "
 
' all expressed in centimeters
DIM convs![14]
convs![1] = 0.0254 : convs![2] = 0.254 : convs![3] = 2.54
convs![4] = 4.445 : convs![5] = 17.78 : convs![6] = 30.48
convs![7] = 71.12 : convs![8] = 213.36 : convs![9] = 10668
convs![10] = 74676 : convs![11] = 1 : convs![12] = 100 : convs![13] = 10000
 
DO
PRINT
FOR i = 1 TO 13
PRINT FORMAT$("##",i); " "; units$[i]
NEXT i
DO
unit = UBYTE(INLINE$("\nPlease choose a unit 1 to 13 : "))
LOOP UNTIL unit >= 1 AND unit <= 13
DO
value = USHORT(INLINE$("\nNow enter a value in that unit : "))
LOOP UNTIL value >= 0
 
PRINT
PRINT "The equivalent in the remaining units is : "
PRINT
FOR i = 1 TO 13
IF i <> unit THEN PRINT " "; units$[i], " : "; value * convs![unit] / convs![i]
NEXT i
DO
yn$ = LCASE$(INLINE$("\nDo another one y/n : "))
LOOP UNTIL (yn$ = "y") OR (yn$ = "n")
LOOP UNTIL yn$ = "n"
 
END FUNCTION
END PROGRAM</syntaxhighlight>
{{out}}
<pre>Similar as FreeBASIC entry.</pre>
 
==={{header|uBasic/4tH}}===
This program uses a command prompt. It will accept queries as long as the order ''"quantity, from unit, to unit"'' is preserved. '''EXIT''' will leave the program. Note all arithmetic is done in fixed point math, so some rounding errors are unavoidable.
<syntaxhighlight lang="basic">Do ' get in command loop
t := "" ' no token
n = Info ("nil") ' units are undefined
f = _Fmul ' first, a multiplication
o = Ask("> ") ' show the prompt
' strip trailing spaces
For x = Len (o) While Peek(o, Set(x, x-1)) = Ord(" ") : o = Clip(o, 1) : Next
 
Do While Len (o) ' if there is something left to parse
t = FUNC(_Parse (" ")) ' get the token
If Val (t) # Info ("nil") Then n = FUNC (_Ntof (Val (t)))
l = Name (t) ' is it a number, set it
If Line (l) Then n = FUNC (l (f, n)) : f = _Fdiv
Loop ' if it's a function, execute it
Until n = Info ("nil") ' display the result
Print Show (Str ("+?.####", FUNC(_Ftoi (n))));" ";Show (t)
Loop
 
End
 
_Parse ' parse string and get token
Param (1)
Local (3)
 
Do ' get only complete tokens
If Set(b@, Find(o, a@)) < 0 Then
c@ := o : o := "" ' last token, we're done
Else ' get the next token
c@ = Clip (o, Len(o) - b@) : o = Chop (o, b@+1)
EndIf
Until Len (c@) : Loop
 
Return (c@) ' return token
 
Rem 'arshin' = 0.7112, 'centimeter' = 0.01, 'diuym' = 0.0254,
Rem 'fut' = 0.3048, 'kilometer' = 1000.0, 'liniya' = 0.00254,
Rem 'meter' = 1.0, 'milia' = 7467.6, 'piad' = 0.1778,
Rem 'sazhen' = 2.1336, 'tochka' = 0.000254, 'vershok' = 0.04445,
Rem 'versta' = 1066.8
 
_arshin Param (2) : Return (FUNC(a@(b@, FUNC(_Itof (711200)))))
_centimeter Param (2) : Return (FUNC(a@(b@, FUNC(_Ntof (1)))))
_diuym Param (2) : Return (FUNC(a@(b@, FUNC(_Itof (25400)))))
_fut Param (2) : Return (FUNC(a@(b@, FUNC(_Itof (304800)))))
_kilometer Param (2) : Return (FUNC(a@(b@, FUNC(_Ntof (100000)))))
_liniya Param (2) : Return (FUNC(a@(b@, FUNC(_Itof (2540)))))
_meter Param (2) : Return (FUNC(a@(b@, FUNC(_Ntof (100)))))
_milia Param (2) : Return (FUNC(a@(b@, FUNC(_Ntof (746760)))))
_piad Param (2) : Return (FUNC(a@(b@, FUNC(_Itof (177800)))))
_sazhen Param (2) : Return (FUNC(a@(b@, FUNC(_Itof (2133600)))))
_tochka Param (2) : Return (FUNC(a@(b@, FUNC(_Itof (254)))))
_vershok Param (2) : Return (FUNC(a@(b@, FUNC(_Itof (44450)))))
_versta Param (2) : Return (FUNC(a@(b@, FUNC(_Ntof (106680)))))
_exit Param (2) : Return (Info ("nil"))
 
_Fmul Param (2) : Return ((a@*b@)/16384)
_Fdiv Param (2) : Return ((a@*16384)/b@)
_Ftoi Param (1) : Return ((10000*a@)/16384)
_Itof Param (1) : Return ((16384*a@)/10000)
_Ntof Param (1) : Return (a@*16384)
</syntaxhighlight>
{{Out}}
<pre>> convert 1 meter to fut
3.2808 fut
> convert 10 diuym to centimeter
25.3997 centimeter
> how much is 1 fut in diuym
12.0000 diuym
> 20 diuym in tochka
2000.7211 tochka
> 1 milia = versta
7.0000 versta
> exit
 
0 OK, 0:1014 </pre>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="basic">dim units$(14)
units$(1) = "tochka" : units$(2) = "liniya" : units$(3) = "dyuim"
units$(4) = "vershok" : units$(5) = "piad" : units$(6) = "fut"
units$(7) = "arshin" : units$(8) = "sazhen" : units$(9) = "versta"
units$(10) = "milia" : units$(11) = "centimeter" : units$(12) = "meter"
units$(13) = "kilometer"
 
// all expressed in centimeters
dim convs(14)
convs(1) = 0.0254 : convs(2) = 0.254 : convs(3) = 2.54
convs(4) = 4.445 : convs(5) = 17.78 : convs(6) = 30.48
convs(7) = 71.12 : convs(8) = 213.36 : convs(9) = 10668
convs(10) = 74676 : convs(11) = 1 : convs(12) = 100 : convs(13) = 10000
 
repeat
clear screen
print
for i = 1 to arraysize(units$(), 1) - 1
print i using ("##"), " ", units$(i)
next
print
repeat
input "Please choose a unit 1 to 13 : " unit
until unit >= 1 and unit <= 13
print
repeat
input "Now enter a value in that unit : " value
until value >= 0
print "\nThe equivalent in the remaining units is : \n"
for i = 1 to 13
if i = unit continue
print " ", units$(i), "\t : ", value * convs(unit) / convs(i)
next
print
repeat
input "Do another one y/n : " yn$
yn$ = lower$(yn$)
until yn$ = "y" or yn$ = "n"
until yn$ = "n"
end</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|C}}==
Accepts length and unit as input, prints out length in all other units. Usage printed on incorrect invocation.
<syntaxhighlight lang="c">
<lang C>
#include<string.h>
#include<stdlib.h>
Line 223 ⟶ 1,045:
return 0;
}
</syntaxhighlight>
</lang>
Output :
<pre>
Line 259 ⟶ 1,081:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <iostream>
#include <iomanip>
Line 321 ⟶ 1,143:
}
//-------------------------------------------------------------------------------------------
</syntaxhighlight>
</lang>
Output:
<pre>
Line 359 ⟶ 1,181:
=={{header|D}}==
{{trans|Raku}}
<langsyntaxhighlight lang="d">import std.stdio, std.string, std.algorithm, std.conv;
 
void main(in string[] args) {
Line 384 ⟶ 1,206:
foreach (immutable key; factor.keys.schwartzSort!(k => factor[k]))
writefln("%10s: %s", key, meters / factor[key]);
}</langsyntaxhighlight>
{{out}}
<pre>1 meter to:
Line 420 ⟶ 1,242:
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Old_Russian_measure_of_length;
 
Line 495 ⟶ 1,317:
readln(yn);
until yn.toLower = 'n';
end.</langsyntaxhighlight>
 
=={{header|EasyLang}}==
{{trans|Gambas}}
<syntaxhighlight>
units$[] = [ "tochka" "liniya" "dyuim" "vershok" "piad" "fut" "arshin" "sazhen" "versta" "milia" "centimeter" "meter" "kilometer" ]
convs[] = [ 0.254 0.254 2.54 4.445 17.78 30.48 71.12 213.36 10668 74676 1 100 10000 ]
for i to len units$[]
print i & ") " & units$[i]
.
print ""
write "Please choose a unit (1 to 13): "
repeat
unit = number input
until unit >= 1 and unit <= 13
.
print unit
write "Now enter a value in that unit: "
repeat
value = -1
value = number input
print value
until value >= 0
.
print value
print ""
print value & " " & units$[unit] & " are"
print ""
for i to len units$[]
if i <> unit
print value * convs[unit] / convs[i] & " " & units$[i]
.
.
</syntaxhighlight>
 
=={{header|Elena}}==
{{trans|Julia}}
ELENA 56.2x:
<langsyntaxhighlight lang="elena">import system'collections;
import system'routines;
import extensions;
Line 522 ⟶ 1,377:
{
if (program_arguments.Length != 3)
{ console.writeLine:("need two arguments - number then units"); AbortException.raise() };
real value := program_arguments[1].toReal();
Line 529 ⟶ 1,384:
{
console.printLine("only following units are supported:",
unit2mult.selectBy::(x=>x.Item1).asEnumerable());
AbortException.raise()
Line 536 ⟶ 1,391:
console.printLine(value," ",unit," to:");
 
unit2mult.forEach::(u,mlt)
{
console.printPaddingLeft(30, u, ":").printLine(value * unit2mult[unit] / mlt)
}
}</langsyntaxhighlight>
{{out}}
<pre>2.3 meter to:
Line 560 ⟶ 1,415:
=={{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.
<langsyntaxhighlight lang="factor">USING: formatting inverse io kernel math prettyprint quotations
sequences units.imperial units.si vocabs ;
IN: rosetta-code.units.russian
Line 591 ⟶ 1,446:
PRIVATE>
 
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 650 ⟶ 1,505:
 
=={{header|Fortran}}==
<langsyntaxhighlight lang="fortran">PROGRAM RUS
IMPLICIT NONE
REAL, PARAMETER:: E_m = 1.
Line 700 ⟶ 1,555:
WRITE (*, '(F20.3, " ", A)') RD_V / wert(J), nam(J)
END DO
END PROGRAM RUS</langsyntaxhighlight>
{{out}}
<pre>m mm km cm arshin fut piad vershok dyuim liniya tochka ladon lokot sazhen versta milya
Line 740 ⟶ 1,595:
10.000 arshin</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
Dim units(1 To 13) As String = {"tochka", "liniya", "dyuim", "vershok", "piad", "fut", _
"arshin", "sazhen", "versta", "milia", _
"centimeter", "meter", "kilometer"}
 
' all expressed in centimeters
Dim convs(1 To 13) As Single = {0.0254, 0.254, 2.54, 4.445, 17.78, 30.48, _
71.12, 213.36, 10668, 74676, _
1, 100, 10000}
Dim unit As Integer
Dim value As Single
Dim yn As String
 
Do
Shell("cls")
Print
For i As Integer = 1 To 13
Print Using "##"; i;
Print " "; units(i)
Next
Print
Do
Input "Please choose a unit 1 to 13 : "; unit
Loop Until unit >= 1 AndAlso unit <= 13
Print
Do
Input "Now enter a value in that unit : "; value
Loop Until value >= 0
Print
Print "The equivalent in the remaining units is : "
Print
For i As Integer = 1 To 13
If i = unit Then Continue For
Print " "; units(i), " : "; value * convs(unit) / convs(i)
Next
Print
Do
Input "Do another one y/n : "; yn
yn = LCase(yn)
Loop Until yn = "y" OrElse yn = "n"
Loop Until yn = "n"
End</lang>
Sample input/output:
{{out}}
<pre>
 
1 tochka
2 liniya
3 dyuim
4 vershok
5 piad
6 fut
7 arshin
8 sazhen
9 versta
10 milia
11 centimeter
12 meter
13 kilometer
 
Please choose a unit 1 to 13 : ? 13
 
Now enter a value in that unit : ? 1
 
The equivalent in the remaining units is :
 
tochka : 393700.8
liniya : 39370.08
dyuim : 3937.008
vershok : 2249.719
piad : 562.4297
fut : 328.084
arshin : 140.6074
sazhen : 46.86914
versta : 0.9373828
milia : 0.1339118
centimeter : 10000
meter : 100
 
Do another one y/n : ? n
</pre>
=={{header|Forth}}==
Tested with GForth.
<langsyntaxhighlight lang="forth">create units s" kilometer" 2, s" meter" 2, s" centimeter" 2, s" tochka" 2, s" liniya" 2, s" diuym" 2, s" vershok" 2, s" piad" 2, s" fut" 2, s" arshin" 2, s" sazhen" 2, s" versta" 2, s" milia" 2,
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 851 ⟶ 1,622:
1e s" meter" show
20e s" versta" show
10e s" milia" show</langsyntaxhighlight>
{{out}}
<pre>
Line 903 ⟶ 1,674:
 
 
</pre>
 
=={{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.
<syntaxhighlight lang="frink">arshin := (2 + 1/3) ft
vershok := 1/16 arshin
sazhen := 3 arshin
verst := 1500 arshin
versta := verst
 
do
{
valstr = input["Enter unit of measure: ", "1 arshin"]
val = eval[valstr]
if ! (val conforms length)
println["$valstr is not a unit of length."]
} until val conforms length
 
println["$valstr = "]
println[" " + (val -> "arshin")]
println[" " + (val -> "vershok")]
println[" " + (val -> "sazhen")]
println[" " + (val -> "verst")]
println[" " + (val -> "feet")]
println[" " + (val -> "meters")]
println[" " + (val -> "centimeters")]
println[" " + (val -> "kilometers")]</syntaxhighlight>
{{out}}
<pre>
Enter unit of measure: [1 arshin]
1 arshin =
1 arshin
16 vershok
1/3 (approx. 0.33333333333333333) sazhen
1/1500 (approx. 0.00066666666666666667) verst
7/3 (approx. 2.3333333333333333) feet
889/1250 (exactly 0.7112) meters
1778/25 (exactly 71.12) centimeters
889/1250000 (exactly 0.0007112) kilometers
</pre>
 
=={{header|Go}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 974 ⟶ 1,784:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,016 ⟶ 1,826:
=={{header|Haskell}}==
 
<langsyntaxhighlight Haskelllang="haskell">module Main where
 
import Text.Printf (printf)
Line 1,050 ⟶ 1,860:
(_) -> do
name <- getProgName
printf "Arguments were wrong - please use ./%s <number> <unit>\n" name</langsyntaxhighlight>
 
Output:
Line 1,101 ⟶ 1,911:
=={{header|J}}==
Translation of python.
<syntaxhighlight lang="j">
<lang J>
#!/usr/bin/ijconsole
NB. Use, linux.
UNIT2MULT=: |:_2 (; ".)&;/\;:'arshin 0.7112 centimeter 0.01 diuym 0.0254 fut 0.3048 kilometer 1000.0 liniya 0.00254 meter 1.0 milia 7467.6 piad 0.1778 sazhen 2.1336 tochka 0.000254 vershok 0.04445 versta 1066.8'
NB. $ /usr/local/j64-801/bin/jconsole j.ijs 8 meter
 
conv=: UNIT2MULT 1 : 0
UNIT2MULT =: /:~ _ ".&.>@:{:@:]`1:`]}"1<;._2@:(,&':');._2 'arshin:0.7112,centimeter:0.01,diuym:0.0254,fut:0.3048,kilometer:1000.0,liniya:0.00254,meter:1.0,milia:7467.6,piad:0.1778,sazhen:2.1336,tochka:0.000254,vershok:0.04445,versta:1066.8,'
if. 2 ~: # y do. 'ERROR. Need two arguments - number then units'
 
exit 3 : 0 :: 1: a: -.~ _3 {. ARGV
if. 3 ~: # y do. smoutput 'ERROR. Need two arguments - number then units'
else.
'VALUE UNIT'=:. (;~ _ &". _2 {:: )&;~/y
if. _ = | VALUE do. smoutput 'ERROR. First argument must be a (float) number'
else.
UNITtry. =: {: y
UNITS scale=:. 0&({"1::~ UNIT2MULTi.&(<UNIT))~/m
((":;:inv y),' to:'),":({.m),.({:m)*L:0 VALUE%scale
if. UNIT-.@:e.UNITS do. smoutput 'ERROR. Only know the following units: ' , deb , ,&' '&> UNITS
elsecatch.
'ERROR. Only know the following units: ',;:inv{.m
smoutput deb(,,&' '&>_2{.y),'to:'
smoutput UNITS ,. (VALUE * (< 1 ,~ UNITS i. UNIT) {:: UNIT2MULT) %&.> {:"1 UNIT2MULT
end.
end.
end.
)
 
</lang>
NB. for use from os command line only:
exit echo conv }.ARGV</syntaxhighlight>
 
If this were named <code>ormol</code>
 
<pre>
$ /usr/local/j64-801/bin/jconsole j.ijsormol 8 meter
8 meter to:
┌──────────┬──────────┐
Line 1,154 ⟶ 1,966:
│versta │0.00749906│
└──────────┴──────────┘
$
</pre>
 
The same display can be achieved from the J comand line using the expression <code>conv ;:'8 meter'</code>. However, this is only possible if the <code>exit</code> line is omitted, since the exit command would exit the J session. If dual use was desired, the code could be packaged as a shell script (see the [[Native_shebang#J|native shebang]] task) and the exit line could be made conditional on the name of that shell script (which would appear as the first element in <code>ARGV</code>).
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">public class OldRussianMeasures {
 
final static String[] keys = {"tochka", "liniya", "centimeter", "diuym",
Line 1,190 ⟶ 2,003:
return Double.NaN;
}
}</langsyntaxhighlight>
 
<pre>1 meter to:
Line 1,223 ⟶ 2,036:
versta: 7,00000
milia: 1,00000</pre>
 
=={{header|jq}}==
{{works with|jq}}
<syntaxhighlight lang="jq">
def lpad($len): tostring | ($len - length) as $l | (" " * $l) + .;
 
def Units: {
"arshin" : 0.7112,
"centimeter": 0.01,
"diuym" : 0.0254,
"fut" : 0.3048,
"kilometer" : 1000.0,
"liniya" : 0.00254,
"meter" : 1.0,
"milia" : 7467.6,
"piad" : 0.1778,
"sazhen" : 2.1336,
"tochka" : 0.000254,
"vershok" : 0.04445,
"versta" : 1066.8
};
 
def cyrillic: {
"arshin" : "арши́н",
"centimeter": "сантиметр",
"diuym" : "дюйм",
"fut" : "фут",
"kilometer" : "километр",
"liniya" : "ли́ния",
"meter" : "метр",
"milia" : "ми́ля",
"piad" : "пядь",
"sazhen" : "саже́нь",
"tochka" : "то́чка",
"vershok" : "вершо́к",
"versta" : "верста́"
};
 
def request:
def explain: "number and unit of measurement expected vs \(.)" | error;
def check:
$ARGS.positional
| if length >= 2
then (try (.[0] | tonumber) catch false) as $n
| (.[1] | sub("s$";"")) as $u
| if $n and Units[$u] then [$n, $u]
else explain
end
else explain
end;
check ;
 
# Input: a number
# Delete unhelpful digits
def humanize($n):
tostring
| ( capture("^(?<head>[0-9]*)[.](?<zeros>0*)(?<tail>[0-9]*)$")
| (.head|length) as $hl
| if $hl > $n then .head + "."
elif .head | (. == "" or . == "0")
then .head + "." + .zeros + .tail[:1 + $n - $hl]
else .head + "." + (.zeros + .tail)[:1 + $n - $hl]
end ) // .;
 
def display:
Units
| . as $Units
| request as [$n, $unit]
| "\($n) \($unit)\(if $n == 1 then "" else "s" end) ::",
(to_entries[]
| "\(.key|lpad(10)) : \(($n * $Units[$unit] / .value) | humanize(5)) \(cyrillic[.key])"),
"" ;
 
display
</syntaxhighlight>
'''Invocation example'''
<pre>
jq -nr -f old-russian-measure-of-length.jq --args 2.3 meter
</pre>
{{output}}
<pre>
2.3 meters ::
arshin : 3.23397 арши́н
centimeter : 229.999 сантиметр
diuym : 90.5511 дюйм
fut : 7.54593 фут
kilometer : 0.0023 километр
liniya : 905.511 ли́ния
meter : 2.3 метр
milia : 0.00030799 ми́ля
piad : 12.9358 пядь
sazhen : 1.07799 саже́нь
tochka : 9055.11 то́чка
vershok : 51.7435 вершо́к
versta : 0.0021559 верста́
</pre>
 
=={{header|Julia}}==
Line 1,228 ⟶ 2,137:
{{trans|Python}}
 
<langsyntaxhighlight lang="julia">using DataStructures
 
const unit2mult = Dict(
Line 1,250 ⟶ 2,159:
for (unt, mlt) in sort(unit2mult)
@printf(" %10s: %g\n", unt, value * unit2mult[unit] / mlt)
end</langsyntaxhighlight>
 
{{out}}
Line 1,271 ⟶ 2,180:
=={{header|Kotlin}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="scala">// version 1.0.6
 
/* clears console on Windows 10 */
Line 1,315 ⟶ 2,224:
}
while (yn == "y")
}</langsyntaxhighlight>
Sample input/output
{{out}}
Line 1,354 ⟶ 2,263:
Do another one y/n : n
</pre>
=={{header|M2000 Interpreter}}==
 
<syntaxhighlight lang="m2000 interpreter">
module OldRusianMeasureOfLength {
unit2mult=list:="arshin" := 0.7112, "centimeter" := 0.01, "diuym" := 0.0254, "fut" := 0.3048, "kilometer" := 1000.0, "liniya" := 0.00254, "meter" := 1.0, "milia" := 7467.6, "piad" := 0.1778, "sazhen" := 2.1336, "tochka":= 0.000254, "vershok" := 0.04445, "versta" := 1066.8
k=each(unit2mult)
menu // empty menu list
menu + "(exit)"
while k
menu + eval$(k!)
end while
double v
do
Print "Value, Unit";
input ":", v;
print " ";
menu !
if menu>0 then
print menu$(menu)
if menu$(menu)="(exit)" then exit
Print v;" ";menu$(menu);" to:"
v*=unit2mult(menu$(menu))
k=each(unit2mult)
while k
if eval$(k!)=menu$(menu) then continue
print format$("{0:-12}: {1}",eval$(k!), round(v/eval(k),9))
end while
else
exit
end if
always
}
OldRusianMeasureOfLength
</syntaxhighlight>
{{out}}
<pre>
Value, Unit: 1 meter
1 meter to:
arshin: 1.406074241
centimeter: 100
diuym: 39.37007874
fut: 3.280839895
kilometer: 0.001
liniya: 393.700787402
meter: 1
milia: 0.000133912
piad: 5.624296963
sazhen: 0.468691414
tochka: 3937.007874016
vershok: 22.497187852
versta: 0.000937383
</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
These units are built-in to Wolfram Language:
<syntaxhighlight lang="mathematica">ClearAll[units, ConvertRussianQuantities]
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"]]</syntaxhighlight>
{{out}}
<pre>{1/16 Russian arshins, 1/48 Russian sazhens, 1/24000 Russian versts, 889/200 cm, 889/20000 m, 889/20000000 km}
{16 Russian vershoks, 1/3 Russian sazhens, 1/1500 Russian versts, 1778/25 cm, 889/1250 m, 889/1250000 km}</pre>
 
 
=={{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</langsyntaxhighlight>
 
''Instruction:''
Line 1,369 ⟶ 2,342:
100 m = 2249,2971 vershoks = 140,58107 arshins = 46,860366 sazhens = 0,093790712 versts;
3 vershoks = 13,3375 cm; 2 sazhens = 96 vershoks = 6 arshins = 4,268 m; 1 verst = 1,067 km.
 
=={{header|Nim}}==
{{trans|Python}}
<syntaxhighlight lang="nim">import os, strutils, sequtils, tables
 
const Unit2Mult = {"arshin": 0.7112, "centimeter": 0.01, "diuym": 0.0254,
"fut": 0.3048, "kilometer": 1000.0, "liniya": 0.00254,
"meter": 1.0, "milia": 7467.6, "piad": 0.1778,
"sazhen": 2.1336, "tochka": 0.000254, "vershok": 0.04445,
"versta": 1066.8}.toOrderedTable
 
if paramCount() != 2:
raise newException(ValueError, "need two arguments: number then units.")
 
let value = try: parseFloat(paramStr(1))
except ValueError:
raise newException(ValueError, "first argument must be a (float) number.")
 
let unit = paramStr(2)
if unit notin Unit2Mult:
raise newException(ValueError,
"only know the following units: " & toSeq(Unit2Mult.keys).join(" "))
 
echo value, ' ', unit, " to:"
for (key, mult) in Unit2Mult.pairs:
echo key.align(10), ": ", formatFloat(value * Unit2Mult[unit] / mult, ffDecimal, 5)</syntaxhighlight>
 
{{out}}
Output for command: ./convert 1 meter
<pre>1.0 meter to:
arshin: 1.40607
centimeter: 100.00000
diuym: 39.37008
fut: 3.28084
kilometer: 0.00100
liniya: 393.70079
meter: 1.00000
milia: 0.00013
piad: 5.62430
sazhen: 0.46869
tochka: 3937.00787
vershok: 22.49719
versta: 0.00094</pre>
 
=={{header|Perl}}==
Displaying converted values to 5 significant digits.
{{trans|Raku}}
<langsyntaxhighlight lang="perl">sub convert {
my($magnitude, $unit) = @_;
my %factor = (
Line 1,414 ⟶ 2,430:
 
print convert(1,'meter'), "\n\n";
print convert(1,'milia'), "\n";</langsyntaxhighlight>
{{out}}
<pre> tochka: 3937.0
Line 1,444 ⟶ 2,460:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>constant units = {{"-- metric ---",0},
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
{"kilometer",1000},
<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>
{"km","kilometer"},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"kilometer"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">},</span>
{"meter",1},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"km"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"kilometer"</span><span style="color: #0000FF;">},</span>
{"m","meter"},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"meter"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">},</span>
{"centimeter",0.01},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"m"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"meter"</span><span style="color: #0000FF;">},</span>
{"cm","centimeter"},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"centimeter"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.01</span><span style="color: #0000FF;">},</span>
{" old russian ",0},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"cm"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"centimeter"</span><span style="color: #0000FF;">},</span>
{"tochka",0.000254},
<span style="color: #0000FF;">{</span><span style="color: #008000;">" old russian "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">},</span>
{"liniya",0.00254},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"tochka"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.000254</span><span style="color: #0000FF;">},</span>
{"diuym",0.0254},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"liniya"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.00254</span><span style="color: #0000FF;">},</span>
{"vershok",0.04445},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"diuym"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.0254</span><span style="color: #0000FF;">},</span>
{"piad",0.1778},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"vershok"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.04445</span><span style="color: #0000FF;">},</span>
{"fut",0.3048},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"piad"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.1778</span><span style="color: #0000FF;">},</span>
{"arshin",0.7112},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"fut"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.3048</span><span style="color: #0000FF;">},</span>
{"sazhen",2.1336},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"arshin"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.7112</span><span style="color: #0000FF;">},</span>
{"versta",1066.8},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"sazhen"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2.1336</span><span style="color: #0000FF;">},</span>
{"milia",7467.6}},
<span style="color: #0000FF;">{</span><span style="color: #008000;">"versta"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1066.8</span><span style="color: #0000FF;">},</span>
{names,facts} = columnize(units)
<span style="color: #0000FF;">{</span><span style="color: #008000;">"milia"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7467.6</span><span style="color: #0000FF;">}},</span>
 
<span style="color: #0000FF;">{</span><span style="color: #000000;">names</span><span style="color: #0000FF;">,</span><span style="color: #000000;">facts</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">(</span><span style="color: #000000;">units</span><span style="color: #0000FF;">)</span>
function strim(atom v)
string res = sprintf("%,f",v)
<span style="color: #008080;">function</span> <span style="color: #000000;">strim</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">v</span><span style="color: #0000FF;">)</span>
integer l = length(res)
<span style="color: #004080;">string</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%,f"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">v</span><span style="color: #0000FF;">)</span>
while l do
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span>
integer c = res[l]
<span style="color: #008080;">while</span> <span style="color: #000000;">l</span> <span style="color: #008080;">do</span>
if c!='0' then
<span style="color: #004080;">integer</span> <span style="color: #000000;">c</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">l</span><span style="color: #0000FF;">]</span>
l -= 1+(c='.')
<span style="color: #008080;">if</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">!=</span><span style="color: #008000;">'0'</span> <span style="color: #008080;">then</span>
exit
<span style="color: #000000;">l</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">+(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #008000;">'.'</span><span style="color: #0000FF;">)</span>
end if
<span style="color: #008080;">exit</span>
l -= 1
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end while
<span style="color: #000000;">l</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
res = res[1..l+1]
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
return res
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">l</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
end function
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
while true do
string input = prompt_string("\nEnter length & measure or CR to exit:")
<span style="color: #000080;font-style:italic;">-- Obviously, uncomment these lines for a prompt (not under p2js)
if input="" then exit end if
--while true do
input = lower(trim(input))
-- string input = prompt_string("\nEnter length & measure or CR to exit:")
string fmt = iff(find(' ',input)?"%f %s":"%f%s")
-- if input="" then exit end if
sequence r = scanf(input,fmt)
-- input = lower(trim(input))</span>
if length(r)!=1 then
<span style="color: #004080;">string</span> <span style="color: #000000;">input</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"7.4676 km"</span>
printf(1,"enter eg 1km or 1 kilometer\n")
<span style="color: #004080;">string</span> <span style="color: #000000;">fmt</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #008000;">' '</span><span style="color: #0000FF;">,</span><span style="color: #000000;">input</span><span style="color: #0000FF;">)?</span><span style="color: #008000;">"%f %s"</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"%f%s"</span><span style="color: #0000FF;">)</span>
else
<span style="color: #004080;">sequence</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">scanf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">input</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">)</span>
{atom v, string name} = r[1]
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
integer k = find(name,names)
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"enter eg 1km or 1 kilometer\n"</span><span style="color: #0000FF;">)</span>
if k=0 or facts[k]=0 then
<span style="color: #008080;">else</span>
printf(1,"unrecognised unit: %s\n",{name})
<span style="color: #0000FF;">{</span><span style="color: #004080;">atom</span> <span style="color: #000000;">v</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">name</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
else
<span style="color: #004080;">integer</span> <span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">name</span><span style="color: #0000FF;">,</span><span style="color: #000000;">names</span><span style="color: #0000FF;">)</span>
if string(facts[k]) then
<span style="color: #008080;">if</span> <span style="color: #000000;">k</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">or</span> <span style="color: #000000;">facts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
-- abbreviation, eg cm->centimeter
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"unrecognised unit: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">name</span><span style="color: #0000FF;">})</span>
k = find(facts[k],names)
<span style="color: end if#008080;">else</span>
<span style="color: #008080;">if</span> <span style="color: #004080;">string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">facts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">then</span>
for i=1 to length(names) do
<span style="color: #000080;font-style:italic;">-- abbreviation, eg cm-&gt;centimeter</span>
object f = facts[i]
<span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">facts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">],</span><span style="color: #000000;">names</span><span style="color: #0000FF;">)</span>
if f=0 then -- header
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
printf(1,"--------------%s--------------\n",{names[i]})
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">names</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
elsif atom(facts[i]) then -- not abbrev
<span style="color: #004080;">object</span> <span style="color: #000000;">f</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">facts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
printf(1,"%20s %s\n",{strim(v*facts[k]/facts[i]),names[i]})
<span style="color: #008080;">if</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- header</span>
end if
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"--------------%s--------------\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">names</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]})</span>
end for
<span style="color: #008080;">elsif</span> <span style="color: #004080;">atom</span><span style="color: #0000FF;">(</span><span style="color: #000000;">facts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- not abbrev</span>
end if
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%20s %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">strim</span><span style="color: #0000FF;">(</span><span style="color: #000000;">v</span><span style="color: #0000FF;">*</span><span style="color: #000000;">facts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">]/</span><span style="color: #000000;">facts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]),</span><span style="color: #000000;">names</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]})</span>
end if
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end while</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000080;font-style:italic;">--end while</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 1,534 ⟶ 2,555:
:<code>commandname <value> <unit></code>
 
<langsyntaxhighlight lang="python">from sys import argv
unit2mult = {"arshin": 0.7112, "centimeter": 0.01, "diuym": 0.0254,
Line 1,555 ⟶ 2,576:
print("%g %s to:" % (value, unit))
for unt, mlt in sorted(unit2mult.items()):
print(' %10s: %g' % (unt, value * unit2mult[unit] / mlt))</langsyntaxhighlight>
 
{{out}}
Line 1,606 ⟶ 2,627:
=={{header|Racket}}==
Follows the Raku solution, produces similar output.
<langsyntaxhighlight lang="racket">
#lang racket
 
Line 1,634 ⟶ 2,655:
(show 'meter)
(show 'milia)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 1,641 ⟶ 2,662:
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" perl6line>convert(1, 'meter');
 
say '*' x 40, "\n";
Line 1,671 ⟶ 2,692:
for %factor.keys.sort:{ +%factor{$_} }
}
</syntaxhighlight>
</lang>
 
<pre>
Line 1,715 ⟶ 2,736:
::* &nbsp; uses the correct length unit names when not plural
::* &nbsp; columnarized the output &nbsp; (instead of a horizontal stream).
<langsyntaxhighlight lang="rexx">/*REXX program converts a metric or old Russian length to various other lengths. */
numeric digits 200 /*lots of digits. */
/*──translation───*/
Line 1,845 ⟶ 2,866:
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</langsyntaxhighlight>
This REXX program makes use of &nbsp; '''LINESIZE''' &nbsp; REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console).
 
Line 1,906 ⟶ 2,927:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Old Russian measure of length
 
Line 1,947 ⟶ 2,968:
end
end
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,981 ⟶ 3,002:
centimeter : 10000
meter : 100
</pre>
 
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
≪ { "arshin" 0.7112 "centimeter" 0.01 "diuym" 0.0254 "fut" 0.3048 "kilometer" 1000 "liniya" 0.00254 "meter" 1
"milia" 7467.6 "piad" 0.1778 "sazhen" 2.1336 "tochka" 0.000254 "vershok" 0.04445 "versta" 1066.8 }
→ value unit table
≪ '''IF''' table unit POS
'''THEN'''
LAST 1 + table SWAP GET value * → meters
≪ 1 table SIZE '''FOR''' j
meters table j 1 + GET / →STR " " + table j GET + "s" +
2 '''STEP'''
'''ELSE''' value unit ": unknown unit" +
'''END'''
≫ ≫
'OLDRU' STO
 
3.14 "fut" OLDRU
{{out}}
<pre>
13: "1.34571428571 arshins"
12: "95.7072 centimeters"
11: "37.68 diuyms""37.68 diuyms"
10: "3.14 futs"
9: "0.000957072 kilometers"
8: "376.8 liniyas"
7: "0.957072 meters"
6: "1.28163265306E-04 milias"
5: "5.38285714286 piads"
4: "0.448571428571 sazhens"
3: "3768 tochkas"
2: "21.5314285714 vershoks"
1: "8.97142857143E-04 verstas"
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">module Distances
 
RATIOS =
{arshin: 0.7112, centimeter: 0.01, diuym: 0.0254,
fut: 0.3048, kilometer: 1000.0, liniya: 0.00254,
meter: 1.0, milia: 7467.6, piad: 0.1778,
sazhen: 2.1336, tochka: 0.000254, vershok: 0.04445,
versta: 1066.8}
 
def self.method_missing(meth, arg)
from, to = meth.to_s.split("2").map(&:to_sym)
raise NoMethodError, meth if ([from,to]-RATIOS.keys).size > 0
RATIOS[from] * arg / RATIOS[to]
end
 
def self.print_others(name, num)
puts "#{num} #{name} ="
RATIOS.except(name.to_sym).each {|k,v| puts "#{ (1.0 / v*num)} #{k}" }
end
end
 
Distances.print_others("meter", 2)
puts
p Distances.meter2centimeter(3)
p Distances.arshin2meter(1)
p Distances.versta2kilometer(20) # en Hoeperdepoep zat op de stoep
# 13*13 = 169 methods supported, but not:
p Distances.mile2piad(1)
</syntaxhighlight>
{{out}}
<pre>2 meter =
2.8121484814398197 arshin
200.0 centimeter
78.74015748031496 diuym
6.561679790026246 fut
0.002 kilometer
787.4015748031495 liniya
0.00026782366489903046 milia
11.248593925759279 piad
0.9373828271466067 sazhen
7874.0157480314965 tochka
44.994375703037115 vershok
0.0018747656542932134 versta
 
300.0
0.7112
21.336
distances.rb:12:in `method_missing': mile2piad (NoMethodError)
from distances.rb:22:in `<main>'
</pre>
 
Line 1,987 ⟶ 3,094:
:<code>commandname <value> <unit></code>
 
<langsyntaxhighlight lang="rust">use std::env;
use std::process;
use std::collections::HashMap;
Line 2,024 ⟶ 3,131:
 
}
</syntaxhighlight>
</lang>
<pre>
$ ./oldrus test
Line 2,063 ⟶ 3,170:
 
=={{header|Scala}}==
<langsyntaxhighlight Scalalang="scala">import scala.collection.immutable.HashMap
 
object OldRussianLengths extends App {
Line 2,084 ⟶ 3,191:
} else println("Please provide a number and unit on the command line.")
 
}</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">func convert (magnitude, unit) {
var factor = Hash(
tochka => 0.000254,
Line 2,115 ⟶ 3,222:
convert(1, 'meter')
say('')
convert(1, 'milia')</langsyntaxhighlight>
{{out}}
<pre>1 meter to:
Line 2,151 ⟶ 3,258:
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">
<lang Tcl>
package require units
 
Line 2,190 ⟶ 3,297:
add_russian_units
demo
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,227 ⟶ 3,334:
One nice side effect of this implementation is that units can work with more complex dimensions:
 
<syntaxhighlight lang="tcl">
<lang Tcl>
% units::convert "1 piad^2" "hectare"
3.1612805858160454e-6
% units::convert "100 km/h" "versta/minute"
1.562305
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
Line 2,238 ⟶ 3,345:
{{libheader|Wren-fmt}}
{{libheader|Wren-str}}
<langsyntaxhighlight ecmascriptlang="wren">import "io" for Stdin, Stdout
import "./fmt" for Fmt
import "./str" for Str
 
var units = [
Line 2,291 ⟶ 3,398:
if (yn == "n") break
System.print()
}</langsyntaxhighlight>
 
{{out}}
Line 2,327 ⟶ 3,434:
centimeter : 10000.0
meter : 100.0
 
Do another one y/n : n
</pre>
 
=={{header|XPL0}}==
{{trans|Wren}}
<syntaxhighlight lang "XPL0">int Units, Unit, I, YN;
real Convs, Value;
 
[Units:= ["tochka", "liniya", "dyuim", "vershok", "piad", "fut",
"arshin", "sazhen", "versta", "milia",
"centimeter", "meter", "kilometer"];
 
Convs:= [0.0254, 0.254, 2.54, 4.445, 17.78, 30.48,
71.12, 213.36, 10668., 74676.,
1., 100., 10000.];
 
loop [for I:= 0 to 13-1 do
[if I+1 < 10 then ChOut(0, ^ ); IntOut(0, I+1);
ChOut(0, ^ ); Text(0, Units(I)); CrLf(0);
];
CrLf(0);
loop [Text(0, "Please choose a unit 1 to 13 : ");
OpenI(0);
Unit:= IntIn(0);
if Unit >= 1 and Unit <= 13 then quit;
];
Unit:= Unit-1;
loop [Text(0, "Now enter a value in that unit : ");
OpenI(0);
Value:= RlIn(0);
if Value >= 1. then quit;
];
Text(0, "^m^jThe equivalent in the remaining units is:^m^j^m^j");
Format(7, 8);
for I:= 0 to 13-1 do
[if I # Unit then
[RlOut(0, Value*Convs(Unit)/Convs(I));
Text(0, " : "); Text(0, Units(I)); CrLf(0);
];
];
CrLf(0);
YN:= ^ ;
while YN # ^y and YN # ^n do
[Text(0, "Do another one y/n : ");
OpenI(0);
YN:= ChIn(0) or $20;
];
if YN = ^n then quit;
CrLf(0);
];
]</syntaxhighlight>
{{out}}
<pre>
1 tochka
2 liniya
3 dyuim
4 vershok
5 piad
6 fut
7 arshin
8 sazhen
9 versta
10 milia
11 centimeter
12 meter
13 kilometer
 
Please choose a unit 1 to 13 : 13
Now enter a value in that unit : 1
 
The equivalent in the remaining units is:
 
393700.78740157 : tochka
39370.07874016 : liniya
3937.00787402 : dyuim
2249.71878515 : vershok
562.42969629 : piad
328.08398950 : fut
140.60742407 : arshin
46.86914136 : sazhen
0.93738283 : versta
0.13391183 : milia
10000.00000000 : centimeter
100.00000000 : meter
 
Do another one y/n : n
Anonymous user