aaronla
|
codepad
|
|
aaronla
|
Saved pastes by aaronla:
def g(f, y, all_legal_inputs_to_f):
"returns x for y = f(x)"
for x in all_legal_inputs_to_f:
if y == f(x):
return x
|
view (15 lines, 11 lines of output) |
// hypothetical C# async sequencing
interface IAsyncEnumerable<out T>
{
IAsyncEnumerator<out T> GetEnumerator(CancellationToken token);
|
view (86 lines) |
// async iteration in JavaScript?
function SelectAsync(asyncGenerator, asyncProjection) {
return function(cancellationToken) {
return spawnSequence(function*(Yielder){
|
view (15 lines) |
// C# async sequencing
interface IAsyncEnumerable<out T>
{
IAsyncEnumerator<out T> GetEnumerator();
|
view (55 lines) |
// C#-ish, assuming IAsyncEnumerable
IAsyncEnumerable<int> f( IAsyncEnumerable<int> eg) {
int i = 1;
yield i++;
|
view (30 lines) |
// promises/A only, not promises/A+
// extract :: w a -> a
// duplicate :: w a -> w (w a)
// extend :: (w a -> b) -> w a -> w b
|
view (20 lines) |
// async fibonacci
function async_fib(x) { return spawn(function*() {
throw new Task.Result(
x < 2 ? x
|
view (14 lines) |
// async enumerables and observables
public IAsyncEnumerable<T> ae2ao(IAsyncObservable<T> source)
{
return AsyncEnumerableEx.Create(async Yield =>
|
view (36 lines) |
// async enumerables and observables
public IAsyncEnumerable<T> ae2ao(IAsyncObservable<T> source)
{
return AsyncEnumerableEx.Create(async Yield =>
|
view (36 lines) |
var dr = new DataReader(aStream)
function flow() {
while (dr.UnconsumedBufferLength > 0) {
console.log(dr.readString());
|
view (10 lines) |
// this seems like a *Bad Idea*, but is probably *technically* valid
void* rmalloc(size_t sz) {
void *pv;
|
view (19 lines) |
// resumable functions and Rx
template <class T>
void ImperativeGenerator(
function<task(Subject<T>&)> producer,
|
view (28 lines) |
template <int n, int m>
struct trial_divide_composite
{
enum { value = (n%m == 0) || trial_divide_composite<n, m-1>::value };
};
|
view (28 lines, 3 lines of output) |
template <int n, int m>
struct trial_divide_composite
{
enum { value = (n%m == 0) || trial_divide_composite<n, m-1>::value };
};
|
view (28 lines) |
template <int n, int m>
struct trial_divide_composite
{
enum { value = (n%m == 0) || trial_divide_composite<n, m-1>::value };
};
|
view (28 lines, 3 lines of output) |
> function *adding() { for (;;) { yield ((yield null) + (yield null)); }}
undefined
> it = adding()
{}
> it.send(2)
|
view (11 lines) |
#define CGOTO(label) { _dispatch = (label); goto _dispatcher; }
#define BEGIN_CGOTO int _dispatch=-1; _dispatcher: switch (_dispatch) { case -1:;
#define END_CGOTO }
int main() {
|
view (22 lines, 3 lines of output) |
// here's a prototypical contravariant type.
abstract class OutStream<T> {
write(T value);
}
|
view (37 lines) |
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) |