Skip to content

Instantly share code, notes, and snippets.

@possibly-wrong
possibly-wrong / sim_output.txt
Created January 31, 2017 02:45
Hi-Opt II sub-optimal index plays
(13, 7, 7, 9, 10, 7, 8, 12, 9, 29), 6-5 vs. 9 (100): hit, not double
(16, 17, 13, 14, 15, 12, 12, 12, 13, 60), 10-2 vs. 2 (100): stand, not hit
(14, 16, 18, 20, 13, 18, 16, 14, 18, 56), 6-1 vs. 3 (100): double, not hit
(11, 13, 14, 17, 9, 12, 12, 10, 11, 46), 9-3 vs. 5 (100): stand, not hit
(7, 12, 13, 15, 8, 9, 9, 10, 6, 41), 3-6 vs. 3 (100): hit, not double
(6, 10, 9, 14, 8, 8, 9, 10, 5, 40), 2-10 vs. 2 (100): stand, not hit
(3, 5, 9, 11, 6, 7, 8, 7, 4, 29), 6-3 vs. 2 (100): double, not hit
(24, 24, 24, 24, 24, 24, 24, 24, 24, 96), 2-10 vs. 4 (100): hit, not stand
(17, 21, 18, 17, 17, 20, 17, 20, 18, 67), 4-8 vs. 5 (100): hit, not stand
(9, 12, 13, 9, 11, 12, 13, 10, 9, 57), 7-3 vs. 10 (100): hit, not double
@possibly-wrong
possibly-wrong / clock.txt
Created August 27, 2017 19:55
Times when hour and minute hands may be swapped yielding another valid time
00:00:00.000 == 00:00:00.000
00:05:02.097 == 01:00:25.174
00:10:04.195 == 02:00:50.349
00:15:06.293 == 03:01:15.524
00:20:08.391 == 04:01:40.699
00:25:10.489 == 05:02:05.874
00:30:12.587 == 06:02:31.048
00:35:14.685 == 07:02:56.223
00:40:16.783 == 08:03:21.398
00:45:18.881 == 09:03:46.573
#include "blackjack_pdf.h"
#include <iostream>
int main()
{
int num_decks = 6;
bool h17 = false;
bool das = true;
bool ls = false;
mode = 2
# Convert integer to words.
if mode == 0:
units = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',
'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen',
'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
tens = ['zero', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty',
'seventy', 'eighty', 'ninety']
powers = ['zero', 'thousand', 'million', 'billion', 'trillion',
units = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',
'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen',
'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
tens = ['zero', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty',
'seventy', 'eighty', 'ninety']
powers = ['zero', 'thousand', 'million', 'billion', 'trillion',
'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion',
'nonillion', 'decillion']
hundred = 'hundred'
minus = 'minus'
1 [1]
2 [1, 2]
3 [1]
4 [3]
5 []
6 []
7 []
8 [6]
9 []
10 []
@possibly-wrong
possibly-wrong / skittles.py
Created December 19, 2019 17:08
Monte Carlo simulation of searching for duplicate packs of Skittles
import numpy as np
def sample():
"""Return number of random Skittles packs opened until first duplicate."""
packs = set()
count = 0
while len(packs) == count:
packs.add(tuple(np.bincount(
np.random.randint(0, 5, np.random.binomial(100, 0.6)))))
count = count + 1
@possibly-wrong
possibly-wrong / keycount_mod.c
Created October 25, 2020 12:51
6x6 Hotel Key Card Counter mod
/*
Ref: https://gist.github.com/skeeto/1718d6613dc47a7aff13333942a40776
*/
static long long
valid(long long x)
{
int v = 0;
long long a = transpose(x);
v += x == a;
a = flipv(a);
@possibly-wrong
possibly-wrong / chocolates.m
Last active December 4, 2020 20:59
Searching for chocolates
(* https://possiblywrong.wordpress.com/2015/02/08/searching-for-chocolates/ *)
d[n_, k_] := If[! (0 <= k <= n), 0,
Sum[
(-1)^j Binomial[k, j] (n - j)!,
{j, 0, k}
]
]
v[n_, k_] := v[n, k] = Which[
@possibly-wrong
possibly-wrong / chocolates.cpp
Created December 4, 2020 20:57
Searching for chocolates
// https://possiblywrong.wordpress.com/2015/02/08/searching-for-chocolates/
#include "math_Rational.h" // https://github.com/possibly-wrong/precision
#include <vector>
#include <map>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <ctime>