Skip to content

Instantly share code, notes, and snippets.

Christophe Grand cgrand

Block or report user

Report or block cgrand

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View rle.clj
(defn mundane-pack
"Mundane recursive way to pack a sequence"
[[f & r :as S]]
(if (seq S)
(let [[packed tail] (split-with #{f} S)]
(if (seq tail)
(cons packed (pack tail))
[packed]))
[nil]))
View gist:1200354
(defn neighbours [[x y]]
(for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
[(+ dx x) (+ dy y)]))
(defn step [cells]
(set (for [[loc n] (frequencies (mapcat neighbours cells))
:when (or (= n 3) (and (= n 2) (cells loc)))]
loc)))
(def board #{[2 1] [2 2] [2 3]})
@cgrand
cgrand / gist:1236838
Created Sep 23, 2011 — forked from laurentpetit/gist:1233437
coding-dojo-20110921
View gist:1236838
; juste pour l'art
(defn primes []
(keep :prime
(iterate (fn [{:keys [known candidate]}]
(if (some #(zero? (rem candidate %)) known)
{:known known :candidate (inc candidate)}
{:known (conj known candidate) :candidate (inc candidate) :prime candidate}))
{:known [] :candidate 2})))
@cgrand
cgrand / gist:1877266
Created Feb 21, 2012 — forked from remleduff/gist:1876575
Simplified AST processing code from CinC
View gist:1877266
(use '[clojure.walk :only [walk]])
(def ^:dynamic ^:private *frame*)
(defn- new-frame [] (atom {}))
(defn- collect-frame [ast]
(case (:op ast)
:constant
{:constants [{:value (:form ast)}]}
@cgrand
cgrand / fib-seq-1.clj
Created Mar 6, 2012 — forked from scientific-coder/fib-seq-1.clj
Code snippets for Duchess-fr Battle Language 2012-02-29 test it on http://tryclj.com/ !
View fib-seq-1.clj
(def fib-seq
"lazy seq of Fibonacci numbers"
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))
@cgrand
cgrand / fib-seq-1.clj
Created Mar 8, 2012 — forked from scientific-coder/fib-seq-1.clj
Code snippets for Duchess-fr Battle Language 2012-02-29 test it on http://tryclj.com/ !
View fib-seq-1.clj
(def fib-seq
"lazy seq of Fibonacci numbers"
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))
View gist:2652814
(defn lein-env
"Create a new classlojure based leiningen environment by fetching all jars
and classes directories found inside the ccw.leiningen-core plugin."
[]
(let [leiningen-core (bundle-dir "ccw.leiningen-core")
jar (fn [f] (and (.isFile f) (.endsWith (.getName f) ".jar")))
classes-dir (fn [d] (let [manifest (io/file d "META-INF" "MANIFEST.MF")]
(and (.exists manifest)
(.isFile manifest))))
libs (->> leiningen-core file-seq (filter #(or (jar %) (classes-dir %))))]
@cgrand
cgrand / clojure-match.clj
Created Sep 5, 2012 — forked from ckirkendall/clojure-match.clj
Language Compare F#, Ocaml, Scala, Clojure, Ruby and Haskell - Simple AST example
View clojure-match.clj
(use '[clojure.core.match :only [match]])
(defn evaluate [env [sym x y]]
(match [sym]
['Number] x
['Add] (+ (evaluate env x) (evaluate env y))
['Multiply] (* (evaluate env x) (evaluate env y))
['Variable] (env x)))
(def environment {"a" 3, "b" 4, "c" 5})
@cgrand
cgrand / gist:4038631
Created Nov 8, 2012 — forked from laurentpetit/gist:4038525
Memento du déroulé Agile Grenoble 2012
View gist:4038631
(ns agile.life
(:use [clojure.pprint :only [pprint]]))
;; cell representation
(pprint [2 2])
;; game state representation
#{[2 2] [3 2]}
;; game initial state ("blinker")
@cgrand
cgrand / answer.clj
Last active Dec 11, 2015 — forked from laurentpetit/gist:4538379
Optimisons sans trahir
View answer.clj
; original
(defn best-plan [bids]
(first (vals (reduce (fn [plans {:keys [DEPART VOL DUREE PRIX]}]
(assoc plans DEPART
(max-key #(:gain % 0) (first (vals plans))
(let [[[_ {:keys [gain path] :or {gain 0}}]]
(subseq plans >= (+ DEPART DUREE))]
{:gain (+ gain PRIX) :path (cons VOL path)}))))
(sorted-map) (sort-by :DEPART > bids)))))
You can’t perform that action at this time.