Skip to content

Instantly share code, notes, and snippets.

View orb's full-sized avatar

Norman Richards orb

View GitHub Profile
clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: if-let in this context, compiling:(NO_SOURCE_PATH:1:1)
at clojure.lang.Compiler.analyze (Compiler.java:6380)
clojure.lang.Compiler.analyze (Compiler.java:6322)
clojure.lang.Compiler$InvokeExpr.parse (Compiler.java:3573)
clojure.lang.Compiler.analyzeSeq (Compiler.java:6562)
clojure.lang.Compiler.analyze (Compiler.java:6361)
clojure.lang.Compiler.analyze (Compiler.java:6322)
clojure.lang.Compiler$BodyExpr$Parser.parse (Compiler.java:5708)
clojure.lang.Compiler$FnMethod.parse (Compiler.java:5139)
clojure.lang.Compiler$FnExpr.parse (Compiler.java:3751)
(defn can-sum-to-zero
([nums]
(can-zero nums #{}))
([nums can-sum-to]
(when (seq nums)
(let [num (first nums)]
(if (can-sum-to (- num))
true
(let [can-also-sum-to (map #(+ num %) can-sum-to)]
(recur (rest nums)
(ns maze.tiles)
;;(print "\u2588 \u2588")
(def tiles1
{0 ["***"
"*!*"
"***"]
1 ["* *"
"* *"
"***"]
@orb
orb / maze.clj
Created July 10, 2013 20:38
maze generator from lambda jam
(ns maze.core
(:use maze.tiles)
(:require [clojure.data.json :as json]))
(defn empty-maze [xsize ysize]
(let [row (into [] (take ysize (repeat 0)))]
(into [] (take xsize (repeat row)))))
(defn all-coords [maze]
(let [xsize (count maze)
(ns logic.nono
(:refer-clojure :exclude [==])
(:use [clojure.core.logic])
(:require [clojure.core.logic.fd :as fd]))
(def max-size 25)
(defn count-ones [marks howmany post-marks]
(conde
[(emptyo marks)
@orb
orb / sudoku.clj
Last active April 24, 2020 12:04 — forked from swannodette/gist:3217582
updated for the latest core.logic, with some minor tweaks for (I hope) clarity
(ns sudoku
(:refer-clojure :exclude [==])
(:use [clojure.core.logic])
(:require [clojure.core.logic.fd :as fd]))
(defn init-board [vars puzzle]
(matche [vars puzzle]
([[] []]
succeed)
@orb
orb / dollars_and_cents.clj
Last active December 17, 2015 19:58
Skeptics Guide to the Universe - Episode 410 - WTN http://www.theskepticsguide.org/ a core.logic finite domains example
(ns dollars-and-cents
(:refer-clojure :exclude [==])
(:use [clojure.core.logic])
(:require [clojure.core.logic.fd :as fd]))
;; A bank teller made a mistake today. The teller switched the dollars
;; and cents when they cashed a check for Mrs. Jones, giving her
;; dollars instead of cents and cents instead of dollars.
;; After buying a newspaper for 5 cents, Mrs. Jones realized that she
<html>
<head>
<title>TEST</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
Bitcoin price is <b id="price">--</b>
<script>
$(function(){
$.get("https://data.mtgox.com/api/1/BTCUSD/ticker", function(data) {
@orb
orb / mupl-ski.rkt
Created March 4, 2013 17:41
SKI in MUPL in Racket
(define S (fun "S" "x" (fun #f "y"
(fun #f "z"
(call (call (var "x") (var "z"))
(call (var "y") (var "z")))))))
(define K (fun "K" "x" (fun #f "y" (var "x"))))
(define I (fun "I" "x" (var "x")))
;; SKK
(define SKK
(call (call S K) K))
@orb
orb / stream-maker.rkt
Created February 23, 2013 05:54
My version of stream-maker from PL class. This function works under the assumption that there is some state that is passed along from thunk to thunk as context. The current stream output value can be computed using val-fn. The state to pass to the next thunk is computed using the next-state function. I think it's much easier to understand, thoug…
(define (my-stream-maker val-fn next-state seed)
(define (stream-thunk current-state)
(lambda () (cons (val-fn current-state)
(stream-thunk (next-state current-state)))))
(stream-thunk seed))
(define ones
(my-stream-maker identity
identity