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
| ; Improved version of quicksort - uses destructuring for more concise code | |
| ; Quicksort works as follows. From the given list of numbers, choose a "pivot". Now make two piles - one consisting of the numbers | |
| ; which are less than the pivot, the other greater than the pivot. And sort each one (recursively). Then concat everything to return the | |
| ; final list. See http://www.sorting-algorithms.com/quick-sort | |
| (defn qsort | |
| "sort a list of numbers using quicksort" | |
| [[pivot & remaining]] | |
| (if (nil? pivot) | |
| nil |
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
| ;some simple code to determine if a number is prime. | |
| (defn isPrime? | |
| "returns true if the input number is a prime number, false otherwise" | |
| [n] | |
| (let [divisors (range 2 (inc (int (Math/sqrt n)))) | |
| remainders (map #(mod n %) divisors)] | |
| (not-any? #(= % 0) remainders))) | |
| (defn nPrimes | |
| "compute list of first N primes and optionally apply a function to each" |
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
| Verifying that +soumendradaas is my blockchain ID. https://onename.com/soumendradaas |
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
| ; a deliberately ineffienct code to generate the nth Fibonacci number | |
| (defn fibonacci | |
| [n] | |
| (if (< n 2) | |
| n | |
| (+ (fibonacci (- n 1)) (fibonacci (- n 2))))) | |
| ; generate the first 10 fibonacci numbers | |
| (map fibonacci (range 10)) |
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
| ; Given a CSV file and a list of column names, this function loads all the records into a in-memory data structure. | |
| ; For example, consider a CSV file that contains the first/last name of persons, their age, and zip code | |
| ; | |
| ;Smith,John,45,90210 | |
| ;Frank,Peter,25,90110 | |
| ;Dalton,Timothy,38,90110 | |
| ;Hayes,Fred,45,92101 | |
| ; | |
| ;Define a vector that contains the column names [ :firstname :lastname :age :zip ] | |
| ;And a vector of functions specifying how each column is to be transformed after reading [ identity identity #(Integer. %) #(Integer. %)] |