Skip to content

Instantly share code, notes, and snippets.

@jtpio
Last active December 7, 2015 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtpio/94bead0c4ff53912cd04 to your computer and use it in GitHub Desktop.
Save jtpio/94bead0c4ff53912cd04 to your computer and use it in GitHub Desktop.
MathJam Shout 2015-11-17 solution checker for the factorial puzzle
from math import factorial
# Calculate the product of factorials without 50!
# P = 1!2!3!4!...49!51!...98!99!100!
P = 1
for i in range(1, 101):
if i == 50:
continue
P *= factorial(i)
# Calculate the upper triangle
# * is used to show the numbers on the diagonal
# 2
# 3 2
# 4 3 2
# 5 4 3 *
# 6 5 * 3 2
# 7 * 5 4 3 2
# * 7 6 5 4 3 2
N = 100
A = 1
for i in range(2, N, 2):
p = (N - i) // 2
A *= (i ** p)
A *= ((i + 1) ** p)
square_root = A * (2 ** 25)
B = square_root ** 2
print('A (triangle product) =', A)
print('square_root = A * (2 ** 25) =', square_root)
print('')
print('B = (A * (2 ** 25)) ** 2')
print('P = 1!2!3!4!...49!51!...98!99!100!')
print('')
print('B =', B)
print('P =', P)
print('')
print('(A * (2 ** 25)) ** 2 == P?', B == P)
A (triangle product) = 28096349883404598089174618406697591339063729278760470524375815447930677728268054637723711781571533000589924279516684938800795391136686979696889986194040454583750899427115686326631405740305909751115327957219067038598369826352746302054406619686964827826350874070790677705547562491885702638977879633221491189235912983642182003359235345033464787592304119671495703555646547952045218424356576120659071929167130506605353650471917081531693573814754631958356249017091735946600018479535588865323201644866820727262268930927659027399754251864481640813770447714989077192429094669781977513809326851618374630233355596127174191776539933598318980770741329347410565163827288974168221092590320128325541924868171283731317299495810314221764382117932181181053281446107851865588401390247312894528011564801444125387716711114512670727601330970503288157953137987697749083049256668587683745452736217902601908191277407014991601807527362869635909997594198857361809130649875908614395234458562124951829409780878218364380431666995722452101832019285493022086120761521509507854573329275739442835357423010607876109354910000909098678536058017264627617659192425778605389772893311862339823781686833405304878856765138782355017312169184790423726498518241814972359797160079122946031536953648002745333732048940311139810697375496413278559029129856403057235252866357256816672816509086021852697964624378614885210024033871413171958954221832225772112474469122931484760463688938434179712502703578201779954801805167458709633256225919394803046385459602544900180872787632970303769163887360676144323283710501507418741933269942386714368478944936363015434385648808249416313149295145493653433999475765640716356021558602660022744857150167004420034974191625661131792078692192475844595778598139513463254471730089160357295439462075620603624806428113210607492792929679135672427917401985161717668389471235349471434525649763539264949573794421549662127446833100247484588969279995287143827033039609425749343887677535109370555734849870297290567207262184278308029297752890317051673022537803625381130088304698154961360698583541173241480358463904791636198259848736084293674438510169570545495513511629566320413087049594186506632825907262299756182448485572019028477702692997233918908157399452178548605125401020928277975978904634830606817136518560510583325406072501612105045380528236437114972656944102437443497224986508144507445947483958480922283195886509675440083323422658156150830665220707040541227327814600848726036545929902655994776268471005233955092454302121810344371601542526945720951955294886074258636348039799199539288861596591625091175351278385991242952395693507007902264661450821747935625291070713742675524272205107242386618024115903552828174447762849702257940246794354122735878163588589585402037432789770816281940719253778991479823400183885101590667721467183100778449128477921223752867995804634219786211276524552445735975578823410319360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
square_root = A * (2 ** 25) = 942757061610907515070539669453482673150402847750577252498172641892139466547084917113784921762340857204050574122191597644415450497809365965524675653228869238579557859765992252980283292977504307941936196098206094050090375649205033805536047220636122601690998212148908981304711708399729360971803811657115467047815574167538708363341233956921931939660412306837064923250100309291640542545219877193478624230347297219014889900711709621893667867404164894731691589419071491582145951270320308161444527614971885149112349008524831754071190860897622431934085151462156371396112971918761819312644118808402841480690274482068729770120868397209309554581147525177292184871211627628077331212287600604130670381138162304315192596355801473452825879798171354051332020660287580089959154437758923702163336146343650407121614018355559623067689383159246588272443827794820958160238635536671970274299146637550038351474460746820858683421753985548523006772394709153824523871370376984039939115763879639471663206092613078388754416500854613309924179566537764196063237236261707318659746666196408384336887846104677257575773891491624289790228018288360773402067371425703261605968044076139674977974593696793630996867563589243094228260003683545707181981128445740046628693341668045512254876566669060054114029342388342199620537958672865599306000923785846148592400306989661561584487802604302406867870527117775419967557162904030022401036227582335078995520925921504146054015138953841869638951517030928307772360244968741885196840971188970399973333750022339880065883653280943015841753355299467158717809280730516579671725454819458924980549701298937128708043714712286078719258729807396900582701897613839353399413178666970752310762594992538455762979134658215901760342615821361639131620458327631015856670363199085145965527340332990402127520805287613630795610848999339739256829366527773864507173062082489835485733367246494345080457313899867472478390094877603404811617655690822788018399889327782865408523691489754986875207230003099256121597508868537955844125457110946968802920979199177204603631173989521176440188093928616731472267412717785430983248612745226378366977127666163338032114431055492287791141315688758732128705873071143332440547302629293593761138528392561720097281705214962361029375120029468480222081789003908427964343746755390253472671932142413269122077848833609096626199290213038232081477998488452321268538526055938930048781116568621896345950119590359808429299662979383761855567696732785720079909919795437196112655624089094390240811593653740917113486689815508361373359209294726458363753029775534595499434800245115891337124546715812914241640534873738180002228654619685227079206712471470071377256055761017369292200171445881931387191596092460634302471124373395260677800418205219280857699998935150516872692232017912638313653478960137137151894565535586619618346971671203772393970202884212689480815776291370881482513290761569063403520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
B = (A * (2 ** 25)) ** 2
P = 1!2!3!4!...49!51!...98!99!100!
B = 888790877217232468274638364885415255661867660289075589701897016801651474139108506885723444036751970769638979776316769393826640059337202036618886100191556507543179203072473263746969745761495898941222173496085179328042282863957032277336655035403080200104090964601667422665735553476502510896827905107293162821298628813237616853697702321307251296379099706956344458360326599681460692064683526046141321524504153337056549576909595295015188480191226589603529005113464039489605248367282993129735761597662995492301602427381892417034257410118032404781612369986065657506394759432110967811875065348923066988335908854847794542936379127446801958954223447013969328503881523013076428970527001562856649526153227676245284223079551567809988653917073701409034771796413552511467576563286251697781024665645854950957923410835376032440818275235927487425387163526841784976488528364378550293394630442735728968325282882474977831999164203029009172925587035972162910299082693664522878053538794706712722801815205229787420745414727453367854042251485649623200296361337741481180632130434048231485566515446407706717450604023504326510106182667971893969290032334160300010844762730669750319490994122129525396878655262477548873333564181112881314816367770432658309368307740592841423212818066984003697722606487386666902825317735404541464600821566174453482083872771669545986011423864011032438922990578072170616797978918918702100032169926544891624228329126774678326025911694607900853697645179780195341214230374487690178364942548888066677683739342062158112101469016901290609665194462266959425621299428817142785201623266701060337453691017247383689374386309081124347151606816082617562216700396258706317586670416036268374339136620812210347805645896570823007186802999234289631698285902964063377127747710036055830430763894830390748804238200215989124473561250263918991570613688655341933926240251895160731907693739235588752291923123496187029918061595529318738761054456862670993956345614605801747075925726795700698403765795073244275014081039055566175954810480447031246425860158333360603106794500075490689323010633491550479233157434601426811123757521734189053769992802535491025392513971613607567236778318422167831066656046308111329689744557526228786754645863205908721190978757775668035170287349397022570924528198796195379630197032396265921720512892937839733579835234567835043577756735190254811821028021547373456308998495281365803581174824648700297037115402724956511619762364437592722979428381177914773719717400426084694814106397621880796340640594451421661297953604612714519468431263335163728790944010902477483039853479527575118388974390785931928835895792137293465518417869266633473032809691892108160533109070198357551334039597515677844903827275312356271099362122553461320115087042682396727890342816324633238211170478048247489220424492857538230157806030457630247264083887193442276905595224456019044621313232496608547402887100315029739731039865421651915507963932766647237180744421216173670643323239391677642264538887025930345940550015943561816586813408881796497441504738771745470055775478676321276468213523653745446686902232286581984743721646515072644466846971966024657523140495843604069551267389301676763344205839942451348078490329560156879676874475019023253702186693238343151393394457860086905304971266484964831767522163231574887719775186420111214377797289753793695627627387949750829204409557390396800193696602451251635870866586510748205754343551478284086421147617631715733207543134510668640830434310188344375445498772727552723198903976868812027947093979645843246841389998455502230037655563938229750099089380290012280310272009545253095812419824536499677088653995334579079936689399705026284517453167583756192772719685147958296570404067683932140917856414852077348098201653821917121995449266699705599612210052159418700288369315457264372839115334593757883885037980836828334675892978688324928795968138366907821695007240983674723276291849197895129081198287692183060763540088297477045444509281669302268901560151913076437965593800410427285099862534643728236381483309049813859259857998996333777407499192342163614448268709400667523922132557141069201557959094603337210405662220774218125685946664488050200954074370817770716240349881946282581515199756890096856864930309729594027370392643696726104874581162016816063629447224882102277571691204999988134669941792468924498958932297772918022999713077015985505408973714564461681554763360531900275796980828718901554243221665594248489562850306608992893643072983703239714653469828230180806337752638812409992995866896137033529492918557839428732625705474520202730021863856431750090420891727740074264014911877859811020392350933505029129342108319684371937317486176578552371417905048298080096697233743106159444745354317980189962166664505048912664527402077562116024448266493981915747118851125397466906380988673501712827882760896089412083988979187819413662852623653710594608246416587805927925836968177275038202377647523150621318144192523653519830300156466058402582272970320602622028946338779080223538581200392158588865526614815262946550822203998047333750971678639141014046403798617349970564887932246000556814484571643162839441684620665910390908097920597019010689342221308508386459214310725736815838350577131824711863739785190902960114723940237326466674896228417213014947058093519681872537562824970083125582688222412062335676871644415339774456812917915657784948479292431154776568153740884722721482615036023402248742770066372555925533296049471398037945953473197732159823524951840301265137216449511305671636690269709961293687062942170925618251288416477996596642361021862675757721035038036306101960589221003568047974445050664045690364547211084734723828055389637394439887557716526145134535461981376288219504991627042527958885342678360135304537149876127549406107493517055451072329503894914665766348390400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
P = 888790877217232468274638364885415255661867660289075589701897016801651474139108506885723444036751970769638979776316769393826640059337202036618886100191556507543179203072473263746969745761495898941222173496085179328042282863957032277336655035403080200104090964601667422665735553476502510896827905107293162821298628813237616853697702321307251296379099706956344458360326599681460692064683526046141321524504153337056549576909595295015188480191226589603529005113464039489605248367282993129735761597662995492301602427381892417034257410118032404781612369986065657506394759432110967811875065348923066988335908854847794542936379127446801958954223447013969328503881523013076428970527001562856649526153227676245284223079551567809988653917073701409034771796413552511467576563286251697781024665645854950957923410835376032440818275235927487425387163526841784976488528364378550293394630442735728968325282882474977831999164203029009172925587035972162910299082693664522878053538794706712722801815205229787420745414727453367854042251485649623200296361337741481180632130434048231485566515446407706717450604023504326510106182667971893969290032334160300010844762730669750319490994122129525396878655262477548873333564181112881314816367770432658309368307740592841423212818066984003697722606487386666902825317735404541464600821566174453482083872771669545986011423864011032438922990578072170616797978918918702100032169926544891624228329126774678326025911694607900853697645179780195341214230374487690178364942548888066677683739342062158112101469016901290609665194462266959425621299428817142785201623266701060337453691017247383689374386309081124347151606816082617562216700396258706317586670416036268374339136620812210347805645896570823007186802999234289631698285902964063377127747710036055830430763894830390748804238200215989124473561250263918991570613688655341933926240251895160731907693739235588752291923123496187029918061595529318738761054456862670993956345614605801747075925726795700698403765795073244275014081039055566175954810480447031246425860158333360603106794500075490689323010633491550479233157434601426811123757521734189053769992802535491025392513971613607567236778318422167831066656046308111329689744557526228786754645863205908721190978757775668035170287349397022570924528198796195379630197032396265921720512892937839733579835234567835043577756735190254811821028021547373456308998495281365803581174824648700297037115402724956511619762364437592722979428381177914773719717400426084694814106397621880796340640594451421661297953604612714519468431263335163728790944010902477483039853479527575118388974390785931928835895792137293465518417869266633473032809691892108160533109070198357551334039597515677844903827275312356271099362122553461320115087042682396727890342816324633238211170478048247489220424492857538230157806030457630247264083887193442276905595224456019044621313232496608547402887100315029739731039865421651915507963932766647237180744421216173670643323239391677642264538887025930345940550015943561816586813408881796497441504738771745470055775478676321276468213523653745446686902232286581984743721646515072644466846971966024657523140495843604069551267389301676763344205839942451348078490329560156879676874475019023253702186693238343151393394457860086905304971266484964831767522163231574887719775186420111214377797289753793695627627387949750829204409557390396800193696602451251635870866586510748205754343551478284086421147617631715733207543134510668640830434310188344375445498772727552723198903976868812027947093979645843246841389998455502230037655563938229750099089380290012280310272009545253095812419824536499677088653995334579079936689399705026284517453167583756192772719685147958296570404067683932140917856414852077348098201653821917121995449266699705599612210052159418700288369315457264372839115334593757883885037980836828334675892978688324928795968138366907821695007240983674723276291849197895129081198287692183060763540088297477045444509281669302268901560151913076437965593800410427285099862534643728236381483309049813859259857998996333777407499192342163614448268709400667523922132557141069201557959094603337210405662220774218125685946664488050200954074370817770716240349881946282581515199756890096856864930309729594027370392643696726104874581162016816063629447224882102277571691204999988134669941792468924498958932297772918022999713077015985505408973714564461681554763360531900275796980828718901554243221665594248489562850306608992893643072983703239714653469828230180806337752638812409992995866896137033529492918557839428732625705474520202730021863856431750090420891727740074264014911877859811020392350933505029129342108319684371937317486176578552371417905048298080096697233743106159444745354317980189962166664505048912664527402077562116024448266493981915747118851125397466906380988673501712827882760896089412083988979187819413662852623653710594608246416587805927925836968177275038202377647523150621318144192523653519830300156466058402582272970320602622028946338779080223538581200392158588865526614815262946550822203998047333750971678639141014046403798617349970564887932246000556814484571643162839441684620665910390908097920597019010689342221308508386459214310725736815838350577131824711863739785190902960114723940237326466674896228417213014947058093519681872537562824970083125582688222412062335676871644415339774456812917915657784948479292431154776568153740884722721482615036023402248742770066372555925533296049471398037945953473197732159823524951840301265137216449511305671636690269709961293687062942170925618251288416477996596642361021862675757721035038036306101960589221003568047974445050664045690364547211084734723828055389637394439887557716526145134535461981376288219504991627042527958885342678360135304537149876127549406107493517055451072329503894914665766348390400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
(A * (2 ** 25)) ** 2 == P? True
real 0m0.075s
user 0m0.000s
sys 0m0.015s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment