|
aaronla
|
|
codepad
|
|
|
aaronla
|
Saved pastes by aaronla:
def arith2 (input):
@memo_unyield
def expr (Return, input):
if (yield [0,1]):
x = yield factor(input)
|
| view (55 lines) |
# compute pythagorean triples using nondeterministic choice
# skip ahead to the 'pythag' function
import time
c0 = time.clock()
|
| view (44 lines, 7 lines of output) |
static Tuple<TimeSpan, long> PerfTest(Action<long /*iterations*/> unitUnderTest)
{
long n = 100;
var sw = new StopWatch();
|
| view (22 lines) |
static IEnumerable<T> Anonerator(
Func<Func<T, Task>, Task> iteratorator
)
{
T current = default(T);
|
| view (19 lines) |
def def_struct(name, *fields):
c = "class %s(object):\n" % name
c+= " def __init__(self" + ''.join(',%s'%f for f in fields) + "):\n"
c+= (''.join(
" self.%s=%s\n"%(f,f) for f in fields) if fields else
|
| view (13 lines, 2 lines of output) |
g = Grammar()
g['expr'] = g['addend'] & pRep(pLiteral('+') & g['addend'])
g['addend'] = g['factor'] & pRep(pLiteral('*') & g['factor'])
g['factor'] = g['number'] | g['parenthetic']
g['number'] = reduce(pOr, (pLiteral(c) for c in '0123456789'))
|
| view (30 lines) |
#include <time.h>
#include <sys/times.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
|
| view (74 lines, 2 lines of output) |
/* simple tuples */
#define LISTSIZE(S) LISTSIZEx S
#define LISTSIZEx(...) LISTSIZExx(__VA_ARGS__, 5,4,3,2,1)
#define LISTSIZExx(a,b,c,d,e,N, ...) N
|
| view (11 lines, 2 lines of output) |
? #define A(X, Y) Y X
? #define B 1 ## 2 ## 3
? .singlestep A(B, 2)
current: [1 ## 2 ## 3] in A( _ , 2 )
? step
|
| view (14 lines) |
reverse = (lambda g: (lambda f: g(lambda *arg: f(f)(*arg))) (
lambda f: g(lambda *arg: f(f)(*arg))))(
lambda r: lambda s: s[-1] + r(s[:-1]) if len(s) > 0 else "")
print reverse("hello")
|
| view (4 lines, 1 line of output) |
def evalit(s):
print "%r => %r" %(s, eval(s, globals(), globals()))
evalit("0 == False")
evalit("type(0) == type(False)")
|
| view (5 lines, 2 lines of output) |
def evalit(s):
print "%r => %r" %(s, eval(s, globals(), globals()))
print "consistent inequivalence:"
evalit("1 == '1'")
|
| view (11 lines, 7 lines of output) |
using System;
using System.Runtime.InteropServices;
using System.Drawing;
namespace ConsoleApplication1
|
| view (46 lines) |
# simplified monadic packrat (almost CFG) parser
# derived from parse6.py, added (lazy) backtracking
#
# parser :: str -> [ (value, str) ]
class lcons (object):
|
| view (140 lines, 22 lines of output) |
# simplified monadic (PEG) parser. no memoization, some backtracking.
# parser :: str -> maybe (value, str)
def ret (value):
return lambda s: (value, s)
|
| view (98 lines, 16 lines of output) |
from parse import *
from test1 import timeit
def group(p):
return p % (lambda v: ('group', v))
|
| view (31 lines) |
# first, some boilerplate
class Seq:
def __init__(self, defer):
self._defer = defer
def force(self):
|
| view (53 lines, 6 lines of output) |
# first, some boilerplate
class Seq:
def __init__(self, defer):
self._defer = defer
def force(self):
|
| view (56 lines, 6 lines of output) |
#include <iostream>
template <typename T> struct Base {
void f(int) {
std::cout << "Base<T>::f\n";
|
| view (23 lines, 1 line of output) |
#include <iostream>
template <typename T> struct Base {
void f(int) {
std::cout << "Base<T>::f\n";
|
| view (23 lines, 2 lines of output) |
typedef int HRESULT ;
bool SUCCEEDED(HRESULT x){return(x)>=0;}
HRESULT f(){return 0;}
#define g f
#define h f
|
| view (38 lines) |
// in reference to http://hbfs.wordpress.com/2011/08/09/programming-challenge-luminance/
#include <iostream>
#include <iomanip>
using namespace std;
|
| view (66 lines, 2 lines of output) |
#! python
# digraph.txt used: http://jnicholl.org/Cryptanalysis/Data/DigramFrequencies.php
import math
|
| view (42 lines, 4 lines of output) |
;; QR card for scheme
;; (c) 2011 Aaron Lahman
;; r5rs load module
(load {filename-string})
|
| view (152 lines) |
def adds_dynamic_z_decorator(f):
def replacement(*arg,**karg):
# create a new 'z' binding in globals, saving previous
if 'z' in globals():
oldZ = (globals()['z'],)
|
| view (42 lines, 9 lines of output) |
/// answer to question on blog post
/// http://eli.thegreenplace.net/2008/12/22/an-rc-circuit-puzzle/
///
/// From the exercise, Eli said "But the current through the capacitor
/// and resistor is the same current". I'm not sure where you get this
|
| view (11 lines) |
struct to_listoftuples
{
template <class OuterContainerType>
static PyObject* convert(OuterContainerType const& a)
|
| view (18 lines) |
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
template <class It>
|
| view (28 lines, 1 line of output) |
#include <iostream>
#include <iomanip>
#include <set>
#include <algorithm>
#include <iterator>
|
| view (40 lines, 5 lines of output) |
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <iterator>
|
| view (40 lines, 5 lines of output) |
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
using namespace std;
|
| view (25 lines, 5 lines of output) |
#include <iostream>
#include <iomanip>
#include <iterator>
#include <vector>
using namespace std;
|
| view (25 lines, 5 lines of output) |
#include <iostream>
using namespace std;
template <int I, bool Fizz = !(I % 3), bool Buzz = !(I % 5)> struct number {};
template <int I> void fizzbuzz(number<I, false, false>){ cout << I << "\n"; }
template <int I> void fizzbuzz(number<I, true, false>){ cout << "Fizz\n"; }
|
| view (21 lines, 100 lines of output) |