8
1
The Dihedral group \$D_3\$ represents the symmetries of an equilateral triangle, using the identity (represented by id
), rotations (represented by r1
and r2
), and reflections (represented by s0
, s1
, and s2
).
Your task is to compute the composition \$yx\$ of the elements \$x, y \in D_3 \$. They are given by the Cayley table below:
x id r1 r2 s0 s1 s2
y +-----------------------
id | id r1 r2 s0 s1 s2
r1 | r1 r2 id s1 s2 s0
r2 | r2 id r1 s2 s0 s1
s0 | s0 s2 s1 id r2 r1
s1 | s1 s0 s2 r1 id r2
s2 | s2 s1 s0 r2 r1 id
Input
Any reasonable input of x
and y
. Order does not matter.
Output
y
composed with x
, or looking up values in the table based on x
and y
.
Test Cases
These are given in the form x y -> yx
.
id id -> id
s1 s2 -> r1
r1 r1 -> r2
r2 r1 -> id
s0 id -> s0
id s0 -> s0
Notes on I/O
You may use any reasonable replacement of id, r1, r2, s0, s1, s2
, for example 1, 2, 3, 4, 5, 6
, 0, 1, 2, 3, 4, 5
, or even [0,0], [0,1], [0,2], [1,0], [1,1], [1,2]
(here the first number represents rotation/reflection and the second is the index).
can u explain this code? – tarit goswami – 2018-09-16T09:07:29.067
1@taritgoswami Both
o
andO
are three-element lists containing a permutation of the integers0, 1, 2
. In the list comprehension, the former is indexed by the latter, implementing permutation composition. – Jonathan Frech – 2018-09-16T10:25:16.883