# 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.

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.

# Clean, 269 ... 172 170 bytes

import StdEnv
?n=toChar n+'0'
$c|c<2=c=7-c n=[0,1,2,5] t=flatlines[u++[' - ':v]\\[u,v]<-[[map?[a,b,10,x,y],map?[$y,$x,10,$b,$a]]\\a<-n,b<-n,x<-n,y<-n]|['23:59']>=max u v]  Try it online! Ungolfed: import StdEnv numeral n = toChar (n+48) mirror 2 = 5 mirror 5 = 2 mirror c = c digits = [0, 1, 2, 5] times = flatlines [ // flatten with interspersed newlines original ++ [' - ' : reflection] // insert separator \\ // generate all pairs of times and their mirrored copies [original, reflection] <- [ [map numeral [a, b, 10, x, y], map (numeral o mirror) [y, x, 10, b, a]] \\ // generate every combination of display digits a <- digits, b <- digits, x <- digits, y <- digits ] | ['23:59'] >= max original reflection // make sure both times actually exist ]  # Pyth, 48 bytes Lj\:c2bjf!:T"5.:|25:"0mj" - ",ydyX_d25)^"0125"4  Try it online! Generates all possible combinations of 0125 and then manipulates them into the times. These are in the correct order because they are generated in lexicographic order. Finally, this filters out the extra invalid times by removing lines that match the regex 5.: or 25:. Sadly, it doesn't seem like compression works nicely on any of the strings that this program uses, unless I've made an error or oversight. # Perl 5, 147 bytes map{$h=0 x($_<10).$_;map{$_="0$_"if$_<10;say"$h:$_ -$q:$i"if($i=reverse$h=~y/25/52/r)<60&&"$h$_"!~/[34679]/&&($q=reverse y/25/52/r)<24}0..59}0..23


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.

# Jelly, 726662 55 bytes

®ṢiÐ€Uị®
“0152:”©ṢṖp⁺ḣ176j€“:”µ;"Ç€⁾25ẇ$ÐṂœs€2j€“ - ”Y  Try it online! Niladic program. I got the double product of '0125' idea from the 05AB1E answer by Emigna but the rest I did without consulting that since the languages diverge after that. There are probably opportunities for golfing, possibly by a lot. Explanation The program works as follows: • Take all products of length four of the list of characters '0125' with “0152:”©ṢṖp⁺. © copies the string '0152:' to the register for use later. ṢṖ sorts then pops the last element of the string → '0125'. ⁺ duplicates the product link. • ḣ176 removes any times with format 25xx or 5xxx (not valid hours). • j€“:” joins each pair of digits with a ':'. e.g. ['05'],['21']]'05:12'. • Ç€ applies the first link to each of these times. It finds the index of each character in the string '0125:' then for each of those indices gets the character in the string '0152:' and reverses it. This is the mirror operation (reversing and swapping 2s and 5s). • µ;" concatenates the original time with the mirrored time → '05:2115:20' • ⁾25ẇ$ÐṂ filters out the times with the substring '25'. This catches any time pairs with mirrored half 25:xx or 5x:xx. Note: I don't know why the $ is necessary. Perhaps someone could golf it out with the proper syntax but I'm not sure. • Split each of these times into two halves (œs€2) then join them with the string ' - ' (j€“ - ”). '05:2115:20''05:21 - 15:20'. • Finally, Y joins all the strings with a newline and everything is implicitly printed. Old versions 62 bytes i@€®ị“:0152” “:0125”©Ḋp⁺ḣ176j€“:”µ,"UÇ€$F€⁾25ẇ$ÐṂœs€2j€“ - ”Y  Try it online! 66 bytes “0125” i@€¢ị“0152” UṚÇ€ Ñp⁺ḣ176µ,"Ç€j€€“:”j€“ - ”¹⁾2 ẇ$ÐṂ⁾25ẇ$ÐṂY  Try it online! 72 bytes ⁾25 i@€¢µẋ@€¢ṙ" Ṛµ;@""Ç€Ḣ€€ “0125”p⁺j€“:”ḣ176µ,"Ç€j€“ - ”¹⁾2 ẇ$ÐṂÑẇ$ÐṂY  Try it online! # C (gcc), 175 174 bytes One off thanks to @Steadybox. char*p,s[14],*e;f(t){for(t=0;sprintf(p=s,"%02d:%02d -",t/100,t%100),t<2400;)if(t++%10^2&&!strpbrk(s,"346789")&&t%100^26){for(e=s+12;p<e;p++)*e--=*p^7*(*p>49&*p<58);puts(s);}}  Try it online! # Befunge, 178 bytes >0>:5g"7">v1\,+55< v_^#+87:+1_4>99p\ :99gg48 *-:55+/"0"+,55+%"0"+,":",\v >$1+:55v v,," - "_^#-5g99,+"0"%+55,+"0"/+55:-*84gg99:<
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!