Old Russian measure of length: Difference between revisions

m
(Frink)
imported>Arakov
 
(21 intermediate revisions by 14 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 62:
=={{header|Action!}}==
{{libheader|Action! Real Math}}
<langsyntaxhighlight Actionlang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
DEFINE PTR="CARD"
Line 140:
PrintResult(value,unit)
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Old_Russian_measure_of_length.png Screenshot from Atari 8-bit computer]
Line 167:
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>
 
Line 172 ⟶ 279:
===Vanilla===
 
<langsyntaxhighlight lang="applescript">-- General purpose linear measurement converter.
on convertLinear(inputNumber, inputUnitRecord, outputUnitRecord)
set {inputType, outputType} to {inputUnitRecord's type, outputUnitRecord's type}
Line 248 ⟶ 355:
end demo
 
return demo()</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight 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"</langsyntaxhighlight>
 
===AppleScriptObjC===
 
<langsyntaxhighlight lang="applescript">use AppleScript version "2.5" -- macOS 10.12 (Sierra) or later. Not 10.11 (El Capitan).
use framework "Foundation"
use scripting additions
Line 333 ⟶ 440:
end demo
 
return demo()</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight 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"</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f OLD_RUSSIAN_MEASURE_OF_LENGTH.AWK
BEGIN {
Line 373 ⟶ 480:
printf("error: invalid measure; choose from: %s\n\n",units)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 408 ⟶ 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 434 ⟶ 578:
NEXT
ENDIF
ENDPROC</langsyntaxhighlight>
{{out}}
<pre>1 meter =
Line 463 ⟶ 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 504 ⟶ 1,045:
return 0;
}
</syntaxhighlight>
</lang>
Output :
<pre>
Line 540 ⟶ 1,081:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <iostream>
#include <iomanip>
Line 602 ⟶ 1,143:
}
//-------------------------------------------------------------------------------------------
</syntaxhighlight>
</lang>
Output:
<pre>
Line 640 ⟶ 1,181:
=={{header|D}}==
{{trans|Raku}}
<langsyntaxhighlight lang="d">import std.stdio, std.string, std.algorithm, std.conv;
 
