# Mirrored Digital Clock

Many digital clocks display the time using simplified digits comprised of only seven different lights that are either on or off:

When mirrored horizontally, the digits 018 don't change because they are symmetrical. Also, the digits 2 and 5 get swapped, 2 becoming 5 and vice versa. All the other digits become invalid when mirrored.

Thus, given a 24-hour digital clock, there are many clock readings such that the mirrored image of the digital display is also a valid clock reading. Your task is to output all such clock readings along with the mirrored readings.

For example, 22:21 becomes 15:55, and 00:15 becomes 21:00. On the other hand, 12:34 or 16:27 are no longer valid when mirrored (digits 34679 become invalid), and neither are 22:22 or 18:21, because, as there are only 24 hours in a day and 60 minutes in an hour, no sane clock would display 55:55 or 12:81.

### Task

Write a program or a function that takes no input and outputs all valid pairs in ascending order as shown below:

00:00 - 00:00
00:01 - 10:00
00:05 - 20:00
00:10 - 01:00
00:11 - 11:00
00:15 - 21:00
00:20 - 05:00
00:21 - 15:00
00:50 - 02:00
00:51 - 12:00
00:55 - 22:00
01:00 - 00:10
01:01 - 10:10
01:05 - 20:10
01:10 - 01:10
01:11 - 11:10
01:15 - 21:10
01:20 - 05:10
01:21 - 15:10
01:50 - 02:10
01:51 - 12:10
01:55 - 22:10
02:00 - 00:50
02:01 - 10:50
02:05 - 20:50
02:10 - 01:50
02:11 - 11:50
02:15 - 21:50
02:20 - 05:50
02:21 - 15:50
02:50 - 02:50
02:51 - 12:50
02:55 - 22:50
05:00 - 00:20
05:01 - 10:20
05:05 - 20:20
05:10 - 01:20
05:11 - 11:20
05:15 - 21:20
05:20 - 05:20
05:21 - 15:20
05:50 - 02:20
05:51 - 12:20
05:55 - 22:20
10:00 - 00:01
10:01 - 10:01
10:05 - 20:01
10:10 - 01:01
10:11 - 11:01
10:15 - 21:01
10:20 - 05:01
10:21 - 15:01
10:50 - 02:01
10:51 - 12:01
10:55 - 22:01
11:00 - 00:11
11:01 - 10:11
11:05 - 20:11
11:10 - 01:11
11:11 - 11:11
11:15 - 21:11
11:20 - 05:11
11:21 - 15:11
11:50 - 02:11
11:51 - 12:11
11:55 - 22:11
12:00 - 00:51
12:01 - 10:51
12:05 - 20:51
12:10 - 01:51
12:11 - 11:51
12:15 - 21:51
12:20 - 05:51
12:21 - 15:51
12:50 - 02:51
12:51 - 12:51
12:55 - 22:51
15:00 - 00:21
15:01 - 10:21
15:05 - 20:21
15:10 - 01:21
15:11 - 11:21
15:15 - 21:21
15:20 - 05:21
15:21 - 15:21
15:50 - 02:21
15:51 - 12:21
15:55 - 22:21
20:00 - 00:05
20:01 - 10:05
20:05 - 20:05
20:10 - 01:05
20:11 - 11:05
20:15 - 21:05
20:20 - 05:05
20:21 - 15:05
20:50 - 02:05
20:51 - 12:05
20:55 - 22:05
21:00 - 00:15
21:01 - 10:15
21:05 - 20:15
21:10 - 01:15
21:11 - 11:15
21:15 - 21:15
21:20 - 05:15
21:21 - 15:15
21:50 - 02:15
21:51 - 12:15
21:55 - 22:15
22:00 - 00:55
22:01 - 10:55
22:05 - 20:55
22:10 - 01:55
22:11 - 11:55
22:15 - 21:55
22:20 - 05:55
22:21 - 15:55
22:50 - 02:55
22:51 - 12:55
22:55 - 22:55

A trailing or a leading newline is allowed. Having a few spaces directly before a linefeed is also allowed. The times must be in format hh:mm, padded with zeros when necessary.

This is , so the shortest answer in bytes wins. As usual, standard loopholes are disallowed.

• In Clean, a String is an array of Char. Is it acceptable if my answer gives a list of Char? The types look identical when bare-printed. – Οurous Dec 18 '17 at 22:34
• @Ourous Yes, I think it's fine. The consensus on meta seems to be that a string is a sequence of characters, and that's what a list of characters is. – Steadybox Dec 18 '17 at 22:39
• In this seven-segment display, the digit 1 is not exactly identical to its mirror image because you can tell if the right-most segments or the left-most segments are used to form the vertical "line" which makes up the digit. I understand that we consider them identical here. – Jeppe Stig Nielsen Dec 18 '17 at 22:43
• @JeppeStigNielsen let's pretend OP used an image with 14seg displays instead of 7seg, so the 1 could be centered. – Sparr Dec 19 '17 at 0:17
• @Steadybox Wow, I had this exact idea recently. I plan to use it on people during programming interviews. BTW I have a microwave oven which does not have a sane clock and allows you to specify things like 83:75 :-) – JohnEye Dec 19 '17 at 2:32

