-
-
Save Zhen-hao/de716fe4f5d6d186a55da3800a1d1858 to your computer and use it in GitHub Desktop.
Advent of Clojure solutions
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 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