void main(in string[] args) {
Line 665 ⟶ 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 701 ⟶ 1,242:
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Old_Russian_measure_of_length;
 
Line 776 ⟶ 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 803 ⟶ 1,377:
{
if (program_arguments.Length != 3)
{ console.writeLine:("need two arguments - number then units"); AbortException.raise() };
real value := program_arguments[1].toReal();
Line 810 ⟶ 1,384:
{
console.printLine("only following units are supported:",
unit2mult.selectBy::(x=>x.Item1).asEnumerable());
AbortException.raise()
Line 817 ⟶ 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 841 ⟶ 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 872 ⟶ 1,446:
PRIVATE>
 
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 931 ⟶ 1,505:
 
=={{header|Fortran}}==
<langsyntaxhighlight lang="fortran">PROGRAM RUS
IMPLICIT NONE
REAL, PARAMETER:: E_m = 1.
Line 981 ⟶ 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 1,021 ⟶ 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 1,132 ⟶ 1,622:
1e s" meter" show
20e s" versta" show
10e s" milia" show</langsyntaxhighlight>
{{out}}
<pre>
Line 1,188 ⟶ 1,678:
=={{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.
<langsyntaxhighlight lang="frink">arshin := (2 + 1/3) ft
vershok := 1/16 arshin
sazhen := 3 arshin
Line 1,210 ⟶ 1,700:
println[" " + (val -> "meters")]
println[" " + (val -> "centimeters")]
println[" " + (val -> "kilometers")]</langsyntaxhighlight>
{{out}}
<pre>
Line 1,227 ⟶ 1,717:
=={{header|Go}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,294 ⟶ 1,784:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,336 ⟶ 1,826:
=={{header|Haskell}}==
 
<langsyntaxhighlight Haskelllang="haskell">module Main where
 
import Text.Printf (printf)
Line 1,370 ⟶ 1,860:
(_) -> do
name <- getProgName
printf "Arguments were wrong - please use ./%s <number> <unit>\n" name</langsyntaxhighlight>
 
Output:
Line 1,421 ⟶ 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,474 ⟶ 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,510 ⟶ 2,003:
return Double.NaN;
}
}</langsyntaxhighlight>
 
<pre>1 meter to:
Line 1,543 ⟶ 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,548 ⟶ 2,137:
{{trans|Python}}
 
<langsyntaxhighlight lang="julia">using DataStructures
 
const unit2mult = Dict(
Line 1,570 ⟶ 2,159:
for (unt, mlt) in sort(unit2mult)
@printf(" %10s: %g\n", unt, value * unit2mult[unit] / mlt)
end</langsyntaxhighlight>
 
{{out}}
Line 1,591 ⟶ 2,180:
=={{header|Kotlin}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="scala">// version 1.0.6
 
/* clears console on Windows 10 */
Line 1,635 ⟶ 2,224:
}
while (yn == "y")
}</langsyntaxhighlight>
Sample input/output
{{out}}
Line 1,673 ⟶ 2,262:
 
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:
<langsyntaxhighlight Mathematicalang="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"]]</langsyntaxhighlight>
{{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 ⟶ 2,329:
 
=={{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,704 ⟶ 2,345:
=={{header|Nim}}==
{{trans|Python}}
<langsyntaxhighlight Nimlang="nim">import os, strutils, sequtils, tables
 
const Unit2Mult = {"arshin": 0.7112, "centimeter": 0.01, "diuym": 0.0254,
Line 1,726 ⟶ 2,367:
echo value, ' ', unit, " to:"
for (key, mult) in Unit2Mult.pairs:
echo key.align(10), ": ", formatFloat(value * Unit2Mult[unit] / mult, ffDecimal, 5)</langsyntaxhighlight>
 
{{out}}
Line 1,748 ⟶ 2,389:
Displaying converted values to 5 significant digits.
{{trans|Raku}}
<langsyntaxhighlight lang="perl">sub convert {
my($magnitude, $unit) = @_;
my %factor = (
Line 1,789 ⟶ 2,430:
 
print convert(1,'meter'), "\n\n";
print convert(1,'milia'), "\n";</langsyntaxhighlight>
{{out}}
<pre> tochka: 3937.0
Line 1,819 ⟶ 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,909 ⟶ 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,930 ⟶ 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,981 ⟶ 2,627:
=={{header|Racket}}==
Follows the Raku solution, produces similar output.
<langsyntaxhighlight lang="racket">
#lang racket
 
Line 2,009 ⟶ 2,655:
(show 'meter)
(show 'milia)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 2,016 ⟶ 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 2,046 ⟶ 2,692:
for %factor.keys.sort:{ +%factor{$_} }
}
</syntaxhighlight>
</lang>
 
<pre>
Line 2,090 ⟶ 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 2,220 ⟶ 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 2,281 ⟶ 2,927:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Old Russian measure of length
 
Line 2,322 ⟶ 2,968:
end
end
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,358 ⟶ 3,004:
</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}}==
<langsyntaxhighlight lang="ruby">module Distances
 
RATIOS =
Line 2,387 ⟶ 3,067:
# 13*13 = 169 methods supported, but not:
p Distances.mile2piad(1)
</syntaxhighlight>
</lang>
{{out}}
<pre>2 meter =
Line 2,414 ⟶ 3,094:
:<code>commandname <value> <unit></code>
 
<langsyntaxhighlight lang="rust">use std::env;
use std::process;
use std::collections::HashMap;
Line 2,451 ⟶ 3,131:
 
}
</syntaxhighlight>
</lang>
<pre>
$ ./oldrus test
Line 2,490 ⟶ 3,170:
 
=={{header|Scala}}==
<langsyntaxhighlight Scalalang="scala">import scala.collection.immutable.HashMap
 
object OldRussianLengths extends App {
Line 2,511 ⟶ 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,542 ⟶ 3,222:
convert(1, 'meter')
say('')
convert(1, 'milia')</langsyntaxhighlight>
{{out}}
<pre>1 meter to:
Line 2,578 ⟶ 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,617 ⟶ 3,297:
add_russian_units
demo
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,654 ⟶ 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,665 ⟶ 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,718 ⟶ 3,398:
if (yn == "n") break
System.print()
}</langsyntaxhighlight>
 
{{out}}
Line 2,754 ⟶ 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