# 05AB1E, 34 bytes

0125DâDâεÂ5nÂ‡í)}ʒ€н25‹P}':ý… - ý»

Try it online!

Explanation

0125                                # push "0125"
Dâ                              # cartesian product with itself
Dâ                            # cartesian product with itself
ε       }                   # apply to each
Â                          # bifurcate
5nÂ                       # push 25 bifurcated
‡                      # transliterate
í                     # reverse each
)                    # wrap in a list
ʒ      }           # filter each on
€н                # head of each
25‹             # less than 25
P            # product
':ý        # merge on ":"
… - ý   # merge on " - "
»  # join on newlines

# Python 2, 187180178 177 bytes

R=range(11)
for t in['0000111122201250125012'[j::11]+':'+'0001112255501501501015'[i::11]for i in R for j in R]:print t+' - '+''.join(map(dict(zip('0125:','0152:')).get,t))[::-1]

Try it online!

Thanks for +1 Kevin Cruijssen.

# APL (Dyalog Unicode), 84 bytesSBCS

Complete program outputting to STDOUT. Requires ⎕IO (Index Origin) to be 0 which is default on many systems.

{0::⋄∧/23 59≥⍎¨(':'≠t)⊆t←⌽'015xx2xx8x:'[⎕D⍳i←∊⍺':'⍵]:⎕←1↓⍕i'-'t}⌿1↓¨⍕¨100+0 60⊤⍳1440

Try it online!

⍳1440 that many ɩntegers

0 60⊤ convert to mixed-base ∞,60

100+ add 100 (this pads the needed 0s)

⍕¨ format (stringify) each

1↓¨ drop the first character from each (this removes the leading 1s)

{}⌿ apply the following anonymous function column-wise ( is top hour, is minute)

0:: if any error happens, return nothing

try:

'015xx2xx8x:'[] index this string with:

∊⍺':'⍵ the ϵnlisted (flattened) list of hour, colon, minute

i← stored in i (for input)

⎕D⍳ɩndices of each character in the list of Digits

reverse that

t← store as t (for time)

()⊆ group runs where:

':'≠t colon differs from t

⍎¨ execute (evaluate) each

23 59≥ Boolean for each whether they are less than or equal to 23 and 59 respectively

∧/ are both true?

: if so, then:

⍕i'-'t the formatted (space-separated) list of input, dash, time

1↓ drop the first (space)

⎕← output to STDOUT

# Retina, 57 bytes

-
+m^.{3,9}$0$&0¶1$&1¶2$&5¶5$&2 A\b2?5 \b\d.$&:
O

Try it online! Explanation:

-

Insert the separator.

+m^.{3,9}$0$&0¶1$&1¶2$&5¶5$&2 Generate all possible sets of four mirrored digits. A\b2?5 Delete those with illegal hours. \b\d.$&:

Insert the colons.

O

Sort into order.

# Python 2, 279277 255 bytes

for h in range(1440):
q=[[[0,(a+"52")[(a=="2")+(a=="5")*2]][a in"01825"]for a in c]for c in[("%02d"%e)[::-1]for e in[h%60,h/60]]]
if all(q[0]+q[1]):
z=[int(''.join(j))for j in q]
if(z[1]<60)*(z[0]<24):print"%02d:%02d - %02d:%02d"%(h/60,h%60,z[0],z[1])

Try it online!

# Credits

• 279 bytes reduced to 256 by dylnan.

• 256 bytes reduced to 255 by FlipTrack.

import StdEnv
?n=toChar n+'0'

Try it online!

# Japt v2 (+ -R), 51 bytes

G²Çs4 ùT4 i':2Ã®+" - "+Zw r\d_^Z>1})r3,5Ãkf/5.|25):

Test it online!

### Explanation

G²Ç   s4 ùT4 i':2Ã ®   +" - "+Zw r\d_  ^Z>1})r3,5Ã kf/5.|25):
G²oZ{Zs4 ùT4 i':2} mZ{Z+" - "+Zw r\dZ{Z^Z>1})r3,5} kf/5.|25):/   Ungolfed

G²              Calculate 16**2, or 256.
oZ{       }   Create the range [0...256) and map each integer Z to:
Zs4               Convert Z to a base-4 string.  [0, 1, 2, 3, 10, ..., 3331, 3332, 3333]
ùT4           Pad-left with 0's to length 4. [0000, 0001, 0002, ..., 3331, 3332, 3333]
i':2      Insert a colon at index 2.     [00:00, 00:01, 00:02, ..., 33:31, 33:32, 33:33]

mZ{      }      Map each string Z in the resulting array to:
Zw r\dZ{     }    Reverse Z, and replace each digit Z' with
Z^Z>1       Z' xor'd with (Z>1). This turns 2 to 3 and vice versa.
We now have [00:00, 10:00, 30:00, 20:00, 01:00, ..., 12:22, 32:22, 22:22]
Z+" - "+          Append this to Z with " - " in between. This gives
[00:00 - 00:00, 00:01 - 10:00, 00:02 - 30:00, ..., 33:32 - 32:22, 33:33 - 22:22]
r3,5              Replace all 3s in the result with 5s.
[00:00 - 00:00, 00:01 - 10:00, 00:02 - 50:00, ..., 55:52 - 52:22, 55:55 - 22:22]

k               Remove all results that
f/5.|25):/       match the regex /(5.|25):/g. This removes times with impossible hours.

