Old Russian measure of length: Difference between revisions

no edit summary
m (Promote to task, lots of examples, little controversy)
No edit summary
Line 639:
 
Do another one y/n : ? n
</pre>
=={{header|Forth}}==
Tested with GForth.
<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 )
units swap 2 cells * + 2@ ;
: myval ( u1 -- caddr u1 )
values swap 1 cells * + f@ ;
: 2define create 0 , 0 , ;
 
2define ch_u
variable mlt
variable theunit
: show ( chosen_unit chosen_mutliplier -- )
ch_u 2!
mlt f!
13 0 DO
ch_u 2@ i unit compare if
else mlt f@ f. i unit type cr ." ===========" cr
i myval theunit f!
13 0 DO
." " i unit type ." : " theunit f@ i myval f/ mlt f@ f* f. cr
LOOP
then
LOOP cr ;
1e s" meter" show
20e s" versta" show
10e s" milia" show</lang>
{{out}}
<pre>
1. meter
===========
kilometer: 0.001
meter: 1.
centimeter: 100.
tochka: 3937.00787401575
liniya: 393.700787401575
diuym: 39.3700787401575
vershok: 22.4971878515186
piad: 5.62429696287964
fut: 3.28083989501312
arshin: 1.40607424071991
sazhen: 0.468691413573303
versta: 0.000937382827146607
milia: 0.000133911832449515
 
20. versta
===========
kilometer: 21.336
meter: 21336.
centimeter: 2133600.
tochka: 84000000.
liniya: 8400000.
diuym: 840000.
vershok: 480000.
piad: 120000.
fut: 70000.
arshin: 30000.
sazhen: 10000.
versta: 20.
milia: 2.85714285714286
 
10. milia
===========
kilometer: 74.676
meter: 74676.
centimeter: 7467600.
tochka: 294000000.
liniya: 29400000.
diuym: 2940000.
vershok: 1680000.
piad: 420000.
fut: 245000.
arshin: 105000.
sazhen: 35000.
versta: 70.
milia: 10.
 
 
</pre>
 
Anonymous user