Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
@swannodette
swannodette / gist:1424929
Created December 2, 2011 21:35
test.sml
let
val Id = fn x => x
in
Id
end
(*
Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)
-- Solution to http://beust.com/weblog/2011/10/30/a-new-coding-challenge/
import Data.List(isInfixOf)
partitions n 1 = [[n]]
partitions n k | n > 0 = [m:ms | m <- [1..n `div` 2], ms <- partitions (n-m) (k-1)]
partitions n k | otherwise = []
weighings [] = [0]
weighings (w:ws) = [m + n | m <- weighings ws, n <- [-w, 0, w]]
@swannodette
swannodette / gist:1326585
Created October 30, 2011 23:23
stones.scm
(usefd)
(define (powerset a)
(if (null? a) (list '())
(let ((p (powerset (cdr a))))
(append (map (lambda (x) (cons (car a) x)) p) p))))
(define (remove-duplicates l)
(do ((a '() (if (member (car l) a) a (cons (car l) a)))
(l l (cdr l)))
@bmmoore
bmmoore / match.agda
Created October 25, 2011 03:29
Horrible pattern matching hack
{-# OPTIONS --universe-polymorphism #-}
module match where
open import Data.List hiding (or)
open import Category.Monad
open import Category.Functor
open import Function
open import Data.Maybe
open import Data.Bool
open import Data.Nat
open import Relation.Binary.PropositionalEquality
@wycats
wycats / works_today.js
Created September 27, 2011 21:42 — forked from swannodette/gist:1246024
named_subtemplates.hb
<!--
I'm sure there's a better syntax for naming subtemplates
-->
<h3>This is a list</h3>
<ul>
{{#each items}}
{{@cell}}
<li>
{{..}}
@daveray
daveray / match.pojo.clj
Created August 27, 2011 03:02
Generate match lookup for a Java class
(ns match.pojo
(:use [match.core :only [IMatchLookup val-at* match]]))
(set! *warn-on-reflection* true)
(defmacro pojo-match
"Generate an implementation of match.core/IMatchLookup for the given Java class.
Keys are mapped like this:
isVisible -> :visible?
@larsmans
larsmans / nonogram.pl
Created August 15, 2011 13:22
Nonogram/paint-by-numbers solver in SWI-Prolog
/*
* Nonogram/paint-by-numbers solver in SWI-Prolog. Uses CLP(FD),
* in particular the automaton/3 (finite-state/RE) constraint.
* Copyright 2011, 2014 Lars Buitinck
* Copyright 2014 Markus Triska
* Do with this code as you like, but don't remove the copyright notice.
*/
:- use_module(library(clpfd)).
(deftyped
addInteger
[Integer :> [Integer :> Integer]]
[x y]
(+ x y))
(deftyped
addDouble
[Double :> [Double :> Double]]
@swannodette
swannodette / Coder.scala
Created July 26, 2011 19:09
phone_code.clj
package demo
class Coder(words: List[String]) {
private val mnemonics = Map(
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ")
private val charCode: Map[Char, Char] =
for ((digit, str) <- mnemonics; letter <- str) yield letter -> digit
@swannodette
swannodette / gist:1102865
Created July 24, 2011 17:38
assoco.clj
(ns clojure.core.logic.assoco
(:refer-clojure :exclude [== reify inc not])
(:use [clojure.core.logic minikanren prelude match disequality]))
;; defining assoc as a pure relation
;; a good example of the non-overlapping
;; clauses property. A given map can match
;; only one of the these clauses.
(defne assoco [m k v o]