Qual a probabilidade de ganhar a Mega-Sena da virada?

São 60 números possíveis, e uma aposta tem 6 números. A fórmula é combinação(60,6). Isto dá uma chance em 50 milhões.

Com mais apostas, melhor a probabilidade.

Na loteria, é possível marcar mais números na mesma cartela.

Digamos, com 7 dezenas assinaladas, há o equivalente à Combinação(7,6) apostas = 7 apostas. É como se eu preenchesse 7 cartelas individuais e as submetessem, e multiplico a minha chance de ganhar por 7 (e também o custo de jogar).

É o mesmo resultado calculado neste site: https://www.sorteonline.com.br/mega-sena/probabilidades

Segue planilha para download aqui, para quem quiser mexer.

Entrando nas formulinhas, para quem gosta.

Da análise combinatória:

Combinação(n,p)  = n! / (p! * (n-p)!)

Onde ! denota a função fatorial.

O Excel tem as funções combinação e fatorial pré-definidas, porém, é mais divertido reescrevê-las:

Function fact(n)

    If n = 1 Then

        fact = 1

    Else

        fact = n * fact(n – 1)

    End If

End Function

Esta é uma função recursiva, bastante poderosa. Porém, ela esbarra no limite do tipo double.

Ex. calcular fatorial(60) ele aguenta: 8,2*10^81.

Porém, calcular fatorial(2020) o VBA não aguenta:

O Python é melhor que o VBA para números grandes. Isto porque, no Python, o programa vai armazenando o número na quantidade de bytes necessária, até o limite da memória do computador.

def fator(n):

    if n == 1:

        return(1)

    else:

        return(n*fator(n-1))

print(“Fatorial “, fator(2020))

A função combinatória é só aplicar a fórmula, utilizando a função fatorial definida acima.

Em VBA:

Function comb(n As Long, p As Long)

comb = fact(n) / (fact(p) * fact(n – p))

End Function

Em Python:

def comb(n,p):

    return(fator(n)/(fator(p)*fator(n-p)))

Para fechar, 2020! é igual a:

386096951826724872377527755309254829575652833764136996704568320001962744375418996245016343070140495922821200614629613676056064037951380768693631095293969806083283419391122768593135371533669789505644746708636245286071667761717496505605794126236016354348784410240335472055757629538266448781423997420044753128592681490931155652500393981945786030349664533711594345568989302186320705026331591010701401806321162676014168267730443127229747356930582741007966787455099581158386524638372751639313267766129679555735375331455412649323831848690561911358863665291691253184884758093169216097558804246779418405854622335480512182276766264945125914275956103428084284556933827302002697216249895052496440541172520541257873419634034161103824199316296993063661010122247477806751684315159325496718242301326410047304634788457407629483612153384782033983257542806498117448100169850242485622135551834378243035590642352839055096183047501262709727667023809372071930180723811416036636750921242111077253225291490924545632327925057149716099795229733989622278323677405784299876565959582090676790727740307049077225508605566490968403536385735238912741726753153654163800192588170739101544001978507890178193666229850683801023093469605890012191345770905436000032556827322145416135640856057548854287333531160062595436210299154833029310707445362782649537335586073636441409352069691324058033881627521130303343921325446543099236423768017622330952822024309856222944411670467670029292434583401736238439303991700945727580238299750982559170548833139100553910689597287121942263594164151082680213395221663587816012606720015052645832622621471333102685422392447559330215438244237647008830170109515277728376740158127469507982306996887556451828368694363732003992198093879746125762368988032934128856143997941342867059780561839990632437177907064694382432079447096605996943877612866685823347086095028180222170710715928986388757360066746071573539728102642573049976996579847448174187164026466837941823296708220196587010386827277994485087677372620093957914089258169972214872563807439573846201771190457487767436383507920863265001158985530332683629614342467843804937221206800149726658420435494370022064907930073825842356140820286864504429150801511854514365890388184309207375633689423525046829286070427382305637485912596973375367419760345739950217980127302509287481854594278265427658981413690677647108075218848723615631183228998263867303745241836596694419145869217246024705077412378592333080136866437588005631900741990955327512376380828834010898865112109122200117679929527578871952101638590795253704401058529870302842722801768976320289167271902599225625767622305121280203492060037659871687735744553956446891872856397638184308752827275833141465241377237087280607247672227911921476510099466427100947464296939925307947903326972670620615266725024373992589830067802295068263706563543372266200657231075725406225813916087447037257516901879820294473007469699120258797394881069240769625444137446394025363698666039205630857709229029682411964627222481342313835400760000248298282014684789191216782161001313299389221096618273488723978734883910176473532912398103689047801184926163882078889516242948227926207222798398599415190198383379958023224921700008504785581886491831617089767423337158587605657695370924035915232465034278959481229277255278641922703818140279236081674495149412290836894544282115179683616118844191583046672479060000997496671880332878428953950612778358032083448023516233258828937364836898528863330898553728662430714476112310836556548819026772896916666672491022632933230082044594787660656479369609508622352899543941383995692550547567969679794689990261140429300073943357022253659335410345587776835600085239314982274092032142617241600285547606153599286848476863161163541783080974843391064827635422937416295803320652151693691769908939733927283127338535832997562295235291634892349205745118756949780889187123971284330764415768476973033998802916258114465575907763749305205635060986278491975514474464672254458806857234410272869494209351555904987662052843555593641077334735000243185871626166435489995567743531839402525319028777252590673740070657146817606781166399960411132861682002655514447098043836381875601009788125213646389121448684764478666800367960493084953255241805961090727464679546615218982157594620688546771982908471364789755878887707044374010944486692997646137003523014144478339200998768863760703237203498326237220307578035692438887844741169784356786186401985299971489879829923194004083856969480041497397289465262863214647978593940815429794201584815761969377077597754446250785589118819688309472535988847810731264852902520018791994847255177619133199103397784696304617128344478292442325121108591633318029061667864784808515527387560252024100796176430107903015131441779467272344895619105502295519265018507118428238756968370367729287885962903983789250413811180716741127223957387264111710541149510905192956624428207083391894030881029258437087456354854256388583861141432235437699695203894352189291895609764592583127247584093330090479305172063745326415499877435366649909958866611266850377258481988425964258871356114398124542854504460141256012894066714195604604296809443585918770552117029738264919661512180130075143844966812954224436082616963714987190523714733696955227936508156266340713059106114761487944040893851195897985233581632996731726844059926287692271399731200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Att

Um comentário em “Qual a probabilidade de ganhar a Mega-Sena da virada?

Deixe uma resposta para Arnaldo Gunzi Cancelar resposta

Faça o login usando um destes métodos para comentar:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Foto do Google

Você está comentando utilizando sua conta Google. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s