Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,6 @@
|
|||
(defn trapped-water [towers]
|
||||
(let [maxes #(reductions max %) ; the seq of increasing max values found in the input seq
|
||||
maxl (maxes towers) ; the seq of max heights to the left of each tower
|
||||
maxr (reverse (maxes (reverse towers))) ; the seq of max heights to the right of each tower
|
||||
mins (map min maxl maxr)] ; minimum highest surrounding tower per position
|
||||
(reduce + (map - mins towers)))) ; sum up the trapped water per position
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
;; in the following, # is a tower block and ~ is trapped water:
|
||||
;;
|
||||
;; 10|
|
||||
;; 9| #
|
||||
;; 8| #
|
||||
;; 7| # ~ ~ ~ ~ #
|
||||
;; 6| # ~ # ~ ~ #
|
||||
;; 5| # ~ # ~ # ~ # #
|
||||
;; 4| # ~ # ~ # # # #
|
||||
;; 3| # # # ~ # # # #
|
||||
;; 2| # # # # # # # # ~ #
|
||||
;; 1| # # # # # # # # # #
|
||||
;; ---+---------------------
|
||||
;; 5 3 7 2 6 4 5 9 1 2
|
||||
(trapped-water [5 3 7 2 6 4 5 9 1 2]) ;; 14
|
||||
Loading…
Add table
Add a link
Reference in a new issue