70 lines
1.8 KiB
Text
70 lines
1.8 KiB
Text
;Task:
|
|
Write a function or program which:
|
|
* takes a positive integer representing a duration in seconds as input (e.g., <code>100</code>), and
|
|
* returns a string which shows the same duration decomposed into:
|
|
:::* weeks,
|
|
:::* days,
|
|
:::* hours,
|
|
:::* minutes, and
|
|
:::* seconds.
|
|
|
|
This is detailed below (e.g., "<code>2 hr, 59 sec</code>").
|
|
|
|
|
|
Demonstrate that it passes the following three test-cases:
|
|
|
|
<p style="font-size:115%; margin:1em 0 0.5em 0">'''''Test Cases'''''</p>
|
|
|
|
:::::{| class="wikitable"
|
|
|-
|
|
! input number
|
|
! output string
|
|
|-
|
|
| 7259
|
|
| <code style="background:#eee">2 hr, 59 sec</code>
|
|
|-
|
|
| 86400
|
|
| <code style="background:#eee">1 d</code>
|
|
|-
|
|
| 6000000
|
|
| <code style="background:#eee">9 wk, 6 d, 10 hr, 40 min</code>
|
|
|}
|
|
|
|
<p style="font-size:115%; margin:1em 0 0.5em 0">'''''Details'''''</p>
|
|
|
|
The following five units should be used:
|
|
:::::{| class="wikitable"
|
|
|-
|
|
! unit
|
|
! suffix used in output
|
|
! conversion
|
|
|-
|
|
| week
|
|
| <code style="background:#eee">wk</code>
|
|
| 1 week = 7 days
|
|
|-
|
|
| day
|
|
| <code style="background:#eee">d</code>
|
|
| 1 day = 24 hours
|
|
|-
|
|
| hour
|
|
| <code style="background:#eee">hr</code>
|
|
| 1 hour = 60 minutes
|
|
|-
|
|
| minute
|
|
| <code style="background:#eee">min</code>
|
|
| 1 minute = 60 seconds
|
|
|-
|
|
| second
|
|
| <code style="background:#eee">sec</code>
|
|
|
|
|
|}
|
|
|
|
However, '''only''' include quantities with non-zero values in the output (e.g., return "<code>1 d</code>" and not "<code>0 wk, 1 d, 0 hr, 0 min, 0 sec</code>").
|
|
|
|
Give larger units precedence over smaller ones as much as possible (e.g., return <code>2 min, 10 sec</code> and not <code>1 min, 70 sec</code> or <code>130 sec</code>)
|
|
|
|
Mimic the formatting shown in the test-cases (quantities sorted from largest unit to smallest and separated by comma+space; value and unit of each quantity separated by space).
|
|
<hr style="margin:1em 0;"/>
|
|
<br><br>
|
|
|