Last active
December 20, 2015 08:44
-
-
Save v-kolesnikov/b72ac436c60b89e1a1da to your computer and use it in GitHub Desktop.
Найти максимальную сумму элементов строки матрицы
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
(defn solution | |
[m] | |
(->> m | |
(map #(reduce + %)) | |
(apply max))) | |
(let [m [[1 2 3] | |
[0 -1 2] | |
[4 1 -2]]] | |
(assert (= 6 (solution m)))) | |
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
def solution(m) | |
m.map { |row| row.inject(:+) }.max | |
end | |
m = [[1, 2, 3], | |
[0, -1, 2], | |
[4, 1, -2]] | |
puts solution(m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment