Skip to content

Instantly share code, notes, and snippets.

@richardeast
richardeast / core.clj
Created March 21, 2019 21:34
Turn css hex colors into a Red Green Blue (RGB) sequence (useful for Quil - https://github.com/quil/quil)
(ns hex-rgb.core
(:require [clojure.test :refer [deftest is testing]]))
;;;; Turn css hex colors into a Red Green Blue (RGB) sequence
;;;; Some simple functions.
(defn hex->num
"Turn a string in hex format into a decimal number"
[^String s]
(Integer/parseInt s 16))
@richardeast
richardeast / roman.clj
Last active May 16, 2019 08:30
4Clojure 104 and 92 - Write and read Roman Numerals
;; See http://www.4clojure.com/problem/104
;; My original boring implimentation:
(fn roman [i]
(loop [roman "" i i]
(cond
(> i 999) (recur (str roman "M") (- i 1000))
(> i 899) (recur (str roman "CM") (- i 900))
(> i 499) (recur (str roman "D") (- i 500))
(> i 99) (recur (str roman "C") (- i 100))
(ns bowling.core
"Bowling Kala - based on http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata
Note: This version is stateless as the whole games score is calculated.
http://www.bowlinggenius.com/ used to check edge cases"
(:require [clojure.test :refer [deftest is testing]]))
(defn spare? [[i j]] (= 10 (+ i j)))
(defn strike? [[i _]] (= 10 i))
(defn strike-bonus
@richardeast
richardeast / fizzbuzz_core.clj
Last active July 1, 2018 22:03
Simple Fizzbuzz in Clojure
(ns fizzbuzz.core
(:require [clojure.test :refer [deftest is testing]]))
(def fizzbuzz? #(= 0 (mod % 15)))
(def buzz? #(= 0 (mod % 5)))
(def fizz? #(= 0 (mod % 3)))
(defn fizzbuzz
[n]
(cond
@richardeast
richardeast / particles.html
Last active April 12, 2018 20:34
Copying/playing with "Seb Lee-Delisle - Getting artistic with code" - Coded with my daughter to experiment in creative coding
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
</head>
<body style="background-color: #000;">
<script>
/* Forked from SymfonyLive London 2015 - Seb Lee-Delisle - Getting artistic with code
* https://www.youtube.com/watch?v=DEpqJr73VMU
@richardeast
richardeast / adding-vectors-in-clojure.clj
Last active April 27, 2025 06:02
Adding vectors in Clojure
;; Add two vectors
(defn add-vec-simple [[x1 y1] [x2 y2]]
[(+ x1 x2) (+ y1 y2)])
;; Add two or more vectors together (First attempt.)
(defn add-vec-better [[x1 y1] & args]
(loop [x x1 y y1 more args]
(if (empty? more)
[x y]
(recur (+ x (first (first more)))