Skip to content

Instantly share code, notes, and snippets.

@MarcPer
MarcPer / coin_toss_power.py
Created April 6, 2024 17:26
Coin tossing statistics
# Power analysis for coin tossing
# H1: coin is rigged (p1 > 0.5). Probability of heads in the alternative hypothesis.
# H0: coin is fair (p0 = 0.5). Probability of heads in the null hypothesis.
import math
import itertools
def binom_coeff(n, k):
return math.factorial(n) / (math.factorial(k) * math.factorial(n - k))
@MarcPer
MarcPer / main.rb
Created February 6, 2022 19:43
Wordle with segfault
def parse_vec file
v = {}
file.split("\n").each do |s|
arr = s.split(":")
v[arr[0]] = arr[1].gsub("[", "").gsub("]", "").split(",").map(&:to_i)
end
v
end
def parse_inv file

Keybase proof

I hereby claim:

  • I am marcper on github.
  • I am marcper (https://keybase.io/marcper) on keybase.
  • I have a public key ASATXI5AwqNDiD5GQhh1DkyrSZjNlMp4I4OUnRacviwdKgo

To claim this, I am signing this object:

@MarcPer
MarcPer / orderTasks.js
Last active December 9, 2015 14:42
Group tasks by priority and apply.
function orderTasks(num) {
var out = {},
fib, i = 0,
sum = idx = ct = 0,
tasks = Array.apply(null, {length: num}).map(Number.call, Number).reverse(); // http://stackoverflow.com/a/20066663
while (sum < num) {
idx++;
sum += getFib(idx);
}
@MarcPer
MarcPer / validateCnpjCpf.js
Last active September 17, 2015 15:50
JavaScript function that validates check digits for Brazilian CPF and CNPJ numbers
// Validates last two digits of a CPF or CNPJ
// Validation rules taken from http://ghiorzi.org/DVnew.htm
function validateCnpjCpf(value, type) {
var cpf = (type === "cpf"),
docLength = cpf ? 11 : 14,
chkLast;
if (value == null || value == "") {
return true;
}
@MarcPer
MarcPer / index.html
Created August 7, 2015 22:23
Code from Play by Play: HTML, CSS, and JavaScript with Lea Verou (with minor corrections)
<!DOCTYPE html>
<html lang="eng">
<head>
<meta charset="utf-8">
<title>Conway's Game of Life</title>
<link rel="stylesheet" href="style.css">
</head>
<body>