This file contains 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
# Returns an enumerator that generates password from the standard dictionary | |
# Only parameter is the number of words to use. | |
# Example: passwordy(2).next -> "GarlicUngulp" | |
def passwordy(wc=4) | |
words = File.readlines('/usr/share/dict/words') | |
.select {|w| w.size>5 && w.size<=9} | |
.shuffle | |
Enumerator.new do |yielder| | |
yielder.yield(words |
This file contains 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
PAIRS="..LEXEGEZACEBISOUSESARMAINDIREA.ERATENBERALAVETIEDORQUANTEISRION" | |
planet = (3+rand(2)).times.map { PAIRS[rand(32) * 2,2] }.join.gsub('.', '').capitalize |
This file contains 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
; | |
; Generate a table of the products of prime numbers | |
; | |
(defn √ [x] | |
"Integer square root of x" | |
(int (Math/sqrt x))) | |
(defn prime? [x] | |
"Return true if x is a prime number, using naïve trial division algorithm." |
This file contains 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
(require '[clojure.test.check.generators :as gen]) | |
; Elite planet name letter pairs (http://www.iancgbell.clara.net/elite/text/index.htm) | |
(def pair (gen/elements [[ ] [\L \E] [\X \E] [\G \E] [\Z \A] [\C \E] [\B \I] [\S \O] | |
[\U \S] [\E \S] [\A \R] [\M \A] [\I \N] [\D \I] [\R \E] [\A ] | |
[\E \R] [\A \T] [\E \N] [\B \E] [\R \A] [\L \A] [\V \E] [\T \I] | |
[\E \D] [\O \R] [\Q \U] [\A \N] [\T \E] [\I \S] [\R \I] [\O \N]])) | |
; Generator of Elite-like planet names. Uses a similar algorithm but replaces the use | |
; of a seeded series of numbers with test.check generators. |
This file contains 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
defmodule RomanNumerals do | |
# Roman Numerals (Elixir) | |
@digits %{"I" => 1, | |
"V" => 5, | |
"X" => 10, | |
"L" => 50, | |
"C" => 100, | |
"D" => 500, | |
"M" => 1000} |
This file contains 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 RomanNumeral exposing (numeral_to_number) | |
type Digit = I | V | X | L | C | D | M | |
value : Digit -> number | |
value d = | |
case d of | |
I -> 1 | |
V -> 5 |
This file contains 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
; Neo4J CREATE | |
(defn- format-props [props] | |
"Format a map of {:symbol String} to Cypher format" | |
(->> | |
props | |
seq | |
(map (fn [[k v]] (format "%s: %s" (name k) (pr-str v)))) | |
(clojure.string/join ", "))) |
This file contains 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
; https://en.wikipedia.org/wiki/Midpoint_circle_algorithm | |
(defn mirror-point [x0 y0 x y] | |
[[(+ x0 x) (+ y0 y)] | |
[(+ x0 y) (+ y0 x)] | |
[(- x0 y) (+ y0 x)] | |
[(- x0 x) (+ y0 y)] | |
[(- x0 x) (- y0 y)] | |
[(- x0 y) (- y0 x)] | |
[(+ x0 y) (- y0 x)] |
This file contains 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
#!/usr/bin/env planck | |
; | |
; Coding night challenge - Scrabble | |
; Generate a rack of tiles and find highest scoring word | |
; | |
; Written in ClojureScript running on Planck | |
; http://planck-repl.org/guide-all.html | |
; | |
; To run on OS X: |
This file contains 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 zuhlke.codingnight.binary) | |
; | |
; Coding night challenge - Binary | |
; Convert string of binary digits to int | |
; | |
(defn binary-str-to-int [s] | |
(loop [s (reverse s) | |
acc 0 | |
pwr 1] |
OlderNewer