#C28.txt, May 5, 2025 Help28:=proc(): print(` Pri(pi,k,j), SUC(pi,k), EstSUC(n,k,K) `):end: with(combinat): PriNuray:= proc(pi, k, j) local c, i : c:=1: i:= j: while pi[i] <> j and c <= k do c:= c+ 1: i:= pi[i]: od: if c <= k then print(`SUCCESS!`): return true: else print(`FAIL!`): return false: fi: end: #From Nick OneCycleEGF := proc(n, x) local k; add(x^k/k, k = 1 .. n); end proc: ExpCoeffs := proc(F, n, x) local S, k; S := series(exp(F), x = 0, n+1); [seq(coeff(S, x, k) * k! , k = 0 .. n)]; end proc: F:=OneCycleEGF(50,x): cof:=ExpCoeffs(F,100,x): number_of_permutations:=cof[101]: #number of permutations with only cycles length <= 50 p:=number_of_permutations / (100!): print(evalf(p)); #end from Nick # Currently set to spit out true or false. You can have it return k0 to see how many attempts it actually took. #By Omar Garcia Pri:=proc(pi,k,j) local j0,k0: j0 := pi[j]: k0:= 1: while (k0 <= k) and (j0 <> j) do j0 := pi[j0]: k0+=1: od: if k0 > k then return(false): else return(true): fi: end: PriAurora := proc(pi,k,j) local g,c: g := 0: # number of guesses c := pi[j]: # current locker while g < k do if c = j then RETURN(TRUE) fi: c := pi[c]: g++: od: FAIL: end: #SUC(pi,k): for a permutation pi representing nops(pi) prisoners, and each allowed to look at k boxes, #does it succeed SUC:=proc(pi,k) local j: if coeff(add(Pri(pi, k, j), j=1..nops(pi)),true) = nops(pi) then return(true): else return(false): fi: end: #Code by Salman Manzoor SUCsalmans:=proc(pi,k) local i: for i from 1 to nops(pi) do if not Pri(pi,k,i) then RETURN(false): fi: od: true: end: #EstSUC(n,k,K), estimates the prob. of success with n prisoners and k tries doing it K times EstSUC:=proc(n,k,K) local i: evalf(coeff(add(SUC(randperm(n),k),i=1..K),true)/K): end: