Sums of 24-hour time

Jelly, 16 30 29 20 bytes

Now with the correct output format! Many thanks to Dennis for his help in debugging this answer. Golfing suggestions welcome. Try it online!

Edit: +14 bytes from using the correct output format. -1 byte from removing an extra space. -3 from changing from 24,60,60 to “ð<<‘. -6 bytes from changing +100DḊ€€ to d⁵.

“ð<<‘Œp’S=¥Ðfd⁵j€”:Y

Explanation

“ð<<‘Œp’S=¥Ðfd⁵j€”:Y  Main link. Argument: n

“ð<<‘                 Jelly ord() the string `ð<<` to get [24, 60, 60]. Call this list z.
     Œp               Cartesian product of z's items. 
                        Since each item of z is a literal,
                        Jelly takes the range [1 ... item] for each item.
       ’              Decrements every number in the Cartesian product 
                        to get lowered ranges [0 ... item-1].
        S=¥           Create a dyadic link of `sum is equal to (implicit n)`.
           Ðf         Filter the Cartesian product for items with sum equal to n.
             d⁵       By taking divmod 10 of every number in each item,
                        we get zero padding for single-digit numbers
                        and every double-digit number just turns into a list of its digits.
               j€”:   Join every number with a ':'.
                   Y  Join all of the times with linefeeds for easier reading.

Bash, 71

  • 8 bytes saved thanks to @hvd
for t in {0..23}+{00..59}+{00..59};{((${t//+0/+}-$1))||echo ${t//+/:};}

Try it online.


Perl 6, 62 56 bytes

{map *.fmt('%02d',':'),grep $_==*.sum,(^24 X ^60 X ^60)}

Just checks all possible combinations in the cross product of all hours, minutes, and seconds.

Tags:

Math

Code Golf