Skip to content

Instantly share code, notes, and snippets.

View noahlz's full-sized avatar
🕵️‍♂️
Secret Stuff for SEI Novus. I might take 1 - 3 days to respond.

Noah Zucker noahlz

🕵️‍♂️
Secret Stuff for SEI Novus. I might take 1 - 3 days to respond.
View GitHub Profile
@noahlz
noahlz / labrepl-euler.clj
Created December 25, 2011 00:50
LabREPL Project Euler exercises
;; "Find the sum of all the multiples of 3 or 5 below 1000."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Filtering
;; "Create a divides? predicate that takes a dividend and a divisor, and returns true if divisor evenly
;; divides the dividend"
;; My solution to the filtering "divides?" problem:
(defn divides? [num div] (= 0 (mod num div)))
@noahlz
noahlz / labrepl-unified-updates.clj
Created December 29, 2011 04:04
LabREPL Unified update model notes and exercises
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Atoms
;; Using swap! and merge-with on a map
;; the trick is to put merge-with inside a function.
(def m (atom {:a 1}))
;=> #'user/m
user> (swap! m #(merge-with + % {:a 2}))
@noahlz
noahlz / joy-of-clojure-ch3.clj
Created January 2, 2012 02:03
Code from Joy of Clojure, chapter 3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 3.2 Nil pun with care
(defn print-seq [s]
(when (seq s)
(prn (first s))
(recur (rest s))))
;; #'user/print-seq
(print-seq [1 2])
@noahlz
noahlz / element-search.clj
Created January 7, 2012 02:37
idomatic search using persistent set in Clojure
(re-find #"A|B|C" "B") ;; Two Problems
;=> "B"
(some #(= % "B") ["A" "B" "C"]) ;; A little better...but not the same
;=> true
(get #{ "A" "B" "C"} "B") ;; more readable?
;=> "B"
(#{"A" "B" "C"} "B") ;; Idiomatic per Joy of Clojure
@noahlz
noahlz / joy-of-clojure-lazy-qsort.clj
Created January 11, 2012 03:37
Lazy QuickSort implementation in Clojure, from Joy of Clojure chapter 6.
(ns joy.q)
;; nil
(defn nom [n] (take n (repeatedly #(rand-int n))))
;; #'joy.q/nom
(defn sort-parts [work]
(lazy-seq
(loop [[part & parts] work] ;; Pull apart work - note: work will be a list of lists.
(if-let [[pivot & xs] (seq part)] ;; This blows up unless work was a list of lists.
@noahlz
noahlz / joy-of-clojure-ch7-notes.clj
Created January 14, 2012 04:06
Notes from Joy of Clojure - Chapter 7 - Functional Programming
;; Example of using comp
(map (comp keyword #(.toLowerCase %) name) '(a B C))
;=> (:a :b :c)
;; equpivalent code using -> (but which doesn't use functions as data.
(map #(-> % (name) (.toLowerCase) (keyword)) '[a B C])
;=> (:a :b :c)
;; Using partial
@noahlz
noahlz / CompletionServiceExample.java
Created June 15, 2012 14:59
Toy application that demonstrates the java.util.concurrent.ExecutorCompletionService
import java.util.Random;
import java.util.concurrent.*;
/**
* App that tests completion service.
*/
public class CompletionServiceExample {
private static final int COUNT = 25;
@noahlz
noahlz / ActionProcessor.java
Last active August 9, 2023 21:26
My Java "Rorschach Test."
package com.transacttools.imaginary;
import com.transacttools.imaginary.util.ActionUtils;
import java.util.Date;
import java.text.SimpleDateFormat;
/**
* This class processes actions from the User Interface.
*
* TODO: Get this ready for production!
@noahlz
noahlz / maxsubarray.c
Created June 29, 2012 18:31
Implementation of the O(N) max subarray algorithm described in Programming Pearls.
#include <stdio.h>
// see http://stackoverflow.com/a/7943955/7507
int main(int argc, char *argv[]) {
int bestSoFar = 0;
int bestNow = 0;
int bestStartIndexSoFar = -1;
int bestStopIndexSoFar = -1;
@noahlz
noahlz / factorials.clj
Created July 2, 2012 21:59
Factorial computation in clojure
(defn factorial-using-recur [x]
(loop [current x
next (dec current)
total 1]
(if (> current 1)
(recur next (dec next) (* total current))
total)))
(defn factorial-using-reduce [x]
(reduce * (range 1 (inc x))))