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
;; answer from unlogic to 4clojure.com problem 28 | |
(defn flat [node] | |
(reduce #(concat % (if (coll? %2) (flat %2) [%2])) | |
() | |
node)) |
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
def ds1 = [1, 2, [3, 4, [5, "a"]]]; | |
def isSequential(x) { | |
x instanceof Collection | |
} | |
def mapcat(f, coll) { | |
coll.inject([]) { x, y -> | |
def res = f(y) | |
if (isSequential(res)) { |
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 example.stdin) | |
(defn -main | |
"Read from STDIN" | |
[& args] | |
(println "Enter text:") | |
(loop [input (read-line)] | |
(when-not (= ":done" input) | |
(println (str "You entered: >>" input "<<")) |
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 example.stdin) | |
(defn do-something-cool [v] | |
(println v)) | |
(defn -main | |
"Read from STDIN" | |
[& args] | |
(println "Enter text:") |
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 distance [[x y]] | |
(+ (Math/abs x) (Math/abs y))) | |
(defn add-point [m dist v] | |
(let [m2 (if (m dist) | |
(update-in m [dist] conj v) | |
(assoc m dist [v]))] | |
(let [m3 (if (> dist (:hd m2)) | |
(merge m2 {:hd dist}) | |
m2)] |
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 dist-then-first [pt1 pt2] | |
(let [dist1 (distance pt1) | |
dist2 (distance pt2)] | |
(if (= dist1 dist2) | |
(> (first pt1) (first pt2)) | |
(> dist1 dist2)))) | |
(defn mk-sorted-sift-fn [max-size] | |
(fn [sst pt] | |
(if (< (count sst) max-size) |
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 thornydev.lib.leftist-heap) | |
;; Implementation of a "leftist priority queue" on an immutable | |
;; heap data structure | |
;; This code was (manually) transpiled into Clojure from | |
;; the Scheme version here: | |
;; http://programmingpraxis.com/2009/05/05/priority-queues/2/ | |
;; ---[ core lib fns ]--- ;; |
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 thornydev.top100.heap | |
(:require [thornydev.lib.leftist-heap | |
:refer [pq-first pq-rest pq-insert pq-empty]])) | |
(defn distance [[x y]] | |
(+ (java.lang.Math/abs x) (java.lang.Math/abs y))) | |
(defn dist-lt? [pt1 pt2] | |
(< (distance pt2) (distance pt1))) |
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 ( | |
"fmt" | |
"math/rand" | |
"time" | |
"os" | |
) | |
// Channels-driven concurrency with Go |
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 thornydev.go-lightly | |
(:refer-clojure :exclude [peek take]) | |
(:import (java.io Closeable) | |
(java.util ArrayList) | |
(java.util.concurrent LinkedTransferQueue TimeUnit | |
LinkedBlockingQueue TimeoutException))) | |
;; ---[ go routines ]--- ;; | |
(def inventory (atom [])) |