Skip to content

Instantly share code, notes, and snippets.

Avatar

Ricardo Bittencourt ricbit

View GitHub Profile
@ricbit
ricbit / recurrence.py
Created Apr 17, 2021
Expected number of packs to complete an album (linear)
View recurrence.py
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 Apr 17, 2021
Expected number of packs to complete an album
View matrix.m
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]]]]]
View Makefile
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
View birthpalin.py
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 Jul 22, 2019
Approximate resistor value "target" by using at most "max_resistors" from a given list of resistor values
View resistor.py
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 Mar 18, 2018
Count paths using brute force
View bruteforce.m
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 Mar 13, 2018
OEIS A300665 (Go)
View count_paths.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
View a300665.cc
// 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 {
View gist:df8803042063a2115700c7b1368a3cbc
#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