Introduzione:
Un cubo di Rubik 3x3x3 ha possibili permutazioni, che è di circa 43 quintilioni . Potresti aver sentito parlare di questo numero prima, ma come viene effettivamente calcolato?
Un cubo di Rubik 3x3x3 ha sei lati, ciascuno con nove adesivi. Osservando i pezzi (esterni) invece degli adesivi, abbiamo sei pezzi centrali; pezzi di otto angoli; e dodici pezzi di bordo. Poiché i centri non possono essere spostati, possiamo ignorarli nei calcoli. Per quanto riguarda gli angoli e i bordi:
- Ce ne sono ( ) modi per disporre gli otto angoli. Ogni angolo ha tre possibili orientamenti, sebbene solo sette (degli otto) possano essere orientati indipendentemente; l'orientamento dell'ottava / ultima curva dipende dalle sette precedenti, date ( ) possibilità.
- Ce ne sono () modi per disporre i dodici bordi. La metà daè perché i bordi devono essere sempre in unapermutazione uniformeesattamente quando gli angoli sono. Undici bordi possono essere capovolti in modo indipendente, con il capovolgimento del dodicesimo / bordo finale a seconda degli undici precedenti, date().
Mettendo insieme questo, abbiamo la seguente formula:
Fonte: Wikipedia - permutazioni del cubo di Rubik
Anche se questo può già sembrare piuttosto complesso, è ancora piuttosto semplice per un cubo 3x3x3. Per i cubi pari la formula è leggermente diversa; questa è la formula per un cubo 4x4x4 ad esempio:
Che è circa 7,40 quattuordecilioni sulla scala corta .
E per i cubi NxNxN più grandi (ovvero l'attuale record mondiale 33x33x33) la formula verrà estesa un po '. Per non rendere questa introduzione troppo lunga, ho inserito qui questi collegamenti, in cui le spiegazioni del cubo 4x4x4 e di altri cubi NxNxN di dimensioni sono spiegate con una formula risultante:
Ormai ti starai chiedendo: esiste una formula generale basata su per qualsiasi cubo x x ? Certamente c'è. Ecco tre algoritmi completamente diversi, tutti con gli stessi esatti risultati basati su :
1: Formula di Chris Hardwick:
2: formula di Christopher Mowla:
3: Christopher Mowla's primes Formula:
where is .
Source: Cubers-reddit - Mathematical Counting Formulas of Number of Positions, God's Number, etc.
Challenge:
Choose and implement one of these three formulas (or your own derivative), which given an input-integer in the range , outputs the correct result.
Challenge rules:
- You are free to use another formula besides these three, but keep in mind that these three are proven to be correct. If you use another formula, please add a link of where you got it from (or if you come up with it yourself add an in-depth explanation). And I will check for all integers in the range if the output is correct. Perhaps inspiration could be found in the oeis for this sequence: A075152.
- If your language automatically outputs a scientific output (i.e. instead of the number after the 4x4x4 formula) this is allowed. But please add additional code to your answer to convert this scientific rounding to an exact output so the results can be verified, since rounding errors due to floating point precision during the execution of the formula in your code is not allowed - the actual result should be exact.
- Your program/function should be correct for at least the inputs in the range (although, since already results in a huge-ass number, any larger will probably work as well if you're able to output this one correctly).
- You are not allowed to loop over all possible permutations with a counter, since that would never output anything in a reasonable amount of time. Only the implementation of a formula (either one of the three provided, a derivative of one of those, or a completely new formula), or another method that will give the correct results in a reasonable amount of time (without hard-coding of course) is allowed. I thought about adding a restricted-time to enforce this, but I'm personally against restricted-time in combination with code-golf, so I won't. Still, please make sure your program gives the answers, and if it's too slow for TIO for some reason, add some screenshots with the output from your local machine as verification.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Here the test cases for in the range (feel free to use the WolframAlpha links above for larger test cases):
n=2
3674160
n=3
43252003274489856000
n=4
7401196841564901869874093974498574336000000000
n=5
282870942277741856536180333107150328293127731985672134721536000000000000000
n=6
157152858401024063281013959519483771508510790313968742344694684829502629887168573442107637760000000000000000000000000
n=7
19500551183731307835329126754019748794904992692043434567152132912323232706135469180065278712755853360682328551719137311299993600000000000000000000000000000000000
n=8
35173780923109452777509592367006557398539936328978098352427605879843998663990903628634874024098344287402504043608416113016679717941937308041012307368528117622006727311360000000000000000000000000000000000000000000000000
n=9
14170392390542612915246393916889970752732946384514830589276833655387444667609821068034079045039617216635075219765012566330942990302517903971787699783519265329288048603083134861573075573092224082416866010882486829056000000000000000000000000000000000000000000000000000000000000000
n=10
82983598512782362708769381780036344745129162094677382883567691311764021348095163778336143207042993152056079271030423741110902768732457008486832096777758106509177169197894747758859723340177608764906985646389382047319811227549112086753524742719830990076805422479380054016000000000000000000000000000000000000000000000000000000000000000000000000000000000
NOTE: Since this is a code-golf challenge, it basically boils down to: implement one of these three formulas (or a derivative / your own method that still produces the correct results) as short as possible.
floor
s.