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
; SLIME | |
user> | |
user> (load-file "c:/projects/github/fix-clj/src/fix_clj/core.clj") | |
#'fix-clj.core/next-value-and-rest | |
user> (load-file "c:/projects/github/fix-clj/test/fix_clj/test_core.clj") | |
nil | |
user> (use ['fix-clj.core 'fix-clj.test_core] :reload-all :verbose) | |
; Evaluation aborted. | |
user> (use '[fix-clj.core fix-clj.test_core] :reload-all :verbose) | |
; Evaluation aborted. |
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 java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Random; | |
/** | |
* Implementation of http://en.wikipedia.org/wiki/Quicksort#Simple_version. | |
*/ | |
public class NotSoQuickSort { |
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 java.io.*; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
import java.net.SocketTimeoutException; | |
/** | |
* A simple server with which you can interact over a raw socket. | |
*/ | |
public class SimpleServer { |
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 java.util.concurrent.locks.AbstractQueuedSynchronizer; | |
public class AqsSample { | |
public static void main(String[] args) { | |
Restroom restroom = new Restroom(); | |
Thread larry = new Thread(new Patron("Larry",restroom)); | |
Thread moe = new Thread(new Patron("Moe", restroom)); |
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 java.util.Arrays; | |
import java.util.Random; | |
/** | |
* See http://en.wikipedia.org/wiki/Quick_sort#In-place_version | |
*/ | |
public class QuickSort { | |
private static final Random random = new Random(); | |
private static final int RANDOM_INT_RANGE = 100; |
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 reverse-recursively [coll] | |
(loop [r (rest coll) | |
acc (conj () (first coll))] | |
(if (= (count r) 0) | |
acc | |
(recur (rest r) (conj acc (first r)))))) |
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 java.util.Arrays; | |
import java.util.TreeMap; | |
import java.util.Map; | |
import java.util.Random; | |
/** | |
* Given an array of integers, determine if any two given elements sum to a given target. | |
*/ | |
public class FindTwoSumToTarget { |
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 any-pair-make-sum? [arr target] | |
(let [m (frequencies arr)] | |
(loop [f (first arr) | |
x (- target f) | |
r (rest arr)] | |
(let [entry (find m x) | |
only-needs-one-count (not (= x f))] | |
(if (and entry (or only-needs-one-count (> 1 (val entry)))) | |
true | |
(if (empty? r) |
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
;; See: http://codereview.stackexchange.com/q/6682/9032 | |
(defn map-invert-preserve-dups [m] | |
(apply merge-with into | |
(for [[k v] m] | |
{v [k]}))) | |
(->> "http://www.weeklyscript.com/Pulp%20Fiction.txt" | |
(slurp) | |
(re-seq #"\w{5,}") | |
(frequencies) |
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; LabREPL min-3 exercise | |
;; "Implement min-3 which reduces over a function that returns | |
;; the min of two arguments" | |
;; My attempt | |
(defn min-3 [x & more] | |
(let [s (cons x (seq more))] | |
reduce (fn findmin [x y] (if (< x y) x y)) s))) | |
OlderNewer