This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def random_deck(): | |
# initialize cards deck | |
cards = numpy.array([card for card in itertools.product(range(nfeatures), | |
repeat=ndims)]).T | |
n = cards.shape[1] | |
# shuffle | |
return cards[:, numpy.random.permutation(n)] | |
ncards = 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_sets3(cards, indices=None): | |
nd, n = cards.shape | |
c0 = cards[0, :] | |
if indices is None: | |
indices = numpy.arange(n) | |
groups = [(c0 == f).nonzero()[0] for f in range(nfeatures)] | |
# equals | |
solequal = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_sets2(cards): | |
ndims, ncards = cards.shape | |
all_features = set([0, 1, 2]) | |
# solutions contain the indices of the cards forming sets | |
solutions = [] | |
# iterate over all pairs | |
for idx1, idx2 in itertools.combinations(range(ncards - 1), 2): | |
c1, c2 = cards[:, idx1], cards[:, idx2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_sets(cards): | |
"""Brute-force Sets solver.""" | |
return [indices | |
for indices in itertools.combinations(range(cards.shape[1]), 3) | |
if is_set(cards, indices)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
import inspect | |
from traits.api import * | |
from traits import trait_notifiers | |
class ChangeEventPrinter(object): | |
def __init__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget | |
from IPython.frontend.qt.kernelmanager import QtKernelManager | |
from IPython.frontend.qt.inprocess_kernelmanager import QtInProcessKernelManager | |
from IPython.kernel.zmq.ipkernel import Kernel | |
from IPython.kernel.inprocess.ipkernel import InProcessKernel | |
from IPython.lib import guisupport | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enable.api import Component, ComponentEditor | |
from enable.events import KeyEvent | |
from traits.api import HasTraits, Instance, Str, Bool, Any | |
from traitsui.api import Item, View, VGroup | |
import wx | |
from pyface.qt import QtCore, QtGui | |
import enable.wx.constants as wx_constants | |
class KeyEventComponent(Component): |