Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 21 lines (17 sloc) 0.517 kb
fa89d893 » Andrey Paramonov
2010-03-06 Next chunk of solutions
1 // inspired by
2 // http://blog.dreamshire.com/2009/04/01/project-euler-problem-18-solution
93bb0229 » Andrey Paramonov
2010-05-08 Added more algorithms to recursion.groovy
3 // See also http://en.wikipedia.org/wiki/Dynamic_programming
fa89d893 » Andrey Paramonov
2010-03-06 Next chunk of solutions
4
5 // to solve problem 67 replace file name to triangle67.txt
6
7 def max(x, y) {
8 x < y ? y : x
9 }
10
11 triangle = []
12 new File('triangle18.txt').eachLine { line ->
13 triangle << line.split(/ /)*.toInteger()
14 }
15 (triangle.size()-1).downto(1) { i ->
16 0.upto(i-1) { j ->
17 triangle[i-1][j] += max(triangle[i][j], triangle[i][j+1])
18 }
19
20 }
21 println triangle[0][0]
Something went wrong with that request. Please try again.