Old Russian measure of length: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Phix}}: syntax coloured, made p2js compatible)
m (syntax highlighting fixup automation)
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 172:
===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:
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:
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:
printf("error: invalid measure; choose from: %s\n\n",units)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 409:
 
=={{header|BBC BASIC}}==
<langsyntaxhighlight lang="bbcbasic">REM >oldrussian
@% = &90E
PROColdrus(1, "meter")
Line 434:
NEXT
ENDIF
ENDPROC</langsyntaxhighlight>
{{out}}
<pre>1 meter =
Line 466:
=={{header|C}}==
Accepts length and unit as input, prints out length in all other units. Usage printed on incorrect invocation.
<syntaxhighlight lang="c">
<lang C>
#include<string.h>
#include<stdlib.h>
Line 504:
return 0;
}
</syntaxhighlight>
</lang>
Output :
<pre>
Line 540:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <iostream>
#include <iomanip>
Line 602:
}
//-------------------------------------------------------------------------------------------
</syntaxhighlight>
</lang>
Output:
<pre>
Line 640:
=={{header|D}}==
{{trans|Raku}}
<langsyntaxhighlight lang="d">import std.stdio, std.string, std.algorithm, std.conv;
 
void main(in string[] args) {
Line 665:
foreach (immutable key; factor.keys.schwartzSort!(k => factor[k]))
writefln("%10s: %s", key, meters / factor[key]);
}</langsyntaxhighlight>
{{out}}
<pre>1 meter to:
Line 701:
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Old_Russian_measure_of_length;
 
Line 776:
readln(yn);
until yn.toLower = 'n';
end.</langsyntaxhighlight>
 
=={{header|Elena}}==
{{trans|Julia}}
ELENA 5.2:
<langsyntaxhighlight lang="elena">import system'collections;
import system'routines;
import extensions;
Line 821:
console.printPaddingLeft(30, u, ":").printLine(value * unit2mult[unit] / mlt)
}
}</langsyntaxhighlight>
{{out}}
<pre>2.3 meter to:
Line 841:
=={{header|Factor}}==
This solution makes use of Factor's rather robust <code>units</code> vocabulary. Units may be defined in terms of any unit and converted to any unit through the power of inverse functions (via the <code>inverse</code> vocabulary). This means that we also have access to a variety of units defined in <code>units.si</code>, <code>units.imperial</code>, etc.
<langsyntaxhighlight lang="factor">USING: formatting inverse io kernel math prettyprint quotations
sequences units.imperial units.si vocabs ;
IN: rosetta-code.units.russian
Line 872:
PRIVATE>
 
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 931:
 