Implicit: output result of last expression, joined with newlines (-R)

# JavaScript (ES6), 142 bytes

f=(n=0)=>n<176?(s=(g=n=>d[n>>2]+d[n&3])(n%4*4|n/4&3,d='0152')+':'+g(n>>6|(n/4&12)),s<'25'?g(n>>4,d='0125')+:${g(n&15)} -${s}
:'')+f(n+1):''

Try it online!

# Charcoal, 59 bytes

Ｆ012Ｆ0125Ｆ0125Ｆ015¿›‹⁺ικ25⁼⁺λμ25«ικ:λμ - Ｆ⟦μλ3κι⟧§015::2Ｉν⸿

Try it online! Link is to verbose version of code. Explanation:

Ｆ012Ｆ0125Ｆ0125Ｆ015

Create four nested loops for the unmirrored digits.

¿›‹⁺ικ25⁼⁺λμ25«

Check that neither the hours nor minutes is 25. (Mirroring the 25 minutes will result in 25 hours, so that's a no-go.)

ικ:λμ -

Print the unmirrored time.

Ｆ⟦μλ3κι⟧§015::2Ｉν⸿

Print the mirrored time by converting the reversed digits (or 3 for the colon) from string to integer and looking them up in a translation table.

Alternatively, also for 59 bytes:

Ｆ¹¹Ｆ¹⁶¿⁻¹¹κ¿⁻²﹪κ⁴«≔⟦÷ι⁴﹪ι⁴¦⁴÷κ⁴﹪κ⁴⟧θＦθ§0125:λ - Ｆ⮌θ§0152:λ⸿

Try it online! Link is to verbose version of code. Explanation:

Ｆ¹¹Ｆ¹⁶

Create loops for the hours and minutes.

¿⁻¹¹κ¿⁻²﹪κ⁴«

Exclude 25 and also any minutes ending in 2.

≔⟦÷ι⁴﹪ι⁴¦⁴÷κ⁴﹪κ⁴⟧θ

Convert the hours and minutes to base 4.

Ｆθ§0125:λ

Print the digits looked up in a translation table.

-

Print the separator.

Ｆ⮌θ§0152:λ⸿

Print the reversed digits looked up in a mirrored translation table.

®ṢiÐ€Uị®
v_@#!`+< >,\5^
!"%*+,/4569RSTW
*R4!+S5%/W9",T6

Try it online!

# Kotlin, 205 207 bytes

(0..1439).map{"%02d : %02d".format(it/60,it%60)}.let{it.map{i->i to i.reversed().map{x->"25180:X52180:".let{it[it.indexOf(x)+7]}}.joinToString("")}.filter{(_,b)->it.contains(b)}.map{(a,b)->println("$a-$b")}}

## Beautified

(0..1439)
.map { "%02d : %02d".format(it / 60, it % 60) }              // Make the times
.let { it.map {i->
i to i.reversed().map {x->                         // Pair it with the reversed times
"25180:X52180:".let{ it[it.indexOf(x)+7] }     // - X means bad times are removed
}.joinToString("")                                 // - Make the string
}.filter {(_,b)-> it.contains(b) }                     // Remove the unpaired times
.map { (a, b) -> println("$a -$b") }              // Print out the pairs
}

## Test

fun main(args: Array<String>) {
f()
}

fun f() =
(0..1439).map{"%02d:%02d".format(it/60,it%60)}.let{it.map{i->i to i.reversed().map{x->"25180:X52180:".let{it[it.indexOf(x)+7]}}.joinToString("")}.filter{(_,b)->it.contains(b)}.map{(a,b)->println("$a-$b")}}

TryItOnline

## Edits

• There's supposed to be a space on both sides of the -. Costs only two bytes to add: Try it online! – Steadybox Feb 4 '18 at 13:20
• Fixed, I wonder if there is a way to get back to 205 bytes reducing the rest of the code – jrtapsell Feb 4 '18 at 13:24

# C, 225 bytes

h,m,l,r,d=10,L[]={0,1,5,9,9,2,9,9,8,9};M(h,m){l=L[h%d]*d+L[h/d];r=L[m%d]*d+L[m/d];return L[h%d]<9&L[h/d]<9&L[m%d]<9&L[m/d]<9;}f(){for(h=0;h<24;++h)for(m=0;m<60;++m)M(h,m)&l<60&r<24&&printf("%02d:%02d - %02d:%02d\n",h,m,r,l);}

Since there is no C answer, I post my own. Some other approach might be shorter.

Try it online!