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
import annotation.tailrec | |
object Pascal { | |
def main(args: Array[String]) { | |
for (i <- 0 to 30) { | |
for (j <- 0 to i) { | |
print(pascalRowColumn(i, j) + " ") | |
} |
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
// O(e) memory/space, O(e) time | |
def combine(f: (Int, Int) => Int)(a: Int, b: Int, d: Int): Int = { | |
if (b == 0) d | |
else f(a, combine(f)(a, b - 1, d)) | |
} | |
// O(1) memory/space, O(e) time | |
def combine2(f: (Int, Int) => Int)(a: Int, b: Int, d: Int): Int = { | |
def inner (acc: Int, iter: Int): Int = { | |
if (iter == 0) acc |
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
;; This buffer is for notes you don't want to save, and for Lisp evaluation. | |
;; If you want to create a file, visit that file with C-x C-f, | |
;; then enter the text in that file's own buffer. | |
(defn pascal-row-column | |
"Compute the number in Pascal's triangle at the specified row/column | |
position using tree-recursive approach." | |
[r c] | |
(if (or (zero? c) (= r c)) 1 | |
(+ (pascal-row-column (dec r) c) |
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 fermats (map #(inc (expt 2 (expt 2 %))) (iterate inc 0))) |
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
(let [coll-sizes (map #(expt 2 %) (range 5 10)) ;; Set up the collection sizes to be used | |
methods ['rvrs 'my-rvrs 'reverse]] ;; Hold method names in a collection as symbols | |
(-> (for [x methods | |
y coll-sizes | |
:let [z (binding [*out* (java.io.StringWriter.)] ;; Pipe stdout to a StringWriter (x * y instantiations) | |
(time ((resolve x) (range 0 y))) ;; Resolve x (symbol) to actual function and apply it to coll (size y), timing the running time and printing it to the StringWriter | |
(->> (.. *out* toString) ;; Retrieve output from StringWriter | |
(re-find #"\d+.\d+") ;; Parse out the numeric value (running time) | |
Double/parseDouble))]] | |
[x y z]) ;; Convert to double for plotting |
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
concabs.core> (defn g [n] | |
"Returns a function that takes a constant c and sums | |
the powers of c, 0 to n inclusive." | |
(fn [c] (reduce + (map (fn [e] (expt c e)) (range 0 (inc n)))))) ;; No rounding, clojure.math.numeric-tower/expt | |
;; #'concabs.core/g | |
concabs.core> ((g 2000) 1/2) | |
;; 229626139054850904846566640235536396804463540417739040095528547365153252278474062771331897263301253983689192927797492554689423792172611066285186271233330637078259978290624560001377558296480089742857853980126972489563230927292776727894634\ | |
;; 052080932707941809993116324797617889259211246623299072328443940665362688337817968917011204758969615828117801869553000858005433413251661044016264472562583522535766634413197990792836254043559716808084319706366503081778867804183841109915567\ | |
;; 179344078320163914433261165510760851167452031056697572838864109017830551567765250350871057601645685541635930907524369702298058751/114813069527425452423283320117768198402231770208869520047764273682576626139237031 |
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
;; Triple-sum problem stuff | |
;; | |
;; Using this command: | |
(for [f ["1Kints.txt" | |
"2Kints.txt" | |
"4Kints.txt"] | |
:let [t (->> (:out (sh "java" "-cp" | |
".:stdlib.jar" | |
"ThreeSum" | |
(str "http://algs4.cs.princeton.edu/14analysis/" 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
;; Logging steps taken to validate local irjobs output against current dev. | |
;; Get the deps | |
(require '[java-jdbc [sql :as s]]) | |
(require '[clojure.java [jdbc :as j]]) | |
;; Count the records in the database from today's run: | |
(count (j/query dv01-shareduser (s/select * :shareduser.mlcrtpxp_renewals_result | |
(s/where {"TRUNC(process_date_time)" "28-JAN-2014"})))) | |
;; 45 |
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
;; xalan 2.6 gets put on the classpath when using | |
;; Incanter, causes issues with clj-xpath. So DON'T | |
;; use Incanter when using clj-xpath. | |
(->> (ClassLoader/getSystemClassLoader) | |
(.getURLs) | |
(map #(.toString %)) | |
(clojure.string/join "\n") | |
(re-seq #".*xalan.*") | |
(pprint)) |
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
; This | |
(html [:html | |
[:head | |
[:meta {:charset "utf-8"}] | |
[:title "Title"]] | |
[:body | |
[:header | |
[:h1 "H1 header!"]] | |
[:section | |
[:ul |
OlderNewer