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
// Heap's method, see Sedgewick (1977) | |
function eachPerm(a, callback, target) { | |
var n = a.length; | |
var c = new Array(n); | |
var j = n; | |
while (j--) { c[j] = 0; } | |
var m = 0; | |
callback.call(target, a, m++); | |
var i = 1; | |
do { |
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
function string.split(s, pattern, init, plain) | |
local function f(s, init) | |
local n = #s + 1 | |
if init > n then return nil end | |
local i, j = s:find(pattern, init, plain) | |
if i == nil then | |
return n + 1, init, n - 1 | |
else | |
return j + 1, init, i - 1 | |
end |
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
sub non_blank_or_prompt { | |
my $input = shift; | |
if (length($input // '') < 1) { | |
# Check for tty. However, consider IO::Interactive | |
-t STDIN and -t STDERR | |
or die "Input required"; | |
for (;;) { | |
print STDERR "Enter something: "; | |
defined ($input = <STDIN>) | |
or die "\nInput required"; |
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
#pragma once | |
/* Each coroutine is represented by a pointer to its stack bottom. */ | |
typedef void *co_coro; | |
/* The coroutine procedure takes the calling coroutine as its first argument. */ | |
typedef void (*co_proc)(co_coro back); | |
/* Switch to new coroutine. The stack top must be 16 byte aligned.*/ |
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
# i got my 9 millimeter at my waist, papa | |
# i got my shotgun in the escalade, papa | |
from opcode import HAVE_ARGUMENT, EXTENDED_ARG, opname, opmap, cmp_op | |
from opcode import hasconst, hasfree, hasname, hasjrel, hasjabs, haslocal, hascompare | |
haspair = [opmap[x] for x in ('UNPACK_EX', 'CALL_FUNCTION')] | |
# global convention: | |
# i - position of the opcode in the byte stream |
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
#include <stdlib.h> | |
#include <stdio.h> | |
/* list in core */ | |
/* node in our linked list */ | |
struct node { | |
struct node *link; | |
long data; |
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 product(h) | |
k = h.keys | |
v = h.values_at(*k) | |
p = v.shift.product(*v) | |
p.map { |v| Hash[k.zip(v)] } | |
end |
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
{- how to eval Icon pure integer-expressions -} | |
{- values -} | |
data D = DNull | DInt Int | |
deriving (Show, Eq) | |
newtype V = V { runV :: [D] } | |
deriving (Show) |
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
#include <stdlib.h> | |
#include <errno.h> | |
#include <stdio.h> | |
#include "avltree.h" | |
struct node { | |
struct node *left, *right; | |
int diff; | |
key_t key; | |
}; |