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 put (s) | |
print s | |
STDOUT.flush | |
end |
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
#!/usr/bin/env ruby | |
require 'flickraw' | |
FlickRaw.api_key = "YOUR FLICKR API KEY" | |
FlickRaw.shared_secret = "YOUR FLICKR SHARED SECRET" | |
ARGV[0] ||= "kittens" | |
search_query = ARGV[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
(server/add-middleware | |
friend/authenticate | |
{ :credential-fn (partial creds/bcrypt-credential-fn users) | |
:workflows [(workflows/interactive-form)] | |
:login-uri "/login" | |
:unauthorized-redirect-uri "/login" | |
:default-landing-uri "/" }) | |
(pre-route [:any "/app/*"] { :as req } (let [id (friend/identity req)] | |
(when-not (friend/authorized? [::user] id) (friend/throw-unauthorized id {})))) |
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 bell | |
"Returns the nth Bell number" | |
[n] | |
(cond | |
(= n 0) 1 | |
(= n 1) 1 | |
:else (reduce + (map #(abs (stirling-2 n %)) (range 0 (inc n)))))) |
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- stirling-loop-internal | |
[^long n ^long k compfunc] | |
{ :pre [(<= k n)] } | |
(let [workitems (for [n' (range 1 (inc n)) k' (range 0 (inc (- n k))) | |
:when (and (>= (- n' k') 0) (>= k (- n' k')))] [n' (- n' k')])] | |
(loop [current (first workitems) items (rest workitems) results {}] | |
(cond | |
(= current [n k]) ((compfunc current results) current) | |
(= (current 0) (current 1)) | |
(recur (first items) (rest items) |
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 natural? | |
"Returns true if n is a natural number (greater than zero, and with no | |
fractional component), else false." | |
[n] | |
(and (> n 0) (zero? (rem n 1)))) | |
(defn nth-sgonal | |
"For a given s-gonal number P(s,n) = x, returns n (n is a natural number if | |
x is a term of the given s-gonal sequence)." | |
^double [^long x ^long s] |
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 palindrome? [n] (let [numseq (seq (str n))] (= (reverse numseq) numseq))) | |
(defn euler-4 [] | |
(apply max | |
(for [x (range 999 900 -1) y (range x 900 -1) | |
:when (palindrome? (* x y))] | |
(* x y)))) |
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 prog-sum | |
"Calculates the sum of an arithmetic progression" | |
([n a] (prog-sum n a a)) | |
([n a d] (/ (* n (+ (* 2 a) (* (dec n) d))) 2))) | |
(defn euler-1 [n f1 f2] | |
(let [ | |
b (dec n) | |
d1 (quot b f1) | |
d2 (quot b f2) |
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
#(some {[:o :o :o] :o [:x :x :x] :x} | |
(partition 3 | |
(map | |
(vec (flatten %)) | |
[0 1 2 3 4 5 6 7 8 | |
0 3 6 1 4 7 2 5 8 | |
0 4 8 2 4 6]))) |
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
;; by inecas (http://www.4clojure.com/user/inecas) | |
(fn [c] | |
(set (map set | |
(filter #(< 1 (count %)) | |
(vals (group-by sort c)))))) |