Skip to content

Instantly share code, notes, and snippets.

View ricbit's full-sized avatar

Ricardo Bittencourt ricbit

View GitHub Profile
@ricbit
ricbit / recurrence.py
Created April 17, 2021 01:42
Expected number of packs to complete an album (linear)
import math
evalue = [0] * 181
norm = math.comb(180, 4)
for i in range(1, 181):
ans = math.comb(i, 0) * math.comb(180 - i, 4 - 0) / norm
for k in range(1, 5):
if i - k >= 0:
px = math.comb(i, k) * math.comb(180 - i, 4 - k) / norm
@ricbit
ricbit / matrix.m
Created April 17, 2021 01:38
Expected number of packs to complete an album
row[n_] := Table[
Binomial[n, 4-(k-n)] Binomial[180-n, k-n] / Binomial[180, 4],
{k, 0, 180}]
m = Table[row[k], {k, 0, 180}]
r = m[[1;;180, 1;;180]]
Print[N[Total[Inverse[IdentityMatrix[180] - r][[1]]]]]
KERNELDIR=/lib/modules/`uname -r`/build
#ARCH=i386
#KERNELDIR=/usr/src/kernels/`uname -r`-i686
MODULES = db9.o
obj-m += db9.o
all:
make -C $(KERNELDIR) M=$(PWD) modules
def to_base(n, base):
ans = []
while n > 0:
ans.append(n % base)
n //= base
return ans
def is_palin(n):
return n == n[::-1]
@ricbit
ricbit / resistor.py
Created July 22, 2019 01:57
Approximate resistor value "target" by using at most "max_resistors" from a given list of resistor values
import itertools
import sys
from fractions import Fraction
def split_integer(n):
for a in range(1, 1 + n // 2):
yield a, n - a
def resistor_pairs(n, cur_list):
for a, b in split_integer(n):
@ricbit
ricbit / bruteforce.m
Last active March 18, 2018 18:09
Count paths using brute force
count[graph_, pos_, 0] := 1
count[graph_, pos_, size_] := Sum[
If[graph[[i, pos]] == 1, count[graph, i, size - 1], 0],
{i, 1, Length[graph]}]
@ricbit
ricbit / count_paths.go
Created March 13, 2018 12:23
OEIS A300665 (Go)
// Number of n-step paths made by a chess king, starting from the corner of an infinite chessboard, and never revisiting a cell.
// OEIS A300665
// Ricardo Bittencourt, March 13 2018
package main
import "fmt"
type Grid struct {
grid []bool
@ricbit
ricbit / a300665.cc
Created March 11, 2018 16:39
OEIS A300665
// Number of n-step paths made by a chess king, starting from the corner of an infinite chessboard, and never revisiting a cell.
// OEIS A300665
// Ricardo Bittencourt, March 11 2018
#include <iostream>
#include <vector>
using namespace std;
struct Grid {
#define STATE_CAPA 0
#define STATE_RACE 1
#define STATE_CAPA_FADEIN 2
#define STATE_CAPA_FADEOUT 3
#define STATE_SELECT 4
#define STATE_CHAR_SELECT 5
#define STATE_DRAW_TRACK 6
#define STATE_SHOP 7
#define STATE_CREDITS 8
#define STATE_PODIUM 9