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 backtracking [solution? explore node] | |
(if (solution? node) [node] | |
(mapcat | |
#(backtracking solution? explore %1) | |
(explore node)))) |
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 in-range? [vec coords] | |
(boolean | |
(reduce #(and | |
(vector? %1) | |
(> (count %1) %2) | |
(%1 %2)) | |
vec coords))) |
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
(defprotocol TradeTax | |
(trade-tax [trade logic])) | |
(defprotocol Commission | |
(commission [trade logic])) | |
(defrecord Trade [ref-no account instrument principal tax-fees | |
unit-price quantity]) | |
(defn calculate-tax [{:keys [principal]} logic] |
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 com.freiheit.clojure.appengine.appengine-local | |
(:use | |
[compojure.http routes servlet helpers] | |
clojure.contrib.test-is | |
compojure.server.jetty | |
[clojure.contrib def str-utils duck-streams]) | |
(:require | |
[clojure.contrib.logging :as log]) | |
(:import | |
[com.google.appengine.api.labs.taskqueue.dev LocalTaskQueue] |
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 mygae.core | |
(:gen-class :extends javax.servlet.http.HttpServlet) | |
(:use compojure.core | |
ring.util.servlet | |
ring.adapter.jetty) | |
(:require [compojure.route :as route])) | |
(defroutes example | |
(GET "/" [] "<h1>Hello World Wide Web</h1>") | |
(route/not-found "Page not found")) |
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 local-dev | |
"Tools for local development. | |
Enables the use of the App Engine APIs on the REPL and in a local Jetty instance." | |
(:use ring.adapter.jetty | |
[ring.middleware file file-info]) | |
(:import [java.io File] | |
[java.util HashMap] | |
[com.google.apphosting.api ApiProxy ApiProxy$Environment] | |
[com.google.appengine.tools.development | |
ApiProxyLocalFactory |
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 alien-nums | |
(:require (clojure.contrib [combinatorics :as comb :only cartesian-product] | |
[seq-utils :as seq-utils :only indexed]))) | |
(defn leading-zero? [lang num] | |
(= (first num) (first lang))) | |
(defn generate-nums [lang] | |
(when-let [lst (map list lang)] | |
(let [fcp #(map flatten |
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
(define (member-of-2? a lst1 lst2) | |
(if (or (null? lst1) (null? lst2)) #f | |
(or | |
(and (eq? a (car lst1)) | |
(or (eq? a (car lst2)) | |
(member-of-2? a (list a) (cdr lst2)))) | |
(member-of-2? a (cdr lst1) lst2)))) |
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
def ifM[B](t: => M[B], f: => M[B])(implicit a: Monad[M], b: A <:< Boolean): M[B] = | |
>>= ((x: A) => if (x) t else f) |
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
type Instrument = String | |
type Account = String | |
type Quantity = BigDecimal | |
type Money = BigDecimal | |
import java.util.{Calendar, Date} | |
val today = Calendar.getInstance.getTime | |
case class Trade(ref: String, ins: Instrument, account: Account, unitPrice: Money, | |
quantity: Quantity, tradeDate: Date = today) { |