Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a vectorized version, where 1M hands can be calculated in about a minute. I got about 28:1 with it, so there might still be something a little off with finding 'all different' sets. My guess is that this is what your solution has trouble with, as well.</p> <pre><code>%# initialization K = 12; %# cards to draw NF = 4; %# number of features (this is hard-coded to 4) nIter = 100000; %# number of iterations %# each card has four features. This means that a card can be represented %# by a coordinate in 4D space. A set is a full row, column, etc in 4D %# space. We can even parallelize the iterations, at least as long as we %# have RAM (each hand costs 81 bytes) %# make card space - one dimension per feature, plus one for the iterations cardSpace = false(3,3,3,3,nIter); %# To draw cards, we put K trues into each cardSpace. I can't think of a %# good, fast way to draw exactly K cards that doesn't involve calling %# unique for i=1:nIter shuffle = randperm(81) + (i-1) * 81; cardSpace(shuffle(1:K)) = true; end %# to test, all we have to do is check whether there is any row, column, %# with all 1's isEqual = squeeze(any(any(any(all(cardSpace,1),2),3),4) | ... any(any(any(all(cardSpace,2),1),3),4) | ... any(any(any(all(cardSpace,3),2),1),4) | ... any(any(any(all(cardSpace,4),2),3),1)); %# to get a set of 3 cards where all symbols are different, we require that %# no 'sub-volume' is completely empty - there may be something wrong with this %# but since my test looked ok, I'm not going to investigate on Friday night isDifferent = squeeze(~any(all(all(all(~cardSpace,1),2),3),4) &amp; ... ~any(all(all(all(~cardSpace,1),2),4),3) &amp; ... ~any(all(all(all(~cardSpace,1),3),4),2) &amp; ... ~any(all(all(all(~cardSpace,4),2),3),1)); isSet = isEqual | isDifferent; %# find the odds fprintf('odds are %5.2f:1\n',sum(isSet)/(nIter-sum(isSet))) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload