Convert seconds to compound duration: Difference between revisions

Content deleted Content added
No edit summary
Chunes (talk | contribs)
added Factor
Line 1,344: Line 1,344:
86400 = 1 day
86400 = 1 day
6000000 = 9 wk, 6 day, 10 hr, 40 min</pre>
6000000 = 9 wk, 6 day, 10 hr, 40 min</pre>

=={{header|Factor}}==
<lang factor>USING: assocs io kernel math math.parser qw sequences
sequences.generalizations ;
IN: rosetta-code.compound-duration

CONSTANT: units qw{ wk d hr min sec }

: convert ( seconds -- {wk,d,hr,min,sec} )
60 /mod swap 60 /mod swap 24 /mod swap 7 /mod swap
5 narray reverse ;
: .compound ( n -- ) convert [ number>string ] map units zip
[ first "0" = not ] filter [ " " join ] map ", " join print ;
{ 7259 86400 6000000 } [ .compound ] each</lang>
{{out}}
<pre>
2 hr, 59 sec
1 d
9 wk, 6 d, 10 hr, 40 min
</pre>


=={{header|Forth}}==
=={{header|Forth}}==