This file contains 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 sys | |
import time | |
def progress(iterable, length=33): | |
count = avg = 0 | |
total = len(iterable) | |
then = time.time() | |
for it in iter(iterable): | |
yield it |
This file contains 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
mi_dcg_clause, [] --> [natnum(0)]. | |
mi_dcg_clause, [natnum(X)] --> [natnum(s(X))]. | |
mi_dcg_clause, [always_infinite] --> [always_infinite]. | |
mi_dcg --> []. | |
mi_dcg --> mi_dcg_clause, mi_dcg. | |
%% Original version from https://www.metalevel.at/acomip/ : | |
mi_ldclause(natnum(0), Rest, Rest). |
This file contains 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
rewrite(L, R), [Skip] --> [Skip], rewrite(L, R). % Skip the current head. | |
rewrite(L, R), R --> L. % Match the current prefix and return. | |
rewrite(Rules) --> {member(L-R, Rules)}, rewrite(L, R). % Try a single rule. | |
normalize(P) --> P, normalize(P). % If at first you succeed, try, try again. | |
normalize(P) --> \+P. % P failed so list remains the same. | |
% Single-step rewrite with {"ab"->"x", "ca"->"y"}: | |
% ?- phrase(rewrite([[a,b]-[x], [c,a]-[y]]), [a,b,c,a,b,c], Out). | |
% Out = [a, b, c, x, c] ; |
This file contains 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
% Implementation of call-by-name lambda calculus in Prolog using logic variables as lambda variables | |
% | |
% The grammar is: | |
% Term ::= Term-Term % abstraction: LHS is function body; RHS is parameter (Y-X instead of λX.Y) | |
% | Term+Term % application: LHS is function; RHS is argument (F+X instead of (F X)) | |
eval(Y-X, Y-X). % abstractions are left as-is | |
eval(F+X, Y) :- | |
copy_term(F,B), % copy before destructive unification of parameter in case F appears elsewhere | |
eval(B, Y0-X), % eval into what must be an abstraction and unify X with parameter |
This file contains 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
package main | |
import ( | |
"net/http" | |
"compress/gzip" | |
"io/ioutil" | |
"strings" | |
"sync" | |
"io" | |
) |
This file contains 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
; 8-bit Xor-Shift random number generator. | |
; Created by Patrik Rak in 2008 and revised in 2011/2012. | |
; See http://www.worldofspectrum.org/forums/showthread.php?t=23070 | |
org 40000 | |
call rnd ; BASIC driver | |
ld c,a | |
ld b,0 | |
ret |
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <strings.h> | |
/* | |
* Pearson hashing (from Wikipedia) | |
* | |
* Pearson hashing is a hash function designed for fast execution on processors with 8-bit registers. | |
* Given an input consisting of any number of bytes, it produces as output a single byte that is strongly | |
* dependent on every byte of the input. Its implementation requires only a few instructions, plus a |