facets := n-> Immutable(Filtered(Cartesian([1..n],[1..n],[1..n],[1..3]), f->f[f[4]] in [1,n]));; twister := function(n,layer,dirn) local x,y; x := dirn mod 3 + 1; y := x mod 3 + 1; return function(facet) local res, t; if facet[dirn] <> layer then return facet; fi; res := ShallowCopy(facet); t := res[y]; res[y] := res[x]; res[x] := n+1 - t; if res[4] = x then res[4] := y; elif res[4] = y then res[4] := x; fi; MakeImmutable(res); return res; end; end; move := function(n, layer, dirn) local f; f := facets(n); return PermListList(f, List(f, twister(n, layer, dirn))); end; CubeGroup := function(n) return GroupByGenerators(List(Cartesian([1..n],[1..3]), pair -> move( n, pair[1], pair[2] ))); end; RestrCubeGroup := function(n) local layers; layers := [1..(n-1)/2]; Append(layers,[(n+3)/2..n]); return GroupByGenerators(List(Cartesian(layers,[1..3]), pair -> move( n, pair[1], pair[2] ))); end;