Skip to content

Instantly share code, notes, and snippets.

Darius Bacon darius

View GitHub Profile
View heh.py
"""
Try to sclambre wrods itno the msot porbable wrooddis *not* in the
lexcion. We optimize the priblitaboy unsig hlil-cimbling wtih random
restrat. The ruselt: pettry asuming. The pragrom: pettry solw.
"""
import collections
import operator
import random
import re
View hypervolumens.py
"""
Approximate unit hypersphere volumes by Monte Carlo sampling.
"""
from __future__ import division
from random import random
# Area of a unit circle, just to get started.
def area(trials):
# Sprinkle `trials` random points (x,y) where 0<=x<=1, 0<=y<=1.
View pooled_testing.py
"""
Evaluation of Group Testing for SARS-Cov-2 RNA.pdf
"""
from __future__ import division
import itertools, random
def runs(n, R, C, npositive):
return [run(R, C, npositive) for _ in range(n)]
View show_with_coalesced_runs.py
"""
Problem from David Albert
"""
from parson import Grammar
def repr_register_bits(bits):
return '/'.join(repr_bits('D', bits & 0xFF) + repr_bits('A', bits >> 8))
bitstring_grammar = Grammar(r"[/0*/ :position (/11+/ :position :many | /1/ :one)]*")
View show_with_coalesced_runs.py
"""
Problem from David Albert
'bumps' idea from Michael Arntzenius & Eugene Ha
"""
def repr_register_bits(bits):
return '/'.join(repr_bits('D', bits & 0xFF) + repr_bits('A', bits >> 8))
def repr_bits(label, bits):
bits = [(bits>>i) & 1 for i in range(8)]
View domification.py
# See https://gist.github.com/kragen/6bee5b4529cbde133050e9dc2e0b4b7e
from parson import Grammar
g = Grammar(r"""
_: {' ' | '\n' | '\t'}*.
digit: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'.
atom: :'<num>' {digit+ ('.' digit* | ) | '.' digit+} :'</num>' _ | {'('} _ a {')'} _.
e: :'<exp> <base>' atom :'</base>' {'**'} _ :'<pow>' atom :'</pow> </exp>' | atom.
m: :'<term>' e (:'<op>' {'/' | '*' | '%'} :'</op>' _ e)+ :'</term>' | e.
@darius
darius / aoc24.scm
Created Dec 25, 2018
advent of code 2018 day 24
View aoc24.scm
;; fails on the real input
(import (use "advent-utils")
simple-parser<-
grammar<- parson-parse feed)
(import (use "lib/pretty-print")
pp)
(import (use "lib/sort")
sort-by-key)
View aoc22.scm
;; Simple least-cost search was too slow.
(import (use "advent-utils")
simple-parser<- product<-)
(import (use "lib/memoize")
memoize)
(import (use "lib/pairing-heap")
priority-queues<-)
(let input (with-input-file '.read-all "advent22"))
@darius
darius / anotherparsonexample.py
Last active Jul 14, 2018
another parson example
View anotherparsonexample.py
from parson import Grammar
g = r"""
_: /\s*/.
ns: /[0-9]+/.
num: {ns ('.' ns | '.') | '.' ns | ns} _ .
e: num {'**'} _ num :to_prefix | num.
m: e {'/'|'*'} _ m :to_prefix | e.
a: m {'+'|'-'} _ a :to_prefix | m.
"""
You can’t perform that action at this time.