Last active
September 29, 2018 06:11
-
-
Save oyyq99999/7f8ba73a4e52f710fa1551fb1ed93c66 to your computer and use it in GitHub Desktop.
a simple script to calculate cube states
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from math import factorial | |
from sys import argv | |
F4 = factorial(4) # 4 same-look centerpieces | |
F8 = factorial(8) # 8 corners | |
F12 = factorial(12) # 12 midges | |
F24 = factorial(24) # 24 wings/centers | |
P3_8 = 3 ** 8 # corner twists | |
P2_12 = 2 ** 12 # midge flips | |
CORNER_STATES = P3_8 * F8 | |
MIDGE_STATES = P2_12 * F12 | |
CENTER_STATES_PER_GROUP = F24 // (F4 ** 6) | |
WING_STATES_PER_GROUP = F24 | |
def calc(n): | |
even = (n % 2 == 0) | |
centerGroupCount = ((n - 2) ** 2) // 4 | |
wingGroupCount = (n - 2) // 2 | |
states = ( | |
# centers | |
CENTER_STATES_PER_GROUP ** centerGroupCount | |
# wings | |
* WING_STATES_PER_GROUP ** wingGroupCount | |
# corners | |
* CORNER_STATES | |
# midges if exists | |
* (1 if even else MIDGE_STATES) | |
# 24 orientations * 3 corner twists for even-order cubes | |
# 2 midge flips * 3 corner twists * 2 permutations for odd-order cubes | |
// (72 if even else 12)) | |
return states | |
class OrderError(Exception): | |
pass | |
def main(): | |
MIN_ORDER = 2 | |
MAX_ORDER = 200 | |
try: | |
order = int(argv[1]) | |
if order < MIN_ORDER or order > MAX_ORDER: | |
raise OrderError('Order should between {} and {}'.format(MIN_ORDER, MAX_ORDER)) | |
except OrderError as e: | |
print(e) | |
return | |
except ValueError as e: | |
print('Wrong order: ' + argv[1]) | |
return | |
except: | |
print('Usage: python {} cube_order'.format(__file__)) | |
return | |
print(calc(order)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment