File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ ; ; https://4clojure.oxal.org/#/problem/079
2
+
3
+ (ns ex.q079 )
4
+
5
+ (defn ans
6
+ " Problem 79, Triangle Minimal Path"
7
+ ([coll]
8
+ (ans coll 0 ))
9
+ ([coll idx]
10
+ (let [curr (nth (first coll) idx)
11
+ next-rows (rest coll)]
12
+ (if (empty? next-rows)
13
+ curr
14
+ (let [left (ans next-rows idx)
15
+ right (ans next-rows (inc idx))]
16
+ (+ curr (min left right)))))))
Original file line number Diff line number Diff line change
1
+ ; ; https://4clojure.oxal.org/#/problem/079
2
+
3
+ (ns ex.q079-test
4
+ (:require [clojure.test :as t]
5
+ [ex.q079 :as sut]))
6
+
7
+ (t/deftest test-q79
8
+ (t/testing " Problem 79, Triangle Minimal Path"
9
+ (t/is (= 7
10
+ (+ 1 2 1 3 )
11
+ (sut/ans
12
+ [[1 ]
13
+ [2 4 ]
14
+ [5 1 4 ]
15
+ [2 3 4 5 ]])))
16
+ (t/is (= 20
17
+ (+ 3 4 3 2 7 1 )
18
+ (sut/ans
19
+ [[3 ]
20
+ [2 4 ]
21
+ [1 9 3 ]
22
+ [9 9 2 4 ]
23
+ [4 6 6 7 8 ]
24
+ [5 7 3 5 1 4 ]])))))
You can’t perform that action at this time.
0 commit comments