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
-- represent base smt types as strings | |
type Variable = String | |
type Refinement = String | |
-- add a list of free vars to refvars | |
data RefVar = RefVar String [Variable] deriving (Show) | |
-- ignore var list for equality | |
instance Eq RefVar where |
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
// List representation with lambdas. | |
// https://en.wikipedia.org/wiki/Church_encoding#Represent_the_list_using_Scott_encoding | |
import java.util.*; | |
import java.util.function.*; | |
public abstract class ConsList<E> extends AbstractSequentialList<E> { | |
public abstract <C> C match(C n, BiFunction<E, ConsList<E>, C> c); | |
public static <E> ConsList<E> nil() { |
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
;; https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search | |
(defn topsort [g] | |
(let [l (atom ()) | |
marks (atom (zipmap (keys g) (repeat nil))) | |
visit (fn visit [n] | |
(case (@marks n) | |
:perm nil | |
:temp (throw (IllegalArgumentException. "Not a DAG")) | |
(do | |
(swap! marks assoc n :temp) |
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
:- use_module(library(clpz)). | |
:- use_module(library(dcgs)). | |
:- use_module(library(lambda)). | |
:- use_module(library(lists)). | |
:- use_module(library(reif)). | |
num_to_parity(N, odds_evens(Os, Es)) :- | |
num_word(N, W), | |
same_length(W, Ls), | |
findall(M, word_to_num(Ls, M), Ms), |
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
:- use_module(library(apply)). | |
:- use_module(library(assoc)). | |
:- use_module(library(clpfd)). | |
:- use_module(library(dcg/basics)). | |
:- use_module(library(dcg/high_order)). | |
:- use_module(library(edcg)). | |
:- use_module(library(pio)). | |
:- use_module(library(portray_text)). | |
% I'd prefer to use characters but this is a compromise to make the code simpler. |
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
(ns earley | |
(:refer-clojure :exclude [==]) | |
(:require [clojure.set :as set]) | |
(:use clojure.core.logic)) | |
(declare nullables single-parse all-parses) | |
;; An Earley set is a tuple of a vector and a set. | |
;; This lets us iterate over them as well as keep track of seen values. | |
(defn- set-conj [{:keys [seen?] :as all} & xs] |
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
;; Persistent priority queue implementation using a binary heap. Min heap by default. | |
;; O(1) lookup, O(log n) insertion and deletion. | |
(ns priority-queue | |
(:import clojure.lang.IPersistentCollection | |
clojure.lang.IPersistentStack | |
clojure.lang.Seqable)) | |
(defn- left [idx] (inc (* 2 idx))) | |
(defn- right [idx] (+ 2 (* 2 idx))) |
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
use std::cmp::Ordering; | |
use std::collections::BinaryHeap; | |
// I can't come up with a better name for this :P | |
#[derive(Debug, PartialEq, Eq)] | |
struct Pair { | |
prime: u128, | |
multiple: u128, | |
} |
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
; @echo off | |
; Racket.exe "%~f0" %* | |
; exit /b | |
#lang racket/base | |
(require racket/port) | |
(define (file->datums filepath) | |
(define fileport (open-input-file filepath)) | |
(read-language fileport void) | |
(for/list ([datum (in-producer read eof fileport)]) datum)) |
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
(defn rotate [s l] | |
(case s | |
0 l | |
1 (cons (last l) (drop-last l)) | |
-1 (concat (rest l) (take 1 l)))) | |
(defn neighbors [b] | |
(let [rels (for [x (range -1 2) | |
y (range -1 2) | |
:when (not= 0 x y)] |
NewerOlder