//// Counting adjacencies in random shuffles of large decks //Session file SetLogFile("adjR.log": Overwrite := true); //adjacency counter numADJ := function(sd); s := 0; n := #sd; for i := 1 to n-1 do if Abs(sd[i]-sd[i+1]) eq 1 then s := s+1; end if; end for; return s; end function; //define deck, set up "shuffle group", sample size n := 15; udeck := [1..n]; G := SymmetricGroup(n); numsamp :=5000; //average number of adjacencies nadj := 0; for i := 1 to numsamp do pi := Random(G); nadj := nadj+numADJ(udeck^(pi^(-1))); end for; avgADJ := nadj/numsamp; print "avgADJ = ",avgADJ; //probability of an adjacency a := 0; for i := 1 to numsamp do pi := Random(G); if numADJ(udeck^(pi^(-1))) gt 0 then a := a+1; end if; end for; probADJ := a/numsamp; print "probADJ = ",probADJ; //End Session UnsetLogFile();