Old Russian measure of length: Difference between revisions

m
imported>Arakov
 
(16 intermediate revisions by 12 users not shown)
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 408 ⟶ 515:
</pre>
 
=={{header|BBC BASIC}}==
==={{header|BASIC256}}===
<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
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}}==
Line 777 ⟶ 1,318:
until yn.toLower = 'n';
end.</syntaxhighlight>
 
=={{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:
<syntaxhighlight lang="elena">import system'collections;
import system'routines;
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)
Line 1,021 ⟶ 1,595:
10.000 arshin</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|Forth}}==
Tested with GForth.
Line 1,422 ⟶ 1,912:
Translation of python.
<syntaxhighlight lang="j">
#!/usr/bin/ijconsole
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'
 
Line 1,442 ⟶ 1,933:
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,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,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>
 
Line 2,363 ⟶ 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}}==
<syntaxhighlight lang="ruby">module Distances
Line 2,670 ⟶ 3,345:
{{libheader|Wren-fmt}}
{{libheader|Wren-str}}
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin, Stdout
import "./fmt" for Fmt
import "./str" for Str
 
var units = [
Line 2,759 ⟶ 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