This file contains hidden or 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 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] |
This file contains hidden or 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
(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)))))) |
This file contains hidden or 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
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 | |
*/ |
This file contains hidden or 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
(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}))))))) |
This file contains hidden or 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
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 | |
} |
OlderNewer