How to resolve the algorithm Old Russian measure of length step by step in the Factor programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Old Russian measure of length step by step in the Factor programming language
Table of Contents
Problem Statement
Write a program to perform a conversion of the old Russian measures of length to the metric system (and vice versa).
It is an example of a linear transformation of several variables.
The program should accept a single value in a selected unit of measurement, and convert and return it to the other units: vershoks, arshins, sazhens, versts, meters, centimeters and kilometers.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Old Russian measure of length step by step in the Factor programming language
Source code in the factor programming language
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
You may also check:How to resolve the algorithm Linear congruential generator step by step in the Scala programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Pinstripe/Display step by step in the Python programming language
You may also check:How to resolve the algorithm Quickselect algorithm step by step in the F# programming language
You may also check:How to resolve the algorithm Simulate input/Mouse step by step in the Oz programming language