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 num-of-ones | |
(:require [clojure.test :refer [deftest is]])) | |
(defn n->digits | |
"ex. (n->digits 14) => [1 4]" | |
[n] | |
(if (< n 10) | |
[n] | |
(conj (n->digits (quot n 10)) (rem n 10)))) | |
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 swap-pairs | |
(:require [clojure.test :refer [deftest is]])) | |
(defn swap-pairs [coll] | |
(->> (partition 2 coll) | |
(mapcat (fn [[a b]] | |
[b a])) | |
(into []))) | |
(deftest swap-pairs-test |
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 format-markdown-table | |
(:require [clojure.string :as s])) | |
(defn format-column [column width] | |
(for [row column | |
:let [word (s/trim row) | |
new-word (str "| " (format (str "%-" (dec width) "s") word)) | |
dashes (str "| " (apply str (repeat (- width 2) "-")) " ")]] | |
(if (= (second word) \-) | |
dashes |
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 from-to | |
(:require [clojure.test :refer [deftest is]])) | |
(defn from-to [lower upper] | |
(let [gen (atom (dec lower))] | |
(fn [] | |
(when (< @gen upper) | |
(swap! gen inc) | |
(deref gen))))) | |
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 three.core | |
(:require ["three" :as three])) | |
(defn make-animation-fn [renderer mesh scene camera] | |
(fn animation [time] | |
(set! (.. mesh -rotation -x) (/ time 2000)) | |
(set! (.. mesh -rotation -y) (/ time 2000)) | |
(.render renderer scene camera))) | |
(defn cube [] |
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 calculate-gpa | |
(:require [clojure.test :refer [deftest is]])) | |
(def grade->points | |
{:A 4 | |
:A- 3.7 | |
:B+ 3.3 | |
:B 3 | |
:B- 2.7 | |
:C+ 2.3 |
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 fib-like | |
(:require [clojure.test :refer [deftest is]])) | |
(defn fibber [a b] | |
(lazy-seq | |
(cons a (fibber b (+ a b))))) | |
(defn fib-like [a b n] | |
(take n | |
(fibber a b))) |
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 truncate | |
(:require [clojure.test :refer [deftest is])) | |
(defn truncate [s n] | |
(let [tokens (re-seq #"\W+|_|[a-zA-Z]+" s) | |
word? #(re-find #"\w+" %) | |
truncate-w (fn [token] | |
(if (and (word? token) | |
(> (count token) n)) | |
(subs token 0 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
(ns pass-doors | |
(:require [clojure.test :refer [deftest is])) | |
(defn pass-doors [n number-of-passes] | |
(let [initial (repeat n 1) | |
passes (range number-of-passes) | |
toggle-door (fn [d] (if (zero? d) 1 0)) | |
create-sections (fn [doors pass] | |
(map vec (partition-all (inc pass) doors))) | |
toggle-section (fn [section pass] |
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 print-ascii) | |
(defn print-ascii [] | |
(doseq [i (range 0x20 0x7F)] | |
(print (char i)))) | |
;; If you want to print in sections exactly as shown in the prompt | |
(defn print-ascii-sections [] | |
(doseq [section (partition-all 16 (range 0x20 0x7F))] | |
(println (apply str (map char section))))) |
OlderNewer