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
module Set | |
( findSets | |
, Shape (..) | |
, Color (..) | |
, Shade (..) | |
, Card (..) | |
, Count (..) | |
) where | |
import Data.List (nub, sort, tails) |
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 main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"strconv" | |
"strings" | |
) |
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
module Main where | |
import Data.Char (isSpace) | |
import qualified Data.List as D | |
import qualified Data.List.Split as S | |
import qualified Data.Map.Strict as M | |
import Data.Maybe (fromMaybe) | |
import qualified Text.Read as TR | |
data Score = Score |
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
almostFactorial = (\f -> (\n -> if n == 0 then 1 else n * f (n - 1))) | |
facA = almostFactorial facA | |
facA 3 -- returns 6 |
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 ycomb.core | |
(:gen-class)) | |
(def almost-factorial | |
(fn [f] | |
(fn [n] | |
(if (= n 0) | |
1 | |
(* n (f (- n 1))))))) |
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 A* | |
"Finds a path between start and goal inside the graph described by edges | |
(a map of edge to distance); estimate is an heuristic for the actual | |
distance. Accepts a named option: :monotonic (default to true). | |
Returns the path if found or nil." | |
[edges estimate start goal & {mono :monotonic :or {mono true}}] | |
(let [f (memoize #(estimate % goal)) ; unsure the memoization is worthy | |
neighbours (reduce (fn [m [a b]] (assoc m a (conj (m a #{}) b))) | |
{} (keys edges))] | |
(loop [q (priority-map start (f start)) |
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 A* | |
"Finds a path between start and goal inside the graph described by edges | |
(a map of edge to distance); estimate is an heuristic for the actual | |
distance. Accepts a named option: :monotonic (default to true). | |
Returns the path if found or nil." | |
[edges estimate start goal & {mono :monotonic :or {mono true}}] | |
(let [f (memoize #(estimate % goal)) ; unsure the memoization is worthy | |
neighbours (reduce (fn [m [a b]] (assoc m a (conj (m a #{}) b))) | |
{} (keys edges))] | |
(loop [q (priority-map start (f start)) |
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
;; Three very fundamental operators in any sort of programming are map, filter | |
;; and reduce. | |
;; They represent the common programming tasks of transforming a collection, | |
;; selecting from it, and summing over it. | |
;; Most people think that map and filter are fairly obvious, but there seems to | |
;; be a certain amount of confusion about reduce. | |
;; But it's actually very simple in concept, and represents an easy idea. |
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
-- problem 1 | |
sum [ x | x <- [1..999], x `mod` 3 == 0 || x `mod` 5 == 0 ] | |
-- problem 2 | |
fibs = 0 : 1 : zipWith (+) fibs (tail fibs) | |
sum [ x | x <- takeWhile (<= 4*10^6) $ drop 2 fibs, even ] | |
-- problem 3 | |
prime n | |
| n < 2 = False |
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 epoch | |
[] | |
(quot (System/currentTimeMillis) 1000)) | |
(let [cache (atom {})] | |
(defn add-key | |
[k v expire] | |
(swap! cache assoc k {:v v, :e expire, :c (epoch)})) | |
(defn del-key |