Skip to content

Commit 54f4ee6

Browse files
committed
Add q79.. difficult, had to cheat
1 parent 547c409 commit 54f4ee6

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/ex/q079.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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)))))))

test/ex/q079_test.clj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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]])))))

0 commit comments

Comments
 (0)