Skip to content

Instantly share code, notes, and snippets.

View roman01la's full-sized avatar
🇺🇦

Roman Liutikov roman01la

🇺🇦
View GitHub Profile
@roman01la
roman01la / day6.clj
Created December 6, 2019 11:49
AoC 2019, Day 6
(def input
(-> (slurp "input_2019_6")
clojure.string/trim
(clojure.string/split #"\n")))
(def orbits-graph
(->> input
(map #(clojure.string/split % #"\)"))
(reduce (fn [ret [v k]]
(assoc! ret k v))
@roman01la
roman01la / day5.clj
Created December 5, 2019 20:10
AoC 2019, Day 5
(defn prefix-params [default params]
(let [diff-ln (- (count default) (count params))]
(if-not (== 0 diff-ln)
(str (subs default 0 diff-ln) params)
params)))
(defn read-instruction [s]
(case s
"1" [1 0 0 1]
"2" [2 0 0 1]
@roman01la
roman01la / day4.clj
Last active December 4, 2019 08:08
AoC 2019, Day 4
(defn increasing? [d]
(re-matches #"1*2*3*4*5*6*7*8*9*" d))
(defn repeating-by? [op s]
(->> (frequencies s)
(some #(op 2 (val %)))))
(defn solve-day4-p1 [from to]
(->> (range from (inc to))
(map str)
@roman01la
roman01la / day03.clj
Last active December 4, 2019 00:22
AoC 2019, Day 3
(defn read-move [s]
[(keyword (subs s 0 1))
(read-string (subs s 1))])
(comment
(= [:R 1009] (read-move "R1009")))
(def input
(->> (slurp "input_2019_3")
(clojure.string/split-lines)
@roman01la
roman01la / day02.clj
Created December 3, 2019 00:57
AoC 2019, Day 2
(defn execute-instruction! [opcode input offset]
(let [p1 (nth input (+ 1 offset))
p2 (nth input (+ 2 offset))
p3 (nth input (+ 3 offset))
op (case opcode
1 +
2 *)]
(->> (op (nth input p1) (nth input p2))
(assoc! input p3))))
@roman01la
roman01la / day01.clj
Created December 1, 2019 09:52
AoC 2019, Day 1
(def input
(->> (clojure.string/split (slurp "src/day01_input") #"\s")
(map read-string)))
(defn calc-fuel [m]
(-> m (/ 3) int (- 2)))
(defn solve-day1-p1 [input]
(->> (map calc-fuel input)
(reduce +)))
(ns test.core)
(defn add [^i32 a ^i32 b]
(let [x 1
y 2]
(if (= a b)
(+ x y)
(+ a b))))
(defn main []
@roman01la
roman01la / adapton.ts
Created September 26, 2019 13:45
Adapton
type Thunk = Function;
type Result = any;
class Adapton {
thunk: Thunk;
result: Result;
sub: Set<Adapton>;
sup: Set<Adapton>;
isClean: boolean;
[data-testid="sidebarColumn"] {
display: none;
}
[data-testid="primaryColumn"] {
max-width: 1000px;
}
[data-testid="primaryColumn"] > div:first-child > div:nth-child(3) {
max-width: 800px;
}
[aria-label=Primary] > a > div > div:nth-child(2),
createStore({
dropTargetIDToBoxID: {
"drop1": "box1"
"drop2": "box2"
"drop3": null
},
boxes: {
"box1": {x:0, y: 0},
"box2": {x:100, y: 100},
}