SHARE
TWEET

Untitled

a guest Dec 5th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns day02
  2.   (:require [clojure.string :as str]))
  3.  
  4. (def input
  5.     (into [] (map read-string
  6.                   (-> "input.txt"
  7.                       (slurp)
  8.                       (str/split #",")))))
  9.  
  10. (let [ints (atom input)]
  11.   (loop [i 0]
  12.     (case (nth @ints i)
  13.       1 (swap! ints assoc (nth @ints (+ i 3))
  14.                (+ (nth @ints (nth @ints (+ i 1)))
  15.                   (nth @ints (nth @ints (+ i 2)))))
  16.       2 (swap! ints assoc (nth @ints (+ i 3))
  17.                (* (nth @ints (nth @ints (+ i 1)))
  18.                   (nth @ints (nth @ints (+ i 2)))))
  19.       99 (println "Program complete:" @ints)
  20.       (println "Something went wrong"))
  21.     (if (>= i (- (count @ints) 1))
  22.       (println "Solution:" (nth @ints 0))
  23.       (if (< 4 (- (count @ints) i))
  24.         (recur (+ i 4))))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top