Skip to content

Instantly share code, notes, and snippets.

View rgrig's full-sized avatar

Radu Grigore rgrig

View GitHub Profile
\documentclass{article}
%include polycode.fmt
\begin{document}
> import Array
> import Data.Bits
> import Data.Char
> import Data.Function
> import qualified Data.IntSet as IS
import qualified Data.IntMap as M
import Maybe
fillBin capacity ws@(w:ws') weight count
| newWeight > capacity = (ws, weight, count)
| otherwise = fillBin capacity ws' newWeight (succ count)
where newWeight = weight + w
go period capacity bins weights acc state seen
| bins == 0 = acc
solution time [s] memory [bytes]
peter.hs .163 7479296
radu.hs .160 7495680
duncan.hs 176.97 7467008
tim.hs .160 7471104 Files out and out.ref differ
nicolas.lhs .460 19001344 Files out and out.ref differ
lennart.hs 2134.98 7467008 Files out and out.ref differ
This was run in /dev/shm (that is, not using the HDD) on a computer with two cores at 4788 bogomips each (Intel i3 @2.4GHz), and 4GB of RAM.
cache = dict() # cache[x] is a map from weights to paths s->x
s = 0 # source
def find(t):
if t in cache: return cache[t]
if t == s:
return dict([(0,[s])])
r = dict()
for (x, w) in pred(t):
for (ww, path) in find(x):
class Benchmark {
public final boolean run() {
if (++iteration == 1) prepare();
if (validateOutput) {
System.setOut(out); // this is where System.out is redefined
out.openLog();
}
try { iterate(); }
finally {
if (validateOutput) {
diff -r e5fa13aae1cc Python/bltinmodule.c
--- a/Python/bltinmodule.c Tue Dec 31 06:52:47 2013 -0500
+++ b/Python/bltinmodule.c Wed Jan 01 15:46:01 2014 +0000
@@ -1559,14 +1559,15 @@
equivalent to (x**y) % z, but may be more efficient (e.g. for ints).");
-
static PyObject *
builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
beginfig(1)
path digit;
numeric d;
string digit_string;
u := 5mm;
max_base = 10;
max_num = 99;
digit_string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
color c_d[];
@rgrig
rgrig / nontrans_dice_5.txt
Created June 25, 2014 08:28
nontransitive triples of dice with 5 faces
22225 13333 11444
23333 12255 11444
23333 22225 11444
33333 12255 11444
33333 22225 11444
33333 22235 11444
33333 22245 11444
33333 22255 11444
33333 22255 11445
33333 22255 12444
@rgrig
rgrig / A.java
Created July 3, 2014 07:45
getOnlyElement
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class A {
public static <T> T getOnlyElement(Iterable<T> xs, Optional<T> e, Optional<T> xx) {
Iterator<T> i = xs.iterator();
if (!i.hasNext()) {
if (e.isPresent()) return e.get();