{- Number of combinations of a NxN Rubik's cube and variations. Copyright 2016 Ken Takusagawa This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . -} {-# LANGUAGE ScopedTypeVariables, LambdaCase #-} module Main where { import System.Environment(getArgs); import Data.Function((&)); import Math.Combinatorics.Exact.Factorial(factorial); main :: IO(); main = getArgs >>= \case{ ["cube",n] -> read n & cube & print; ["supercube",n] -> read n & supercube & print; ["supersupercube",n] -> read n & super_supercube & print; ["megaminx",n] -> read n & megaminx & print; _ -> error "bad arguments"; }; -- http://www.speedcubing.com/chris/cubecombos.html div_exact :: Integer -> Integer -> Integer; div_exact x y = case divMod x y of { (q,0) -> q; _ -> error "division had a remainder"; }; common :: Integer -> Integer -> Integer -> Integer; common i den_base n = let { e1 :: Integer; e1 = div (n*n - 2*n) 4; e2 :: Integer; e2 = div ((n-2)^2) 4; numerator :: Integer; numerator = (24 * 2^i * factorial 12)^(mod n 2) * factorial 7 * 3^6 * (factorial 24)^e1; denominator :: Integer; denominator = den_base ^ e2; } in div_exact numerator denominator; -- https://oeis.org/A075152 cube :: Integer -> Integer; cube = common 10 ((factorial 4)^6); -- https://oeis.org/A080660 supercube :: Integer -> Integer; supercube = common 21 2; -- https://oeis.org/A080659 super_supercube :: Integer -> Integer; super_supercube n = let { e1 :: Integer; e1 = div_exact (n^3-4*n+(mod n 2)*(12 - 9*n)) 24; e2 :: Integer; e2 = div (n-2) 2 + mod n 2; e4 :: Integer; e4 = mod n 2 * div n 2; } in (div_exact (factorial 24) 2)^e1 * 24^e2 * (factorial 7 * 3^6)^(div n 2) * (factorial 12 * 2^21)^e4; -- http://michael-gottlieb.blogspot.com/2008/05/number-of-positions-of-generalized.html -- n=1 megaminx; n=2 gigaminx; etc. megaminx :: Integer -> Integer; megaminx n = div_exact (factorial 30 * factorial 20 * (factorial 60)^(n^2-1) * (factorial 5)^(12*n) * 2^28 * 3^19) ((factorial 5)^(12*n^2) * 2^n); -- agrees with results of http://twistypuzzles.com/~sandy/forum/viewtopic.php?f=1&t=24058 } --end