Skip to content

Instantly share code, notes, and snippets.

@danownsthisspace
Last active December 21, 2021 08:24
Show Gist options
  • Save danownsthisspace/671596eb4010f62c8dda7a7e61a853ee to your computer and use it in GitHub Desktop.
Save danownsthisspace/671596eb4010f62c8dda7a7e61a853ee to your computer and use it in GitHub Desktop.
Advent-of-code day1 2021
(ns scratch
(:require [clojure.string :as str]))
;; (def input [1, 2, 3, 4, 5, 7, 1, 9, 10])
(def input (map #(Integer/parseInt %) (str/split-lines (slurp "input-data.txt"))))
(take 3 input)
(def combined-input (loop [input-nums input
values-to-check []]
(if (= (count input-nums) 2)
values-to-check
(let [combined-vals (reduce + (take 3 input-nums))]
(recur (rest input-nums) (conj values-to-check combined-vals))))))
(defn check-depths [input-depths]
(loop [input-nums input-depths
counter 0]
(if (= (count input-nums) 1)
counter
(let [first-val (first input-nums)
second-val (second input-nums)
next-counter (if (> second-val first-val) (inc counter) counter)]
(recur (rest input-nums) next-counter)))))
(check-depths combined-input)
const fs = require('fs')
// const input = [1, 2, 3, 4, 5, 7, 1, 9, 10]
// const input = [ [1, 2, 3], [2, 3, 4] , [3, 4, 5]]
fs.readFile('input-data.txt', 'utf-8', (err, data) => {
const input = data.split('\n').map((x) => Number(x))
const valuesToCheck = []
let counter = 0
for (let i = 0; i < input.length; i++) {
valuesToCheck.push(input.slice(i, i + 3).reduce((acc, v) => acc + v, 0))
}
for (let i = 0; i < valuesToCheck.length; i++) {
const firstVal = valuesToCheck[i]
const secondVal = valuesToCheck[i + 1]
if (secondVal > firstVal) {
++counter
}
}
console.log('Counter=', counter)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment