-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(ns day03.part1 | ||
(:require [clojure.test :refer [deftest]] | ||
[util :refer [get-resource-path]] | ||
[ysera.test :refer [is=]])) | ||
|
||
|
||
(defn process-input | ||
{:test (fn [] | ||
(is= (process-input ::example1) | ||
[[2 4] | ||
[5 5] | ||
[11 8] | ||
[8 5]]))} | ||
[name] | ||
(let [path (get-resource-path name) | ||
text (slurp path)] | ||
(->> (re-seq #"mul\((\d+),(\d+)\)" text) | ||
(map rest) | ||
(map (partial map ^[String] Integer/parseInt)) | ||
(map vec) | ||
(vec)))) | ||
|
||
|
||
(defn solve | ||
[name] | ||
(->> (process-input name) | ||
(map (partial reduce *)) | ||
(reduce +))) | ||
|
||
|
||
(deftest example | ||
(is= (solve ::example1) | ||
161)) | ||
|
||
|
||
(deftest input | ||
(is= (solve ::input) | ||
188741603)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(ns day03.part2 | ||
(:require [clojure.test :refer [deftest]] | ||
[util :refer [get-resource-path]] | ||
[ysera.test :refer [is=]])) | ||
|
||
|
||
(defn process-input | ||
{:test (fn [] | ||
(is= (process-input ::example2) | ||
[[2 4] | ||
false | ||
[5 5] | ||
[11 8] | ||
true | ||
[8 5]]))} | ||
[name] | ||
(let [path (get-resource-path name) | ||
text (slurp path)] | ||
(->> (re-seq #"mul\((\d+),(\d+)\)|do\(\)|don't\(\)" text) | ||
(map (fn [m] (case (first m) | ||
"do()" true | ||
"don't()" false | ||
(->> (rest m) | ||
(map ^[String] Integer/parseInt) | ||
(vec))))) | ||
(vec)))) | ||
|
||
|
||
(defn solve | ||
[name] | ||
(->> (process-input name) | ||
(reduce (fn [[acc active] instruction] | ||
(cond | ||
(boolean? instruction) [acc instruction] | ||
active [(+ acc | ||
(reduce * instruction)) | ||
active] | ||
:else [acc active])) | ||
[0 true]) | ||
(first))) | ||
|
||
|
||
(deftest example | ||
(is= (solve ::example2) | ||
48)) | ||
|
||
|
||
(deftest input | ||
(is= (solve ::input) | ||
67269798)) |