Skip to content

Instantly share code, notes, and snippets.

View lambda-fairy's full-sized avatar

Chris Wong lambda-fairy

View GitHub Profile
@lambda-fairy
lambda-fairy / eko.cpp
Created January 31, 2013 00:28
Eko solution
// Eko <http://nztrain.com/problems/56>
#include <cstdio>
#include <climits>
using namespace std;
long long total_wood(int *trees, size_t n_trees, int sawblade) {
long long total = 0;
for (size_t i = 0; i != n_trees; ++i) {
if (trees[i] > sawblade) {
"""
=============================
The Epic Fail Guessing Game
=============================
The Epic Fail Guessing Game (*efguess*) is a simple number guessing game.
Except you can't win it, of course. That would be silly.
"""
@lambda-fairy
lambda-fairy / read.py
Last active December 14, 2015 07:48 — forked from anonymous/read.py
Simple input loop demonstrating higher-order functions
"""
Simple input loop thing, with ducks.
By Lambda Fairy (github.com/lfairy)
Examples::
n = read(int, 'Enter a number: ')
MIN = 1
@lambda-fairy
lambda-fairy / gist:5471926
Created April 27, 2013 04:56
Fenwick trees
#!/usr/bin/env python3
class Fenwick:
"""A specialized data structure for representing range sums."""
def __init__(self, size, identity=0):
self.tree = [identity] * (size + 1)
self.identity = identity
@lambda-fairy
lambda-fairy / NotStatistics.hs
Created May 22, 2013 00:45
Definitely not statistics
import qualified Data.Sequence as S
import Data.Foldable (toList)
movingMean :: Int -> [Double]
slices :: Int -> [a] -> [[a]]
slices k ys = case takeMaybe k xs of
Nothing -> []
Just start -> start : loop (S.fromList start) ys
where
@lambda-fairy
lambda-fairy / SUPER_AWESOME_ENCODER_THINGY.py
Last active December 19, 2015 04:39
SUPER AWESOME ENCODER THINGY
"""
========================================================================
SUPER AWESOME ENCODER THINGY
------------------------------------------------------------------------
BY LAMBDA FAIRY COPYRIGHT BLAH BLAH BLAH DON'T COPY OR YOU WILL
>>>>>>>> DIIIIIIIIIIIIIIIIIIIIEEEEEEEEEEEEEEEEEEEE <<<<<<<<
========================================================================
"""
@lambda-fairy
lambda-fairy / scott.py
Last active December 19, 2015 10:39
Scott encoding in Python
"""Great Scott!"""
import sys
sys.setrecursionlimit(4000)
fix = lambda f: lambda x: f(fix(f))(x)
zero = lambda z: lambda s: z
succ = lambda x: lambda z: lambda s: s(x)
# plus, times are faster when the second argument is small
@lambda-fairy
lambda-fairy / names.txt
Created July 9, 2013 06:00
A whole bunch of generated variable names
__
_a
_b
_c
_d
_e
_f
_g
_h
_i
@lambda-fairy
lambda-fairy / PeanoAxioms.agda
Last active December 19, 2015 17:09
Peano axioms in Agda
-- http://en.wikipedia.org/wiki/Peano_axioms
module PeanoAxioms where
data ⊥ : Set where -- empty
data ℕ : Set where
-- [1] 0 is a natural number.
zero : ℕ
-- [6] For every natural number n, S(n) is a natural number.
@lambda-fairy
lambda-fairy / log.c
Last active December 19, 2015 18:18
Simple logging system in C
#include <stdio.h>
#include "log.h"
void
PLog_printf(const char *type, const char *filename, unsigned int line, const char *fmt, ...) {
va_list vl;
va_start(vl, fmt);
fprintf(stderr, "%s:%u: %s: ", filename, line, type);
vfprintf(stderr, fmt, vl);
putc('\n', stderr);