Incremental Game Time Format
Incremental games often have a countdown timer expressing the days, hours, minutes and seconds until a task is complete. Depending on the space available, they can be formatted as:
2d 13h 23h 59m 48s 14m 3h 0m 0s
The goal of this code golf is to write a function or program that performs this formatting.
- The total number of seconds.
- The maximum number of segments to output.
- Segments include:
- 0w weeks
- 0d days
- 0h hours
- 0m minutes
- 0s seconds
- Each segment is separated by a single space.
- Displayed segments must be contiguous. For example, you will not show hours and seconds without showing minutes, even if there are zero minutes.
- Single-digit values do not have leading zeros, though a value of zero must be shown as
- Values are rounded down.
- The first segment displayed is the first non-zero value.
seconds segments output 0 1 0s 123 1 2m 123 2 2m 3s 123 3 2m 3s 82815 3 23h 0m 15s 307891 2 3d 13h 307891 4 3d 13h 31m 31s 604800 1 1w 604800 6 1w 0d 0h 0m 0s
The lowest byte-count solution in one week will win "acceptance".
- Clarified which segment is first, as shown in examples.
- Added test case 4 as per request.