[Question]
  [
# Introduction
You can skip this part if you already know what a cyclic group is.
A group is defined by a set and an associative binary operation \$\times\$ (that is, \$(a \times b) \times c = a \times (b \times c)\$. There exists exactly one element in the group \$e\$ where \$a \times e = a = e \times a\$ for all \$a\$ in the group (**identity**). For every element \$a\$ in the group there exists exactly one \$b\$ such that \$a \times b = e = b \times a\$ (**inverse**). For every two elements \$a, b\$ in the group, \$a \times b\$ is in the group (**closure**).
We can write \$a^n\$ in place of \$\underbrace{a\times a\times a\times ...\times a}\_{n \text{ times}}\$.
The cyclic subgroup generated by any element \$a\$ in the group is \$<a> = \{e, a, a^2, a^3, a^4, ..., a^{n-1}\}\$ where \$n\$ is the order (size) of the subgroup (unless the subgroup is infinite).
A group is cyclic if it can be generated by one of its elements.
# Challenge
Given the Cayley table (product table) for a finite group, determine whether or not it's cyclic.
# Example
Let's take a look at the following Cayley table:
```
1 2 3 4 5 6
2 3 1 6 4 5
3 1 2 5 6 4
4 5 6 1 2 3
5 6 4 3 1 2
6 4 5 2 3 1
```
(This is the Cayley table for Dihedral Group 3, \$D\_3\$).
This is 1-indexed, so if we want to find the value of \$5 \times 3\$, we look in the fifth column on the third row (note that the operator is not necessarily commutative, so \$5 \times 3\$ is not necessarily equal to \$3 \times 5\$. We see here that \$5 \times 3 = 6\$ (also that \$3 \times 5 = 4\$).
We can find \$<3>\$ by starting with \$[3]\$, and then while the list is unique, append the product of the last element and the generator (\$3\$). We get \$[3, 3 \times 3 = 2, 2 \times 3 = 1, 1 \times 3 = 3]\$. We stop here with the subgroup \$\{3, 2, 1\}\$.
If you compute \$<1>\$ through \$<6>\$ you'll see that none of the elements in the group generate the whole group. Thus, this group is not cyclic.
# Test Cases
Input will be given as a matrix, output as a truthy/falsy decision value.
```
[[1,2,3,4,5,6],[2,3,1,6,4,5],[3,1,2,5,6,4],[4,5,6,1,2,3],[5,6,4,3,1,2],[6,4,5,2,3,1]] -> False (D_3)
[[1]] -> True ({e})
[[1,2,3,4],[2,3,4,1],[3,4,1,2],[4,1,2,3]] -> True ({1, i, -1, -i})
[[3,2,4,1],[2,4,1,3],[4,1,3,2],[1,3,2,4]] -> True ({-1, i, -i, 1})
[[1,2],[2,1]] -> True ({e, a} with a^-1=a)
[[1,2,3,4,5,6,7,8],[2,3,4,1,6,7,8,5],[3,4,1,2,7,8,5,6],[4,1,2,3,8,5,6,7],[5,8,7,6,1,4,3,2],[6,5,8,7,2,1,4,3],[7,6,5,8,3,2,1,4],[8,7,6,5,4,3,2,1]] -> False (D_4)
[[1,2,3,4,5,6],[2,1,4,3,6,5],[3,4,5,6,1,2],[4,3,6,5,2,1],[5,‌​6,1,2,3,4],[6,5,2,1,‌​4,3]] -> True (product of cyclic subgroups of order 2 and 3, thanks to Zgarb)
[[1,2,3,4],[2,1,4,3],[3,4,1,2],[4,3,1,2]] -> False (Abelian but not cyclic; thanks to xnor)
```
You will be guaranteed that the input is always a group.
You may take input as 0-indexed values.
  
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~11 10~~ 9 bytes
```
VS≡`ȯU¡!1
```
1-based.
Returns the index of a generator if one exists, 0 otherwise.
[Try it online!](https://tio.run/##ZVC7DcJADO2ZAjqQ3Nwnl@yBoDmdRImEaIgYADrGyAR0DJCKObLIYT9bRIjmfO/Zfs/28dqf6vK87qf77bIZX3W/nR7D4f3cjcPK1VpzduQpUKSGUqEsf0dJMCP5e8lQZIQaMIERWFR7RuiAkitlwar6qrbpRs6JZrSeaFpSGfineUQ4IKISkXVME1U/DpispW52UmxbqBMwtjRnxdRim47zsl00z0TKeeWYkbxwQTlmtKfRnv@JdE5k03cSuyGmAI9Oved8L@PhXD4 "Husk – Try It Online")
## Explanation
```
V          Does any row r of the input satisfy this:
      ¡!    If you iterate indexing into r
   `    1   starting with 1
    ȯU      until a repetition is encountered,
 S≡         the result has the same length as r.
```
[Answer]
# [J](http://jsoftware.com/), 8 bytes
```
1:e.#@C.
```
[Try it online!](https://tio.run/##hVBLCsIwEN33FA9dFEGK@TQNwYLgNRQXYhE3Lrr27DHJTNKoCxd56ft0ZjIPP80YHXYIxwt369aHY@c3zapDO42uxRYvh2lumtv1/sSEvcPF4HyCgISCRg@TvkS4I1PJ6RMjl5KkkEvJ9FddV6S6taLrToSCUTKqn7wq3pKOGqGu8zLXl5997fcLB9jSn1hf5iBm8jzMhoA2YHy/Tp0NK5KVgRXFimWF0uLPxqmG4TnynrMW/WX3umjB9/4N)
## Explanation
```
1:e.#@C.  Input: matrix M
      C.  Convert each row from a permutation to a list of cycles
    #@    Number of cycles in each row
1:        Constant function 1
  e.      Is 1 a member of the cycle lengths?
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~13~~ 11 bytes
```
ị"⁸$ÐĿ«/E€Ẹ
```
[Try it online!](https://tio.run/##bVC7DcJADO2ZAiFKSyh3l88CTHG6kgZlAUpoKGjYAwaIoEAiLJIsctjPJkiIyn7P9nu2t5u23eU83E@Lcd8t@/Pr8bys1uPhOty63B85yTnGWJAjT4FKqhJFyQuqBDOS3EmFAiP0gPGMwKLbMcIElIqUaDZn3U9UfdMOXBfdYHPB9LTXc64diPBBRC8iK0266PvxwY41NV8/xXaP@gHjXvNXTDXuargudwbzrUg5pxwzUhfOK8eMzpQ6828n3RX1atrF/ok9wGNWf/v9m/HwTukN "Jelly – Try It Online")
[Answer]
## JavaScript (ES6), 52 bytes
```
a=>a.some(b=>!a[new Set(a.map(_=>r=b[r],r=0)).size])
```
[Answer]
# [Python 2](https://docs.python.org/2/), 96 91 97 bytes
```
lambda x:any(g(r,r[i],i+1)==len(r)for i,r in enumerate(x))
g=lambda x,y,z:y==z or 1+g(x,x[y-1],z)
```
[Try it online!](https://tio.run/##XVHLboQwDDzDV3BMtO4hgX0IKV@SRhVtA0Xaza4ClYCfp7HNslIPyJnxzGDLj3n8uQe9tuZ9vTa3z@@mmOomzKITEaLtHfQHJY25@iCibO@x6CF9ofDh9@ZjM3oxSZl35mmGGZZ6NmYpklYdOjHBZOc35WCR6@iH8eOrGfxQmMLmmbUKNJRQwRFODiy@FZwQJ4RvjR2oEiINMWVCxJJaJ0QOSlLOAeU@K@dv2VXqY261@aotb9eS7p@X/nuGyyuD8TYjZxCmHbZMxnCmWS@pj7PjxDwvc5q5xGAfuZK5xLDnyJ59JnzzFlTJS5VyqSY3azXpcCuXZy7H4@0HwBO@rlHn2SP2YRSt2Ekp1z8)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 bytes
```
JŒ!ị@€µṂ⁼Jṙ'’$$
```
[Try it online!](https://tio.run/##ATQAy/9qZWxsef//SsWSIeG7i0DigqzCteG5guKBvErhuZkn4oCZJCT///9bWzEsMl0sWzIsMV1d "Jelly – Try It Online")
First silly idea that came to mind: check for isomorphism to **Zn**. (This code is *O*(n!)…)
```
JŒ!ị@€             Generate all ways to denote this group.
                     (by indexing into every permutation of 1…n)
      µṂ⁼          Is the smallest one equal to this?
         Jṙ'’$$      [[1 2 …  n ]
                      [2 3 …  1 ]    (the group table for Z_n)
                      [… … …  … ]
                      [n 1 … n-1]]
```
[Answer]
# [R](https://www.r-project.org/), ~~101~~ 97 bytes
```
function(m)any(sapply(1:(n=nrow(m)),function(x)all(1:n%in%Reduce(`[`,rep(list(m[x,]),n),x,T,T))))
```
[Verify all test cases](https://tio.run/##jVHLboMwELznKyJLkdbS9sAjJKqaT@gl4uYghaYQIRGDDLTk6@l67RBVatpyMTPrmZ1dm6kfjE6b/Wvem2pcvjwty0Gf@qrR0Mkeurxt6ysUH3kNbW66AvrduRveQBwOmUAhBd6gIlhXXQ8CO0kfDtpCKReLknyn2fcic329OQfPoHfaNJ9ES5zvjDKvayrqVaVX@@J9OBVwVEc0RQvc5KJGzCRqiSOmmNqGUwnfhgGhVIAhRhjjGpMMlf0PMLGYkP0PbQVjQnyHmYgQs3w7JMQKdgqyTNBEP3V6XHEZfP@YPGzv2HvHvucjdURVp@GT0/HJaj7J@5ferPwzHU@/we09pcN@Uy4lY96kT@0wbnhjW6rbDcY@W4KOCx1HjK1bLnIcMU6zdpr/pXTzsCKZ0/m342TMs5t7x/v@Pc9pbKfpCw "R – Try It Online")
This simply computes `<g>` for each `g \in G` and then tests if `G \subseteq <g>`, then checks if any of those are true. However, since we're always applying `$g` on the right, we replicate `m[g,]` (the `g`th row) and then index into that row with the result of applying `$g`, accumulating the results rather than using `m[g,g$g]` every time, which saved about 4 bytes.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
JịƬ"ZẈiL
```
[Try it online!](https://tio.run/##bVKxTsMwEN37FSdYiHQZkrihEmJAQgyIkalRQE4a2kAUV04iqFAXFpDYmPiI/gAwIviP8iPBPrs0FIbIfs@@957vcpkVxaxtj5dvj5@LreHy9SE/ad/vv@4WH0/Ll@e2jXpR5KGPATLsYxhjpPcehhorpPe@PkGmEN0hJlCIWLrtK0QVpOTFMcI2HPGiymDn8DxwtIkhT2WjuNts7qyNrSlThdqQWUFmjbp1HkKO4KrFzUkiUFdMIa2Ui1aSoFUZdCVcq6E@b5WCyjcSIvA5XOf1BPiZ6@1z53encBcH6@AG246Z4ISpo/YhBuMudW6gznUnmU0aouF8wylGn2suMJxiTE3f1PzpMnP@GaUxCH@C2fFRKOJJyIxyPQ3LU5BOT6ZSjJq0BnEB6Swt8hSqJhlL0UwrzQk5yiT4wMsRBAj1hJdXFdQChmMuk815r57Znbf5lbrPOkiyIuclJE0Npait715H/KYU0unF3w "Jelly – Try It Online")
Outputs `0` for False and a non-negative integer for True
Jelly finally ties J!
## How it works
```
JịƬ"ZẈiL - Main link. Takes the Cayley matrix n×n M on the left
    Z    - Transpose M
J        - Yield [1, 2, ..., n]
  Ƭ      - Until reaching a fixed point, do the following and replace i with the result
   "     -   Pair each i (intially 1,2...,n) with each row, then do the following:
 ị       -     Take the i'th element of each row
     Ẉ   - Get the length of each
       L - Yield n
      i  - Index of n in the lengths, or 0 if not present
```
[Answer]
## Clojure, 68 bytes
```
#(seq(for[l % :when(apply distinct?(take(count l)(iterate l 0)))]l))
```
[Answer]
# [Python 2](https://docs.python.org/2/), 82 bytes
```
lambda A:len(A)in[len(set(reduce(lambda a,c:a+[A[a[-1]][n]],A,[n])))for n in A[0]]
```
[Try it online!](https://tio.run/##fVJNb4MwDD2PX@Ej0TypSWCVkHbIpX8iy4EV0JDatKL0sF/PEuIkRfs44Tw/Pz/bXL/mz4sVy/D2vpza80fXgmpOvS0VG632wa2fy6nv7se@JEKLx6Z91kq3@oUbo60xqNB9GGPDZQILowWld8YsXT/AwWk1xdN1Gu0MCmFw76I4lFrvEDiCQJAIFUJtEHQAXKYOsMcCwAPJwR6T8UUiHqtiFRV4rI7qJGwMC71TkEzk9tITQ2OZpWRuRrVifUY2j2yR2YJqKfRdHvpS1S9e4nSvCPutrwTn5SRjBNMqs98EOwotar@yw/5k9lmvvJDkKekzgR2SIiV9JklVSeqfmeLMkVtv5sg3pQlEVOa05c3VyUFmkN@/bvswz4/bxp/G1S7f "Python 2 – Try It Online")
0-indexed Cayley table is input; True/False output for cyclic/non-cyclic group.
]