=={{header|Fortran}}==
<langsyntaxhighlight lang="fortran">PROGRAM RUS
IMPLICIT NONE
REAL, PARAMETER:: E_m = 1.
Line 981:
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,022:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Dim units(1 To 13) As String = {"tochka", "liniya", "dyuim", "vershok", "piad", "fut", _
Line 1,065:
Loop Until yn = "n"
End</langsyntaxhighlight>
Sample input/output:
{{out}}
Line 1,107:
=={{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:
1e s" meter" show
20e s" versta" show
10e s" milia" show</langsyntaxhighlight>
{{out}}
<pre>
Line 1,188:
=={{header|Frink}}==
One of Frink's unique features is tracking units of measure through all calculations. It is easy to add new units of measure and allow them to be automatically converted between any existing units. Frink's standard data file contains 642 units of length (not including prefixes) that this program can convert between.
<langsyntaxhighlight lang="frink">arshin := (2 + 1/3) ft
vershok := 1/16 arshin
sazhen := 3 arshin
Line 1,210:
println[" " + (val -> "meters")]
println[" " + (val -> "centimeters")]
println[" " + (val -> "kilometers")]</langsyntaxhighlight>
{{out}}
<pre>
Line 1,227:
=={{header|Go}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,294:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,336:
=={{header|Haskell}}==
 
<langsyntaxhighlight Haskelllang="haskell">module Main where
 
import Text.Printf (printf)
Line 1,370:
(_) -> do
name <- getProgName
printf "Arguments were wrong - please use ./%s <number> <unit>\n" name</langsyntaxhighlight>
 
Output:
Line 1,421:
=={{header|J}}==
Translation of python.
<syntaxhighlight lang="j">
<lang J>
NB. Use, linux.
NB. $ /usr/local/j64-801/bin/jconsole j.ijs 8 meter
Line 1,443:
end.
)
</syntaxhighlight>
</lang>
<pre>
$ /usr/local/j64-801/bin/jconsole j.ijs 8 meter
Line 1,478:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">public class OldRussianMeasures {
 
final static String[] keys = {"tochka", "liniya", "centimeter", "diuym",
Line 1,510:
return Double.NaN;
}
}</langsyntaxhighlight>
 
<pre>1 meter to:
Line 1,548:
{{trans|Python}}
 
<langsyntaxhighlight lang="julia">using DataStructures
 
const unit2mult = Dict(
Line 1,570:
for (unt, mlt) in sort(unit2mult)
@printf(" %10s: %g\n", unt, value * unit2mult[unit] / mlt)
end</langsyntaxhighlight>
 
{{out}}
Line 1,591:
=={{header|Kotlin}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="scala">// version 1.0.6
 
/* clears console on Windows 10 */
Line 1,635:
}
while (yn == "y")
}</langsyntaxhighlight>
Sample input/output
{{out}}
Line 1,677:
=={{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:
 
=={{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:
=={{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:
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:
Displaying converted values to 5 significant digits.
{{trans|Raku}}
<langsyntaxhighlight lang="perl">sub convert {
my($magnitude, $unit) = @_;
my %factor = (
Line 1,789:
 
print convert(1,'meter'), "\n\n";
print convert(1,'milia'), "\n";</langsyntaxhighlight>
{{out}}
<pre> tochka: 3937.0
Line 1,819:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">units</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #008000;">"-- metric ---"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">},</span>
Line 1,887:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000080;font-style:italic;">--end while</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,914:
:<code>commandname <value> <unit></code>
 
<langsyntaxhighlight lang="python">from sys import argv
unit2mult = {"arshin": 0.7112, "centimeter": 0.01, "diuym": 0.0254,
Line 1,935:
print("%g %s to:" % (value, unit))
for unt, mlt in sorted(unit2mult.items()):
print(' %10s: %g' % (unt, value * unit2mult[unit] / mlt))</langsyntaxhighlight>
 
{{out}}
Line 1,986:
=={{header|Racket}}==
Follows the Raku solution, produces similar output.
<langsyntaxhighlight lang="racket">
#lang racket
 
Line 2,014:
(show 'meter)
(show 'milia)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 2,021:
Fairly straightfoward. Define a hash of conversion factors then apply them. Makes no attempt to do correct pluralization because I have no idea what the correct plurals are and little interest in researching them. Conversion factors from Wikipedia: [[wp:Obsolete_Russian_units_of_measurement#Length|Obsolete Russian units of measurement]].
 
<syntaxhighlight lang="raku" perl6line>convert(1, 'meter');
 
say '*' x 40, "\n";
Line 2,051:
for %factor.keys.sort:{ +%factor{$_} }
}
</syntaxhighlight>
</lang>
 
<pre>
Line 2,095:
::* &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,225:
err: say center(' error ', sw % 2, "*"); do j=1 to arg(); say arg(j); end; exit 13
s: if arg(1)=1 then return arg(3); return word( arg(2) 's', 1) /*plurals.*/
tell: parse arg $; numeric digits 8; $= $ / 1; say right($, 40) arg(2)s($); return</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,286:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Old Russian measure of length
 
Line 2,327:
end
end
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,364:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">module Distances
 
RATIOS =
Line 2,392:
# 13*13 = 169 methods supported, but not:
p Distances.mile2piad(1)
</syntaxhighlight>
</lang>
{{out}}
<pre>2 meter =
Line 2,419:
:<code>commandname <value> <unit></code>
 
<langsyntaxhighlight lang="rust">use std::env;
use std::process;
use std::collections::HashMap;
Line 2,456:
 
}
</syntaxhighlight>
</lang>
<pre>
$ ./oldrus test
Line 2,495:
 
=={{header|Scala}}==
<langsyntaxhighlight Scalalang="scala">import scala.collection.immutable.HashMap
 
object OldRussianLengths extends App {
Line 2,516:
} 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,547:
convert(1, 'meter')
say('')
convert(1, 'milia')</langsyntaxhighlight>
{{out}}
<pre>1 meter to:
Line 2,583:
Tcllib already has a [http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/units/units.html units] package which knows about a lot of things, and can be taught more. Since the other examples in this page provide a nicely tabulated conversions for 1 meter, we can copy that directly to get started ...
 
<syntaxhighlight lang="tcl">
<lang Tcl>
package require units
 
Line 2,622:
add_russian_units
demo
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,659:
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,670:
{{libheader|Wren-fmt}}
{{libheader|Wren-str}}
<langsyntaxhighlight lang="ecmascript">import "io" for Stdin, Stdout
import "/fmt" for Fmt
import "/str" for Str
Line 2,723:
if (yn == "n") break
System.print()
}</langsyntaxhighlight>
 
{{out}}
10,333

edits