# Digital display symmetry

The Wolfram Demonstrations Project has a digital display.

In the Math 9 text I am using, they ask this question.

The 24-hour clock represents midnight as 00:00 and three-thirty A.M. as 03:30. The time 03:30 has line symmetry with a horizontal line of reflection. List as many times from midnight onward that have line symmetry, rotational symmetry, or both. Describe the symmetry for each time you find.

Easy to find specific examples, wondering if anyone has some hints or ideas about how to programmatically come up with times that meet different symmetry criteria? (and be able to display the times on a digital clock display?)

• Can you link to the Demonstration you are referring to? – J. M.'s torpor Mar 29 '19 at 18:29
• Edited to link to the demonstration. – Tom De Vries Mar 29 '19 at 18:31

I started by defining all the numbers that I think would be horizontally, vertically, or rotationally symmetric.

horizontal = {0, 1, 3, 8};
vertical = {0, 2, 5, 8};
rotatable = {0, 2, 5, 6, 8, 9};


Then I define a few helper functions to determine whether a particular symmetry exists.

validTimeQ[list__] := list[[3]] <= 5 \[And] (list[[1]] <= 1 \[Or] (list[[1]] <= 2 \[And] list[[2]] <= 3))
verticalSymmetryQ[list__] := list[[1 ;; 2]] == (list[[{4, 3}]] /. {2 -> 5, 5 -> 2})
rotationalSymmetryQ[list__] := list == (Reverse[list] /. {6 -> 9, 9 -> 6})


The validTimeQ function makes sure I don't have any wonky times like 8888 which would be vertically, horizontally, and rotationally symmetric. Then I create 4-tuples of the possibilities.

hSym = Select[Tuples[horizontal, 4], validTimeQ];
vSym = Select[Tuples[vertical, 4],
validTimeQ[#] \[And] verticalSymmetryQ[#] &];
rotSym = Select[Tuples[rotatable, 4],
validTimeQ[#] \[And] rotationalSymmetryQ[#] &];


Finally, I downloaded the source code of the Wolfram Demonstration you linked to and re-used much of the code by Sean Madsen to print the digits.

separation = 0.03;
width = 0.1;
shear = 0;
display[list__] := (
GraphicsRow[
Table[
Graphics[
{RGBColor[.94, .91, .91], #[127], RGBColor[1, .2, 0], #[case]} &
@Function[code, Pick[Table[Polygon[
Function[{start,
end}, (Join[Table[start, {3}], Table[end, {3}]]
+
width {{-#2, -#1}, {0,
0}, {#1, -#2}, {#2, #1}, {0, 0}, {-#1, #2}} & @@
Sign /@ {#1 - #2, -#1 - #2} & @@ (end - start))]
[#[[n]] + separation (#[[n + 1]] - #[[n]]), #[[n + 1]] -
separation (#[[n + 1]] - #[[n]])]
.{{1, 0}, {shear, 1}}], {n, Length[#] - 1}] &
@{{0, 0}, {0, -1}, {1, -1}, {1, 0}, {0, 0}, {0, 1}, {1,
1}, {1, 0}}, IntegerDigits[code, 2, 7], 1]],
PlotRange -> {{-.25, 1.25}, {-1.3, 1.3}},
ImageSize -> {Automatic, 250}],
{case,
list /. {0 -> 119, 1 -> 17, 2 -> 107, 3 -> 59, 4 -> 29, 5 -> 62,
6 -> 126, 7 -> 19, 8 -> 127, 9 -> 31}}],
Spacings -> 0
]
)
display[vSym[[-1]]]


The largest time with vertical symmetry ends up being 22:55.

Because the number 1 is printed to one side of the number, I don't count it as being vertically or rotationally symmetric, but you may have your own idea about what should count.

Also, it turns out that I could have simply left 6 and 9 out of the list rotatable since you can't have a 6 or 9 in the first place or third place, which under rotation means you can't have a 6 or 9 in second or fourth place. Similarly with 8 for both vertical and rotational symmetry, it would require you to be able to put an 8 either in both of positions 1 and 4 or 2 and 3. I realized this about part-way through, but left them in since validTimeQ takes care of them for me.

• Much appreciated, great help and I learned a ton from your answer! – Tom De Vries Apr 1 '19 at 10:32