Convert seconds to compound duration: Difference between revisions
Content deleted Content added
Langurmonkey (talk | contribs) |
→{{header|Uiua}}: improved algorithm |
||
Line 4,156: | Line 4,156: | ||
=={{header|Uiua}}== |
=={{header|Uiua}}== |
||
{{Works with|Uiua|0.12.0-dev.1}} |
{{Works with|Uiua|0.12.0-dev.1}} |
||
[https://uiua.org/pad?src=0_12_0-dev_1__IyBCdWlsZHMgYSBzdHJpbmcgcmVwcmVzZW50YXRpb24gb2YgYSB0aW1lIHBlcmlvZAoKVW5pdHMg4oaQIHsic2Vjb25kIiAibWludXRlIiAiaG91ciIgImRheSIgIndlZWsifQpEdXJhdGlvbnMg4oaQIFs2MCA2MCAyNCA3IDk5OTldCgpQYXJ0cyDihpAg4oeM4peM4oinKOKKmeKKguKKgyjijIrDt3zil78pKUR1cmF0aW9uc-KKmVtdICAjIHNlY29uZHMgLT4gW1MgTSBIIEQgV10KU3VuaXQg4oaQIC_ijZokIl8gXyLijaXijZwo4oqhMXzijZriioLiiplAcyniiaDilqEiMSLiiqIuICMgU3RyaW5naWZ5IGEgdW5pdApTdHJpbmcg4oaQIC_il4ckIl8sIF8i4oeM4omhU3VuaXTilr3iioMowrF84o2J4oeM4oqfVW5pdHPCsOKLlSkgUGFydHMK4omhKCZwJCJfcyAgIFx0PSBfIuKfnCjilqFTdHJpbmcpKVs3MjU5IDg2NDAwIDYwMDAwMDAgMTQwMDAwMDAgMzE0NDk1OTkgMzE0NDk2MDFdCg== Run it in Uiua Pad!] |
|||
[https://www.uiua.org/pad?src=0_12_0-dev_1__IyBCdWlsZHMgYSBzdHJpbmcgcmVwcmVzZW50YXRpb24gb2YgYSB0aW1lIHBlcmlvZAoKVW5pdHMg4oaQIHsic2Vjb25kIiAibWludXRlIiAiaG91ciIgImRheSIgIndlZWsifQpEdXJhdGlvbnMg4oaQIFs2MCA2MCAyNCA3IDk5OTldCgojIG51bWJlci1vZi1zZWNvbmRzIC0-IFtTIE0gSCBEIFddClBhcnRzIOKGkCDih4wo4peM4oinKOKKmeKKguKKgyjijIrDt3zil78pKSBEdXJhdGlvbnPiiplbXSkKIyBTdHJpbmdpZnkgYSB1bml0OiB7IlgiICJ1bml0In0gLT4gYm94IlggdW5pdHMiICAgICAgIApTdW5pdCDihpAgL-KNmijiioLiioIpIiAi4o2l4o2cKOKKoTF84o2a4oqC4oqZQHMp4omg4pahIjEi4oqiLgojIFBhcnNlIHNlY29uZHMgYXMgYSBzdHJpbmcgcGVyaW9kOiBOIC0-ICJ4eHgiICAgIApTdHJpbmcg4oaQIMKw4pah4oqiL-KNmiQiXywgXyLih4ziiaFTdW5pdOKWveKKgyjCsXzijYnih4ziip9Vbml0c8Kw4ouVKSBQYXJ0cwriiLUoW-KWoVN0cmluZ10pWzcyNTkgODY0MDAgNjAwMDAwMCAxNDAwMDAwMCAzMTQ0OTU5OSAzMTQ0OTYwMV0K Run it in Uiua Pad!] |
|||
<syntaxhighlight lang="uiua"> |
<syntaxhighlight lang="uiua"> |
||
# Builds a string representation of a time period |
# Builds a string representation of a time period |
||
Line 4,163: | Line 4,163: | ||
Durations ← [60 60 24 7 9999] |
Durations ← [60 60 24 7 9999] |
||
# |
Parts ← ⇌◌∧(⊙⊂⊃(⌊÷|◿))Durations⊙[] # seconds -> [S M H D W] |
||
⚫ | |||
Parts ← ⇌(◌∧(⊙⊂⊃(⌊÷|◿)) Durations⊙[]) |
|||
⚫ | |||
# Stringify a unit: {"X" "unit"} -> box"X units" |
|||
⚫ | |||
⚫ | |||
# Parse seconds as a string period: N -> "xxx" |
|||
⚫ | |||
⚫ | |||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
7259s = 2 hours, 59 seconds |
|||
╭─ |
|||
86400s = 1 day |
|||
╷ ⌜2 hours, 59 seconds⌟ |
|||
⚫ | |||
⌜1 day⌟ |
|||
14000000s = 23 weeks, 1 day, 53 minutes, 20 seconds |
|||
31449599s = 51 weeks, 6 days, 23 hours, 59 minutes, 59 seconds |
|||
31449601s = 52 weeks, 1 second |
|||
⚫ | |||
⌜52 weeks, 1 second⌟ |
|||
╯ |
|||
</pre> |
</pre> |
||