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 find-longest-streak | |
(:require [clojure.test :refer [deftest is]])) | |
(defn find-longest-streak [bools goal] | |
(let [longest-streak (->> bools | |
(partition-by identity) | |
(filter first) | |
(map count) | |
(apply max 0))] | |
(if (>= longest-streak goal) |
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
---@diagnostic disable: undefined-global | |
-- ============================================================ | |
-- Bootstrapping & Plugin Management | |
-- ============================================================ | |
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" | |
if not vim.loop.fs_stat(lazypath) then | |
vim.fn.system({ | |
"git", | |
"clone", | |
"--filter=blob:none", |
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
(require '[clojure.core.async :as a]) | |
(def xform (comp (map inc) | |
(filter even?) | |
(dedupe) | |
(flatmap range) | |
(partition-all 3) | |
(partition-by #(< (apply + %) 7)) | |
(flatmap flatten) | |
(random-sample 1.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
#!/usr/bin/env bb | |
;; A Babashka script to concatenate all Clojure files in a repository into a single file. | |
;; Respects .gitignore patterns and includes clear file separation markers. | |
;; | |
;; Usage: | |
;; ./onefile.clj ; uses current git repo and default output | |
;; ./onefile.clj /path/to/repo ; uses custom repo path | |
;; ./onefile.clj /path/to/repo out.clj ; specifies output filename | |
;; |
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 roll-call | |
(:require [clojure.test :refer [deftest is]])) | |
(defn roll-call [names] | |
(->> names | |
(map reverse) | |
(map (partial apply str)) | |
sort)) | |
(deftest roll-call-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 max-the-stock | |
(:require [clojure.test :refer [deftest is]])) | |
(defn max-the-stock [prices] | |
(->> (rest prices) | |
(reduce (fn [[min-price max-profit] price] | |
[(min min-price price) | |
(max max-profit (- price min-price))]) | |
[(first prices) 0]) | |
second)) |
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 group-anagrams | |
(:require [clojure.test :refer [deftest is]])) | |
(defn group-anagrams [words] | |
(vals (group-by set words))) | |
(deftest group-anagrams-test | |
(is (= (group-anagrams ["eat" "tea" "tan" "ate" "nat" "bat"]) | |
[["eat" "tea" "ate"] ["tan" "nat"] ["bat"]])) | |
(is (= (group-anagrams ["vote" "please"]) |
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 split | |
"Prompt: Implement your own String split() function | |
in your preferred programming language. | |
My solution is only for single character separators | |
so is not nearly as useful as Clojure's version | |
allowing for regexes." | |
(:require [clojure.test :refer [deftest is]])) | |
(defn split [s sep] |
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 execution-times | |
"assumes each task/function is only run once | |
and logs are clean so that the start and end | |
times of each task show up consecutively in | |
their respective order." | |
(:require [clojure.test :refer [deftest is]])) | |
(defn calculate-execution-times [logs] | |
(reduce (fn [acc [task1 task2]] | |
(let [task (:name task1) |
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 squares | |
(:require [clojure.test :refer [deftest is]] | |
[criterium.core :as cc])) | |
(defn squares [n] | |
(let [nums (range 1 (inc n))] | |
(->> nums | |
(map #(* % %)) | |
(reduce +)))) |
NewerOlder