Puzzles/LCM

From J Wiki
Jump to: navigation, search

Find an interesting use of *./ on a list of integers with length greater than 2.

Solution:

The LCM of the cycle lengths of a permutation p is period of p , the size of the subgroup generated by p . For example:

   ] p=: ?.~ 23
4 22 16 15 18 14 7 8 0 21 3 13 20 9 11 19 6 17 2 5 1 10 12
   C. p
┌──┬─────────────────┬──────────────────────────┬──────────┐
│17│18 2 16 6 7 8 0 4│21 10 3 15 19 5 14 11 13 9│22 12 20 1│
└──┴─────────────────┴──────────────────────────┴──────────┘
   #&> C. p
1 8 10 4
   *./ #&> C. p
40
   # ~. {/\ (100,#p)$p
40
   p&{^:40 i.#p
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22



Contributed by Roger Hui.