Skip to content

Instantly share code, notes, and snippets.

@chase-lambert
chase-lambert / num_of_ones.clj
Last active May 17, 2023 00:44
rendezvous with cassidoo challenge: 22.07.31
(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))))
@chase-lambert
chase-lambert / swap_pairs.clj
Last active May 17, 2023 00:44
rendezvous with cassidoo challenge: 22.08.08
(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
@chase-lambert
chase-lambert / format_markdown_table.clj
Last active May 17, 2023 00:44
rendezvous with cassidoo challenge: 22.08.21
(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
@chase-lambert
chase-lambert / from_to.clj
Last active May 17, 2023 00:43
rendezvous with cassidoo challenge: 22.09.04
(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)))))
@chase-lambert
chase-lambert / three_core.cljs
Last active October 18, 2022 01:53
three.js -> cljs demo
(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 []
@chase-lambert
chase-lambert / calculate_gpa.clj
Last active May 17, 2023 00:43
rendezvous with cassidoo: 22.09.18
(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
@chase-lambert
chase-lambert / fib_like.clj
Last active May 17, 2023 00:43
rendezvous with cassidoo challenge: 22.10.02
(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)))
@chase-lambert
chase-lambert / truncate.clj
Last active May 17, 2023 00:43
rendezvous with cassidoo challenge: 22.10.10
(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)
@chase-lambert
chase-lambert / pass_doors.clj
Last active May 17, 2023 00:42
rendezvous with cassidoo challenge: 22.10.17
(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]
@chase-lambert
chase-lambert / print_ascii.clj
Last active May 17, 2023 00:42
rendezvous with cassidoo challenge: 22.10.30
(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)))))