This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
======================================================================== | |
SUPER AWESOME ENCODER THINGY | |
------------------------------------------------------------------------ | |
BY LAMBDA FAIRY COPYRIGHT BLAH BLAH BLAH DON'T COPY OR YOU WILL | |
>>>>>>>> DIIIIIIIIIIIIIIIIIIIIEEEEEEEEEEEEEEEEEEEE <<<<<<<< | |
======================================================================== | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Simple input loop thing, with ducks. | |
By Lambda Fairy (github.com/lfairy) | |
Examples:: | |
n = read(int, 'Enter a number: ') | |
MIN = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
============================= | |
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. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wormholes <http://nztrain.com/problems/98> | |
#include <algorithm> | |
#include <cstdio> | |
#include <vector> | |
using namespace std; | |
// This can't be INT_MAX -- adding anything to INT_MAX would cause it to | |
// overflow and become negative. | |
// Kudos to Alan Ansell for pointing that out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def max_index(items, start, end): | |
best_item = None | |
best_index = None | |
for index, item in zip(range(start, end), items[start:end]): | |
if best_item is None or item > best_item: | |
best_item = item | |
best_index = index | |
if best_index is None: | |
raise ValueError('maximum of empty sequence') | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from random import randint | |
def simulate(): | |
"""Simulate one round of the game Gus described.""" | |
pushes = 1 | |
# Until a kitten pops out | |
while randint(0, 99) != 0: | |
# Push the button |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Simple implementation of Kruskal's algorithm using a disjoint set""" | |
from collections import namedtuple | |
Edge = namedtuple('Edge', 'weight start end') | |
class DisjointSet: | |
def __init__(self, key): |