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
% unnumber_vars/2 is not working correctly in B-Prolog 8.1. Here is | |
% an alternative implementation of unnumber_vars/2 named varnumbers/2, | |
% which is compatible with SWI-Prolog's varnumbers library. | |
max_varnumber('$VAR'(N), Max) => | |
Max = N. | |
max_varnumber(Term, Max) => | |
Term =.. [_ | Args0], | |
Args @= [Arg : Arg0 in Args0, [Arg], max_varnumber(Arg0, Arg)], | |
Max is max([-1 | Args]). |
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 Data.Bits (setBit) | |
import Data.Word (Word8) | |
import Data.Tuple (swap) | |
import Data.Maybe (fromJust) | |
import qualified Data.Map as M | |
import qualified Data.Heap as H | |
import qualified Data.ByteString as B | |
import Control.Arrow (second, (&&&)) | |
type OccurrenceTable a = M.Map a Int |
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 qualified Data.Heap as H | |
h :: H.MaxPrioHeap Int Char | |
h = H.fromList [(1, 'a')] | |
h' :: H.MaxPrioHeap Int String | |
h' = fmap (:[]) h | |
main :: IO () | |
main = do |
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
#!/bin/sh | |
set -ex | |
DIR="$HOME/var/tmp" | |
SIZE=1024m | |
mkdir -p "$DIR" | |
sudo umount "$DIR" | |
sudo mount -t tmpfs -o size=$SIZE tmpfs "$DIR" |
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
dangerous_capture(Ident) :- | |
for_body(ForBody), | |
stmt_child(ForBody, stmt, VarStmt), | |
statement(VarStmt, var, Var, _, _), | |
var(Var, Decls), | |
var_decls(Decls, D), | |
var_decl(D, VarName, _, _, _), | |
stmt_desc(ForBody, expr, FuncExpr), |
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
private enum Color { Red; Black; } | |
private enum TreeT<T> { | |
Leaf; | |
Node(color: Color, left: TreeT<T>, label: T, right: TreeT<T>); | |
} | |
private class TreeF { | |
private function new() {} |
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 Data.Function (on) | |
import Data.List (sortBy) | |
import Control.Monad (forM_) | |
solve :: Int -> Int -> [Int] -> Int | |
solve e r vs = solve' 0 (sortBy (flip compare `on` snd) (zip [0..] vs)) [] | |
where | |
solve' gain [] as = gain | |
solve' gain ((i,v):vs) as = solve' (gain + v * a) vs ((i,a,b):as) | |
where b = maximum (0:[b' + a - (j-i) * r | (j,a,b') <- as, i < j]) |
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
#!/bin/sh | |
: ${PAGER:=cat} | |
package="$1" | |
readme="$(dpkg-query -L "$package" 2> /dev/null | grep README.Debian | head -n 1)" | |
if [ -s "$readme" ]; then | |
case "$readme" in | |
*.gz) gunzip -qc "$readme" | $PAGER;; | |
*) $PAGER "$readme";; |
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
(defpackage :rb-tree | |
(:use :cl :optima) | |
(:export #:rb-empty | |
#:rb-member | |
#:rb-insert)) | |
(in-package :rb-tree) | |
(defstruct (leaf (:constructor leaf))) | |
(defstruct (node (:constructor node (color left label right))) | |
color left label right) |
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 Data.Maybe (isJust) | |
data Tree a = Leaf | Node (Tree a) a (Tree a) | |
replace :: a -> Tree a -> Tree a | |
replace a Leaf = Node Leaf a Leaf | |
replace a (Node l _ r) = Node l a r | |
rotateR :: Tree a -> Tree a | |
rotateR (Node (Node x a y) b z) = Node x a (Node y b z) |