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
;;; euler.clj -- Project Euler solutions in Clojure | |
;; by Robert Campbell, http://www.robert-campbell.com/ | |
;; Most of my implemented solutions are crude, utilizing only brute force. | |
;; I'm more interested in exploring functional programming techniques in | |
;; Clojure than in mathematical optimizations. I do, however, keep to the | |
;; standard one minute rule, running all programs on a 2.66GHz Core2 Quad. | |
;; Problems requiring a sequence of primes were originally solved using |
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
;; Dynamic form population based on Christophe Grand's suggestions found here: | |
;; http://bit.ly/72NkNS | |
(ns dynamic-form | |
(:refer-clojure :exclude [empty complement]) | |
(:use net.cgrand.enlive-html) | |
(:import [java.io File])) | |
(defn populate-select [options] | |
(fn [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
{- -} | |
-- Problem 1 | |
foldr (+) 0 (filter (\n -> mod n 3 == 0 || mod n 5 == 0) [1..1000]) |
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
/** | |
* Any class which implements the <b>Comparable</b> interface must implement <b>compareTo</b>. Run | |
* these tests on all classes which implement <b>compareTo</b> to confirm they conform to the | |
* general contract. | |
* | |
* @author Robert Campbell | |
*/ | |
@SuppressWarnings("unchecked") | |
public class ComparableTests { |
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 calais.rdf | |
(:use [clojure.http.client] | |
[clojure.contrib.str-utils :only [re-gsub]] | |
[clojure.contrib.seq-utils :only [frequencies flatten partition-all]]) | |
(:require [clojure.contrib.str-utils2 :as str-utils]) | |
(:import [java.io File FileInputStream] | |
[com.hp.hpl.jena.rdf.model Model ModelFactory] | |
[com.hp.hpl.jena.query QueryExecutionFactory QueryFactory])) | |
(defn load-model [file] |
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 render | |
(:refer-clojure :exclude [empty complement]) | |
(:use [clojure.set :only [difference]] | |
[net.cgrand.enlive-html])) | |
(def this-ns *ns*) | |
(defmulti populate | |
"Populate the given tag with content v and | |
taxonomy options if supported by the tag" |
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 calais.web | |
(:use compojure | |
[compojure.http response] | |
[clojure.contrib.def :only [defn-memo]] | |
[clojure.contrib.seq-utils :only [rand-elt]] | |
[clojure.contrib.str-utils :only [re-gsub]]) | |
(:require [calais.rdf :as rdf]) | |
(:import [java.io File])) | |
(declare percent) |
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 match) | |
(defn nest [m] | |
"Converts a flat map with keys using underscore | |
nesting to proper nested maps" | |
(reduce (fn [m [k v]] | |
(let [ks (map keyword | |
(.split (if (keyword? k) (name k) k) "__"))] | |
(assoc-in m ks v))) {} m)) |
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 coordinates | |
(:import [clojure.lang IPersistentVector IPersistentMap])) | |
(declare flatten) | |
(defmulti append | |
"Appends a given data structure to a flat map" | |
#(class %3)) | |
(defmethod append IPersistentVector [m k v] |
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
print "\n\n".join(["%d %s of beer on the wall, %d %s of beer.\n%s"%(i,i>1 and"bottles"or"bottle",i,i>1 and"bottles"or"bottle",i-1==0 and"Go to the store and buy some more, 99 bottles of beer on the wall."or"Take one down and pass it around, %d %s of beer on the wall."%(i-1,i-1>1 and"bottles"or"bottle"))for i in reversed(range(1,100))]) |
OlderNewer