Old Russian measure of length: Difference between revisions

Add Factor example
m (→‎{{header|FORTRAN}}: Fortran instead of FORTRAN)
(Add Factor example)
Line 377:
versta: 7
milia: 1</pre>
 
=={{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.
<lang factor>USING: formatting inverse io kernel math prettyprint quotations
sequences units.imperial units.si vocabs ;
IN: rosetta-code.units.russian
 
: arshin ( n -- d ) 2+1/3 * feet ;
: tochka ( n -- d ) 1/2800 * arshin ;
: liniya ( n -- d ) 1/280 * arshin ;
: dyuim ( n -- d ) 1/28 * arshin ;
: vershok ( n -- d ) 1/16 * arshin ;
: ladon ( n -- d ) 7+1/2 * cm ;
: piad ( n -- d ) 1/4 * arshin ;
: fut ( n -- d ) 3/7 * arshin ;
: lokot ( n -- d ) 45 * cm ;
: shag ( n -- d ) 71 * cm ;
: sazhen ( n -- d ) 3 * arshin ;
: versta ( n -- d ) 1,500 * arshin ;
: milya ( n -- d ) 10,500 * arshin ;
 
<PRIVATE
 
: convert ( quot -- )
[ unparse rest rest but-last write "to:" print ] [ call ] bi
"rosetta-code.units.russian" vocab-words { cm m km } append
[ dup "%8u : " printf 1quotation [undo] call( x -- x ) . ]
with each nl ; inline
 
: main ( -- )
[ 6 m ] [ 1+7/8 milya ] [ 2 furlongs ] [ convert ] tri@ ;
 
PRIVATE>
 
MAIN: main</lang>
{{out}}
<pre>
6 m to:
versta : 5/889
vershok : 134+874/889
shag : 8+32/71
tochka : 23622+6/127
fut : 19+87/127
ladon : 80
piad : 33+663/889
sazhen : 2+722/889
lokot : 13+1/3
milya : 5/6223
dyuim : 236+28/127
liniya : 2362+26/127
arshin : 8+388/889
cm : 600
m : 6
km : 3/500
 
1+7/8 milya to:
versta : 13+1/8
vershok : 315000
shag : 19720+55/71
tochka : 55125000
fut : 45937+1/2
ladon : 186690
piad : 78750
sazhen : 6562+1/2
lokot : 31115
milya : 1+7/8
dyuim : 551250
liniya : 5512500
arshin : 19687+1/2
cm : 1400175
m : 14001+3/4
km : 14+7/4000
 
2 furlongs to:
versta : 66/175
vershok : 9051+3/7
shag : 566+238/355
tochka : 1584000
fut : 1320
ladon : 5364+12/25
piad : 2262+6/7
sazhen : 188+4/7
lokot : 894+2/25
milya : 66/1225
dyuim : 15840
liniya : 158400
arshin : 565+5/7
cm : 40233+3/5
m : 402+42/125
km : 12573/31250
</pre>
 
=={{header|Fortran}}==
<lang fortran>PROGRAM RUS
1,808

edits