solutions to https://golf.cucats.org/contest/8/problems
rotate a matrix m clockwise n times.
f=lambda m,n:m*(n<1)or[*zip(*f(m,n-1)[::-1])]solutions to https://golf.cucats.org/contest/8/problems
rotate a matrix m clockwise n times.
f=lambda m,n:m*(n<1)or[*zip(*f(m,n-1)[::-1])]| partition[n_,l_]:=partition[n,l]=FrobeniusSolve[ConstantArray[1,l],n]; | |
| coeff=Compile[{{r,_Real},{l,_Integer},{succ,_Integer},{g,_Integer}},(r^(succ-g)*(1-r)^(11-succ))/l^succ] | |
| cycle[r_,a_:1][n_Integer,t_List]:=(*arguments | |
| r_ rate (fixed) | |
| a_ add (what are we counting by?) default 1=#steps. should be the same (cycle) | |
| n_ number of r5s to reach | |
| t_ current state | |
| *) | |
| Which[n<=0,0,(*reached goal*) |
| partition[n_,l_]:=partition[n,l]=IntegerPartitions[n+l+1,{l+1}]-1 | |
| coeff=Compile[{{r,_Real},{l,_Integer},{v,_Integer},{g,_Integer}},(r/l)^(11-g-v)*(1-r)^v*(1/l)^g] | |
| cycle[r_,a_:1][n_,t_]:=(*arguments | |
| r_ rate (fixed) | |
| a_ add (what are we counting by?) default 1=steps. should be the same (cycle) | |
| n_ number of r5s to reach | |
| t_ current state | |
| *) | |
| Which[n<=0,0,(*reached goal*) |
| PartitionsOf[n_,l_]:=PartitionsOf[n,l]=Flatten[Permutations/@IntegerPartitions[n+l+1,{l+1}]-1,1] | |
| PartitionsBy[n_,l_,f_]:=PartitionsBy[n,l,f]=Select[PartitionsOf[n,l],f@*Most] | |
| CaseWeight[state_]:=CaseWeight[state]=Multinomial@@state(*cache multinomials*) | |
| ExpectedCycle[n_,t_,r_,a_:1]:=(* | |
| n_ number to reach | |
| t_ current state | |
| r_ rate (fixed) | |
| a_ add (what are we counting?) default 1=steps *) | |
| Module[{st=Sort@t,mt=Min@t,l=Length@t}, |
| FilterBy[m_]:=Cases[x_/;m[Total@Most@x]] | |
| PartitionsOf[n_,l_]:=PartitionsOf[n,l]=Flatten[Permutations/@IntegerPartitions[n+l+1,{l+1}]-1,1] | |
| CycleExpectedMulti[n_,t_,r_,a_:1]:=(* | |
| n_ number to reach | |
| t_ current state | |
| r_ rate (fixed) | |
| a_ add (what are we counting?) default 1=steps*) | |
| Module[{st=Sort@t,mt=Min@t,l=Length@t},(*self explanatory*) |