Skip to content

Instantly share code, notes, and snippets.

View kmorel's full-sized avatar

Kenneth Moreland kmorel

View GitHub Profile
@kmorel
kmorel / SYourNeighbor.py
Created July 22, 2014 20:39
A Python script to compute the odds of a game of Screw Your Neighbor (a.k.a. Ranter-Go-Round) by trying all possible combinations of deals.
#! /usr/bin/env python
opponent_switch_threshold = 8
dealer_pulls_threshold = 10
def opponent_switches(dealer_card, opponent_card):
"""Given that the dealer and opponent have the given cards, returns
(dealer_win, opponent_win, tie) as the odds for each outcome if the opponent
switches with the dealer."""
if dealer_card == 13:
@kmorel
kmorel / BLECarDrag.bas
Created January 25, 2014 17:33
A techBASIC program for controlling an RC car via a RedBearLabs BLE shield on an Arduino running firmata and a jumpered motor shield.
! This app uses the accelerometer to control a car hacked to use the
! RedBear BLE Shield and an Arduino.
redBearUUID$ = "713D0000-503E-4C75-BA94-3148F18D941E"
txUUID$ = "713D0003-503E-4C75-BA94-3148F18D941E"
! The reason I am putting a button over the drag area is because I want to fill
! it with a gradient representing the speed and direction, and the button is the
! only GUI element I know of that can draw a gradient. Unfortunately, to get
! the drag events, I have to disable the button, which messes up the colors.
@kmorel
kmorel / birthdays.csv
Created September 15, 2013 03:24
A result file for the birthday problem simulator (https://gist.github.com/kmorel/6567225). For a given number of people (up to 1000), it gives the probability of having 2, 3, 4, 5, and 6 people with the same birthday.
# People 2 analytic 2 same 3 same 4 same 5 same 6 same
1 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
2 0.002740 0.002720 0.000000 0.000000 0.000000 0.000000
3 0.008204 0.007900 0.000010 0.000000 0.000000 0.000000
4 0.016356 0.015900 0.000050 0.000000 0.000000 0.000000
5 0.027136 0.026810 0.000090 0.000000 0.000000 0.000000
6 0.040462 0.039790 0.000150 0.000000 0.000000 0.000000
7 0.056236 0.055430 0.000240 0.000000 0.000000 0.000000
8 0.074335 0.072730 0.000380 0.000000 0.000000 0.000000
9 0.094624 0.092950 0.000590 0.000000 0.000000 0.000000
@kmorel
kmorel / birthdays.py
Created September 15, 2013 01:13
A Python script to estimate the probabilities of the birthday problem (http://en.wikipedia.org/wiki/Birthday_problem) for subgroups of size 2, 3, 4, 5, and 6 that have the same birthday.
import random
maxBirthdays = 6
numDays = 365
numTrials = 100000
maxGroupSize = 1000
def BirthdayExperiment():
birthdays = [0] * numDays
numToDuplicates = {}