Skip to content

Instantly share code, notes, and snippets.

from functools import update_wrapper
def decorator(d):
return lambda fn: update_wrapper(d(fn), fn)
decorator = decorator(decorator)
@decorator
def n_ary(f):
"""Given binary function f(x, y), return an n_ary function such
@ReitenSchnell
ReitenSchnell / gist:3078169
Created July 9, 2012 18:45
Udacity PS2-2 Recurrence Relation
import math
import random
import pylab
class Node(object):
def __init__(self):
self.links = []
class RecursiveGraph(list):
def add_nodes(self, nodes):
@ReitenSchnell
ReitenSchnell / gist:3078173
Created July 9, 2012 18:46
Udacity PS2-2 Recurrence Relation
import math
import random
import pylab
class Node(object):
def __init__(self):
self.links = []
class RecursiveGraph(list):
def add_nodes(self, nodes):
@ReitenSchnell
ReitenSchnell / Prime factor kata
Created August 29, 2012 08:04
Prime factors kata
Although quite short, this kata is fascinating in the way it shows how ‘if’ statements become ‘while’ statements as the number of test cases increase. It’s also a wonderful example of how algorithms sometimes become simpler as they become more general.
1. Write a class named “PrimeFactors” that has one method: generate. The generate method takes an integer argument and returns a List<Integer>. That list contains the prime factors of argument in numerical sequence.
2. Write test and code for argument = 1. Result should be empty list.
3. Write test and code for argument = 2. Result should be [2].
4. Write test and code for argument = 3. Result should be [3].
5. Write test and code for argument = 4. Result should be [2,2].
6. Write test and code for argument = 6. Result should be [2,3].
7. Write test and code for argument = 8. Result should be [2,2,2].
8. Write test and code for argument = 9. Result should be [3,3].
10;20;30;40
@ReitenSchnell
ReitenSchnell / gist:5998938
Created July 15, 2013 10:19
BlockingCollection with priorities
public class PriorityCollection
{
private readonly BlockingCollection<Item> low = new BlockingCollection<Item>();
private readonly BlockingCollection<Item> middle = new BlockingCollection<Item>();
private readonly BlockingCollection<Item> high = new BlockingCollection<Item>();
private readonly BlockingCollection<Guid> main = new BlockingCollection<Guid>();
private readonly BlockingCollection<Item>[] queue;
private readonly Dictionary<Priority, BlockingCollection<Item>> priorityMap = new Dictionary<Priority, BlockingCollection<Item>>();
public List<Priority> TestList { get; private set; }
@ReitenSchnell
ReitenSchnell / gist:6675ef564be4aaf55513
Created June 25, 2015 13:34
Тестовое задание

По ссылке http://tinyurl.com/qyot9y2 расположен текстовый файл. Из этого файла необходимо удалить все символы, оставив лишь те, которые встречаются относительно редко (используйте базовые знания статистики, чтобы определить что такое для данного файла "редко"). На выходе получится фраза, которая и будет результатом выполнения задания.