Skip to content

Commit

Permalink
prepare to loop
Browse files Browse the repository at this point in the history
  • Loading branch information
codingzorro committed Jan 14, 2024
1 parent 0b8654f commit 9416c81
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions doc/day01.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ The calibration is a two-digit number "encrypted" in each line:
* extract all digits contained in the line: 1, 3 and 5 in this case
* take the first and the last one to get the calibration: 15 in this case

**Note:** We will start by implementing the calibration and only after that we
will implement the "main loop" to accumulate the sum of calibrations.

### Step 1: Write the tests
It is clear that we need at least two functions:
* `(decode "a1b2c3d4e5f")` shall return `[1 3 5]`
Expand All @@ -28,3 +31,5 @@ Note that they fail; i.e, they are "red" according to the TDD terminology.
### Step 2: Go from "green" to "red"
Tag [morning-01-green](https://github.com/codingzorro/advent2023/releases/tag/morning-01-green)
implements the functions needed to pass the existing tests

###
2 changes: 0 additions & 2 deletions src/advent2023/day01.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
[[a b]]
(+ (* a 10) b))



(defn decode
"extract digits in a string; e.g. \"a1b2\" --> [1 2]"
[a-string]
Expand Down
16 changes: 11 additions & 5 deletions test/advent2023/day01_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
(:require [clojure.test :refer :all]
[advent2023.day01 :refer :all]))


(def sample-data
["1abc2"
"pqr3stu8vwx"
"a1b2c3d4e5f"
"treb7uchet"])

(deftest decode-test
(testing "Extract the digits in a given string"
(is (= (decode "1abc2") [1 2]))
(is (= (decode "pqr3stu8vwx") [3 8]))
(is (= (decode "a1b2c3d4e5f") [1 2 3 4 5]))
(is (= (decode "treb7uchet") [7]))
))
(is (= (decode (sample-data 0)) [1 2]))
(is (= (decode (sample-data 1)) [3 8]))
(is (= (decode (sample-data 2)) [1 2 3 4 5]))
(is (= (decode (sample-data 3)) [7]))))

(deftest to-int-test
(testing "Extract the digits in a given string"
Expand Down

0 comments on commit 9416c81

Please sign in to comment.