Skip to content

Instantly share code, notes, and snippets.

View nickbauman's full-sized avatar
🎯
Focusing

Nick Bauman nickbauman

🎯
Focusing
View GitHub Profile
(ns haversine
(:require [math.numeric-tower :refer [expt sqrt]]))
(def RADIUS_OF_EARTH 6371.0088)
(defn radians [degrees]
(/ (* degrees Math/PI) 180))
(defn haversine
[lat1 lon1 lat2 lon2]
@nickbauman
nickbauman / anagram.clj
Created November 15, 2021 22:15
Clojure anagram detector
(defn split-string [word]
(into #{} (clojure.string/split word #"")))
(defn anagram-of? [word candidate]
(boolean (when (= (count word) (count candidate))
(let [word-list (split-string word)
cand-list (split-string candidate)]
(= #{} (clojure.set/difference cand-list word-list))))))
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Arrays;
import java.util.TreeSet;
/*
Report the frequency of 100k random selections of strings in an array
*/
(defn make-change
[target-amount coins]
(let [sorted (reverse (sort coins))]
(loop [amount target-amount
coins-frequency {}]
(if (zero? amount)
coins-frequency
(let [coin (first (filter #(<= % amount) sorted))
count (quot amount coin)]
(recur (- amount (* count coin)) (merge-with + coins-frequency {coin count})))))))
@nickbauman
nickbauman / future_value.go
Last active August 2, 2024 16:25
Future value of investment
package future_value
import "math"
func futureValue(investmentAmount, interestRate, inflationRate, years float64) (float64, float64) {
furtureValue := investmentAmount * math.Pow(1+interestRate/100, years)
futureRealValue := furtureValue / math.Pow(1+inflationRate/100, years)
return furtureValue, futureRealValue
}