I hereby claim:
- I am polgfred on github.
- I am polgfred (https://keybase.io/polgfred) on keybase.
- I have a public key ASABXivtQUvG-O5P9HZwU3eVC6BCbL6U92BcwZSRhxs1MAo
To claim this, I am signing this object:
function gameOfLife(pop) { | |
const newpop = {}; | |
for (const coord in pop) { | |
const parts = coord.split(','); | |
const x = Number(parts[0]); | |
const y = Number(parts[1]); | |
for (let dx = -1; dx <= 1; ++dx) { | |
for (let dy = -1; dy <= 1; ++dy) { | |
newpop[`${x+dx},${y+dy}`] = true; | |
} |
I hereby claim:
To claim this, I am signing this object:
require 'flickraw' | |
require 'retriable/core_ext/kernel' | |
# set your api key and secret | |
FlickRaw.api_key = 'xxx' | |
FlickRaw.shared_secret = 'xxx' | |
# set your oauth access token and secret (you need to authenticate) | |
flickr.access_token = 'xxx' | |
flickr.access_secret = 'xxx' |
;; Suppose that `n` and `d` are procedures of one argument (the term index `i`) | |
;; that return the N(i) and D(i) of the terms of the continued fraction. Define a | |
;; procedure cont-frac such that evaluating (cont-frac n d k) computes the value | |
;; of the k-term finite continued fraction: | |
;; | |
;; N(1) | |
;; f = -------------------- | |
;; N(2) | |
;; D(1) + ------------ | |
;; . N(K) |
var Tree = exports.Tree = function(value, branches) { | |
// @param: value => the value held by this node in the tree | |
// @param: branches => the child nodes of this tree | |
// @returns: the Tree | |
this.value = value | |
this.branches = branches | |
} | |
Tree.unfold = function(seed, transformer) { | |
// @param: seed => the initial seed value for constructing the tree |
data Node t = Leaf t | Branch [(Node t)] | |
-- this is the emitter | |
emit :: Node Char -> [Char] | |
emit (Leaf c) = [c] | |
emit (Branch ns) = "(" ++ (concat (map emit ns)) ++ ")" | |
main = putStrLn (emit (Branch [ | |
Leaf 'A', | |
Leaf 'B', |
(declare read-term) | |
;; accumulate terms from an input sequence until \) | |
(defn read-terms [[c & more :as input] acc] | |
(if (= c \)) [(reverse acc) more] | |
(let [[term input] (read-term input)] | |
(recur input (cons term acc))))) | |
;; read one term from an input param | |
(defn read-term [[c & more]] |
reverseDigits base value = pullFrom value 0 | |
where pullFrom 0 t = t | |
pullFrom v t = pullFrom (div v base) ((t * base) + (mod v base)) |
;; return one sequence from s along with the unread input | |
(defn read-seq [s] | |
(loop [input (rest s) acc ()] | |
(let [[c & more] input] | |
(cond (= \) c) [(reverse acc) more] | |
(= \( c) (let [[term input] (read-seq input)] | |
(recur input (cons term acc))) | |
:else (recur more (cons c acc)))))) | |
(println (first (read-seq (vec "(ABC(DE(FGH)I)J)")))) |
(defn reverse-digits [value base] | |
(loop [v value t 0] | |
(if (zero? v) | |
t | |
(recur (quot v base) (+ (* t base) (rem v base)))))) |