Rotational symmetry of string

A rotation "is made by splitting a string into two pieces and reversing their order". An object is symmetrical under an operation if the object is unchanged after applying said operation. So, a "rotational symmetry" is the fact that a string remains unchanged after "rotation".

Given a non-empty string s consisting of only letters from a to z, output the highest order of the rotational symmetry of the string.

Testcases:

input        output
a            1
abcd         1
abab         2
dfdfdfdfdfdf 6

This is . Shortest answer in bytes wins. Standard loopholes apply.

• Related. – Martin Ender May 19 '17 at 10:23
• previously asked as a CMC: chat.stackexchange.com/transcript/message/37509699#37509699 – John Dvorak May 19 '17 at 10:30
• This is the same as finding the number of symmetric rotations smaller than the size of the string. As @0' points out they form a cyclic group so finding the highest order is the same as finding the size of the group. This would make the explanation of the task which is currently pretty unclear much clearer. – Wheat Wizard Mar 10 '18 at 17:54

Retina, 15 bytes

(^.+?|\1)+#1

Try it online!

Matches the entire string by repeating a substring (shorter substrings are prioritised due to the ungreedy .+?) and replaces the entire string with the number of repetitions we used.

Test cases

let f =

s=>s.length/s.match(.+?)\\1*$.length console.log(f("a")) // 1 console.log(f("abcd")) // 1 console.log(f("abab")) // 2 console.log(f("dfdfdfdfdfdf")) // 6 • f=s=>s.length/s.match(.+?)\\1*$.length – l4m2 Mar 10 '18 at 18:00

Japt, 7 bytes

¬x@¥UéY

Test it online!

Explanation

¬ x@   ¥ UéY
q xXY{ ==UéY}  // Expanded
Uq xXY{U==UéY}  // Variable introduction
// Implicit: U = input string
Uq              // Split U into chars.
xXY{      }  // Map each item X and index Y by this function, then sum the results:
U==UéY   //   Return U equals (U rotated by Y characters).
// Implicit: output result of last expression

PHP, 66 Bytes

for(;strtr($a=$argn,[substr($a,0,++$i)=>""]););echo strlen($a)/$i;

Try it online!

PHP, 67 Bytes

preg_match('#^(.+?)\1*$#',$argn,$t);echo substr_count($argn,\$t);

Try it online!

C (gcc), 59 bytes

-Df(d,s)=for(d=n=strlen(s);n%d|memcmp(s,s+n/d,n-n/d);d--)

n;

Try it online!

• tio should be suggested so the complier flags can be decided added into the code length – l4m2 Mar 10 '18 at 18:21

g x=sum[1|a<-[1..length x],drop a x++take a x==x]

Try it online!