aboutsummaryrefslogtreecommitdiff
path: root/julia
diff options
context:
space:
mode:
Diffstat (limited to 'julia')
-rw-r--r--julia/081-path_sum_two_ways.jl34
1 files changed, 34 insertions, 0 deletions
diff --git a/julia/081-path_sum_two_ways.jl b/julia/081-path_sum_two_ways.jl
new file mode 100644
index 0000000..77a90a4
--- /dev/null
+++ b/julia/081-path_sum_two_ways.jl
@@ -0,0 +1,34 @@
+# matrix = [
+# [131, 673, 234, 103, 18],
+# [201, 96, 342, 965, 150],
+# [630, 803, 746, 422, 111],
+# [537, 699, 497, 121, 956],
+# [805, 732, 524, 37, 331],
+# ]
+
+matrix = open(f -> read(f, String), "data/081_matrix.txt") |>
+ split |>
+ m -> map(l -> map(x -> parse(Int, x), split(l, ",")), m)
+
+for (i, _) in enumerate(matrix)
+ for (j, _) in enumerate(matrix[i])
+ if i == 1 && j == 1
+ continue
+ end
+ if i == 1
+ up = Inf
+ else
+ up = matrix[i - 1][j]
+ end
+ if j == 1
+ left = Inf
+ else
+ left = matrix[i][j - 1]
+ end
+ matrix[i][j] += min(up, left)
+ end
+end
+
+result = matrix[length(matrix)][length(matrix[1])]
+
+println(result)