Skip to content

Instantly share code, notes, and snippets.

@chase-lambert
chase-lambert / roll_call.clj
Created December 2, 2024 21:54
rendezvous with cassidoo challenge: 24.12.02
(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
@chase-lambert
chase-lambert / max_the_stock.clj
Last active November 19, 2024 05:16
rendezvous with cassidoo challenge: 24.11.17
(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))
@chase-lambert
chase-lambert / group_anagrams.clj
Created November 4, 2024 22:01
rendezvous with cassidoo challenge: 24.11.03
(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"])
@chase-lambert
chase-lambert / split.clj
Created October 5, 2024 15:15
rendezvous with cassidoo challenge: 24.09.30
(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]
@chase-lambert
chase-lambert / execution_times.clj
Created August 21, 2024 01:41
rendezvous with cassidoo challenge: 24.08.19
(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)
@chase-lambert
chase-lambert / squares.clj
Last active August 5, 2024 15:27
rendezvous with cassidoo challenge: 24.08.05
(ns squares
(:require [clojure.test :refer [deftest is]]
[criterium.core :as cc]))
(defn squares [n]
(let [nums (range 1 (inc n))]
(->> nums
(map #(* % %))
(reduce +))))
@chase-lambert
chase-lambert / fruit_stand.clj
Last active July 1, 2024 17:18
rendezvous with cassidoo challenge: 24.07.01
(ns fruit-stand
"Example stand -> {\"apple\" {:name \"apple\" :quantity 10 :price 0.5}
\"banana\" {:name \"banana\" :quantity 5 :price 0.2}}\n
Input for `add-fruit` and `update-quantity` would be validated (parsed)
at the call source, hence no error handling in the functions themselves.")
(defonce stand (atom {}))
(defn add-fruit [{:keys [name] :as fruit}]
(swap! stand assoc name fruit))
@chase-lambert
chase-lambert / fix_inverted_punc.clj
Last active June 21, 2024 23:06
rendezvous with cassidoo challenge: 24.05.21
(ns fix-inverted-punc
(:require [clojure.test :refer [deftest is]))
(defn fix-inverted-punc [s]
(let [sentences (->> (re-seq #".+?[.!?]" s)
(map str/trim))]
(->> sentences
(map (fn [sentence]
(let [first-char (first sentence)
last-char (last sentence)]
@chase-lambert
chase-lambert / max_product.clj
Created May 14, 2024 16:04
rendezvous with cassidoo challenge: 24.05.13
(ns max-product
(:require [clojure.test :refer [deftest is]]))
(defn max-product [nums]
(->> (sort nums)
(take-last 3)
(reduce * 1)))
(deftest max-product-test
(is (= 72 (max-product [2 4 1 3 -5 6]))))
@chase-lambert
chase-lambert / unique_sum.rs
Created April 2, 2024 18:32
rendezvous with cassidoo challenge: 24.04.01
pub fn unique_sum(nums: &[i32]) -> i32 {
nums.iter()
.filter(|&&n| {
let mut chars_set = std::collections::HashSet::new();
// `insert(t)` on a hashset returns false if `t` already exists.
n.to_string().chars().all(|c| chars_set.insert(c))
})
.sum()
}