Skip to content

Instantly share code, notes, and snippets.

@Ariarule
Ariarule / gist:7424829
Created November 12, 2013 03:08
;; ariarule's solution to Intervals ;; https://4clojure.com/problem/171 ;; Slightly bleh
(fn [s]
(vec (apply sorted-set (map vec (let [t (set (sort s))
w (rest (butlast t))
v (sort (if (empty? t) t (cons (first t) (conj (vec (map first
(remove
#(and (contains? (second %) 1) (contains? (second %) -1))
(reduce #(assoc %1 %2 (set (map (partial - %2) t))) {} w)))) (last t)))))]
(if (empty? v)
;; ariarule's solution to Generating k-combinations
;; https://4clojure.com/problem/103
(fn [n z]
(set (filter #(= (count %) n)
(reduce (fn [seqs b]
(mapcat
(fn [s] (#(map (partial conj %) z) s)) seqs)) [#{}] (range n)))))
@Ariarule
Ariarule / 4clojue-78-ariarule.clj
Created June 13, 2012 23:04
Reimplement Trampoline (4clojure)
(fn [f & s]
(let [result (apply f s)]
(if (fn? result)
(recur result ())
result)))
@Ariarule
Ariarule / 4clojure-118-ariarule.clj
Created June 13, 2012 22:29
Reimplement Map (4clojure)
(fn mm [f s]
(lazy-seq
(let [fs (f (first s))]
(if (next s)
(cons fs (mm f (next s)))
(list fs)))))
@Ariarule
Ariarule / time-balance.clj
Created April 13, 2012 18:33
time-balance
(defn time-balance [schedule time-track excluded-items]
(- (time-until-the-end time-track)
(time-left-to-do schedule excluded-items)))
;; ariarule's solution to Global take-while
;; https://4clojure.com/problem/114
(fn [n p s]
(take (dec (count (take-while #(< % n)
(reduce #(let [n (if %2
(inc (last %1))
(last %))]
(conj %1 n))
[0]
@Ariarule
Ariarule / goggles.js
Created November 10, 2011 21:13
Safety Goggles
/////////////////////
// SafetyGoggles
// @name SafetyGoggles
// @version 0.1.10082010
// @description Highlighlights Weasel Words in Text. Just a proof of concept version.
// @include http://*
// THIS VERSION IS SLOW AND SOMETIMES BREAKS LINKS -- Still needs work
var docbod;
docbod = document.body;