Skip to content

Instantly share code, notes, and snippets.

@Zhen-hao
Forked from skuro/forkme.md
Last active December 12, 2018 19:34
Show Gist options
  • Save Zhen-hao/de716fe4f5d6d186a55da3800a1d1858 to your computer and use it in GitHub Desktop.
Save Zhen-hao/de716fe4f5d6d186a55da3800a1d1858 to your computer and use it in GitHub Desktop.
Advent of Clojure solutions
(ns advent-of-clojure.core)
(defn next-val [prev]
(mod (* 252533 prev) 33554393))
(defn sum-all [x]
(/ (* x (inc x)) 2))
(defn full-diags [x y]
(- (+ x y) 2))
(defn seq-idx [x y]
(let [diags (full-diags x y)]
(dec (+ y (sum-all diags)))))
(defn seq-gen [init]
(lazy-seq (cons init (seq-gen (next-val init)))))
(defn solve
"Solving https://adventofcode.com/2015/day/25"
[x y]
(nth (seq-gen 20151125)
(seq-idx x y)))
(comment
(let [x 42] (inc x))
((fn [x] (inc x))) 42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment