Skip to content

Instantly share code, notes, and snippets.

Norman Richards orb

View GitHub Profile
@orb
orb / fb.clj
Created Nov 14, 2014
is or a conditional?
View fb.clj
;; http://gigasquidsoftware.com/blog/2014/11/13/clojure-fizzbuzz-without-conditionals
(defn fb [n]
(or (->> (map #(str %1 %2)
(cycle [nil nil "fizz"]) (cycle [nil nil nil nil "buzz"]))
(take n)
last
not-empty)
n))
@orb
orb / mergeseq.clj
Last active Aug 29, 2015
merge ordered seqs example
View mergeseq.clj
;; austin clojure meetup hacking
;; ----------------------------------------
;; just merge 2 seqs
(defn merge2 [s1 s2]
(if (seq s1)
(when (seq s2)
(let [i1 (first s1)
View play.sml
(* SML playing a *)
fun fac 0 = 1
| fac n = n * fac (n - 1);
fun div_by n x =
x mod n = 0;
val div_3 = div_by 3;
val div_5 = div_by 5;
@orb
orb / match.clj
Created Feb 8, 2015
core match testing
View match.clj
(ns randomstuff.match
(:require [clojure.core.match :refer [match]]))
(defn card_color [[suit value]]
(match [suit value]
[:diamonds _] :red
[:hearts _] :red
:else :black)) ;; or [_ _]
@orb
orb / multi.clj
Created Feb 8, 2015
playing with multimethods
View multi.clj
(defmulti fact1 identity)
(defmethod fact1 0 [_] 1)
(defmethod fact1 :default [n] (* n (fact1 (dec n))))
(defmulti fizzbuzz
(fn [n]
[(zero? (mod n 3))
(zero? (mod n 5))]))
@orb
orb / uni.clj
Created Feb 8, 2015
clojure unification tests
View uni.clj
(ns hufflepuff.uni
(:require [clojure.core.logic :refer [defnc fnc]]
[clojure.core.logic.unifier :refer [unifier unify]]))
(defnc numberc [x]
(number? x))
(defnc symbolc [x]
(symbol? x))
@orb
orb / rewrite.nb
Last active Aug 29, 2015
mathematic rewriting
View rewrite.nb
In[1]:= sum[m_, 0] := m;
sum[m_, s[n_]] := s[sum[m, n]];
In[3]:= sum[s[s[0]], s[s[s[s[0]]]]]
Out[3]= s[s[s[s[s[s[0]]]]]]
In[4]:= map[f_, {}] := {};
map[f_, {x_, xs___}] := Prepend[map[f, {xs}], f[x]];
@orb
orb / ex.clj
Created Feb 8, 2015
playing with termito rewriting in clojure
View ex.clj
(ns rewrite.ex
(:require [clojure.core.logic :refer [defnc fnc]]
[termito.core :refer [defrules simplify simplify-one]]))
(defnc numberc [x]
(number? x))
(defrules bad
[:dog :cat]
[:cat :dog])
@orb
orb / closing_time.clj
Created Feb 9, 2015
It's closing time.
View closing_time.clj
(run* [your-location]
(conde
[(== your-location :home)]
[succeed])
(!= your-location :here))
@orb
orb / minikanren.rb
Created Apr 5, 2015
some ruby minikanren scribblings
View minikanren.rb
require 'mini_kanren'
include MiniKanren::Extras
$section = "--"
def section!(label)
$counter = 0
puts "====== #{label}"
end
You can’t perform that action at this time.