Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
|
|
@ -0,0 +1,21 @@
|
|||
# syntax: GAWK -f MAXIMUM_TRIANGLE_PATH_SUM.AWK filename(s)
|
||||
{ printf("%s\n",$0)
|
||||
cols[FNR] = NF
|
||||
for (i=1; i<=NF; i++) {
|
||||
arr[FNR][i] = $i
|
||||
}
|
||||
}
|
||||
ENDFILE {
|
||||
for (row=FNR-1; row>0; row--) {
|
||||
for (col=1; col<=cols[row]; col++) {
|
||||
arr[row][col] += max(arr[row+1][col],arr[row+1][col+1])
|
||||
}
|
||||
}
|
||||
printf("%d using %s\n\n",arr[1][1],FILENAME)
|
||||
delete arr
|
||||
delete cols
|
||||
}
|
||||
END {
|
||||
exit(0)
|
||||
}
|
||||
function max(x,y) { return((x > y) ? x : y) }
|
||||
|
|
@ -44,7 +44,7 @@ public program()
|
|||
{
|
||||
for(int j := 0, j < 18, j += 1)
|
||||
{
|
||||
list[i][j] := mathControl.max(list[i][j] + list[i+1][j], list[i][j] + list[i+1][j+1])
|
||||
list[i][j] := max(list[i][j] + list[i+1][j], list[i][j] + list[i+1][j+1])
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
'''Maximum triangle path sum'''
|
||||
|
||||
from functools import (reduce)
|
||||
from itertools import (starmap)
|
||||
|
||||
|
||||
# maxPathSum :: [[Int]] -> Int
|
||||
def maxPathSum(rows):
|
||||
'''The maximum total among all possible
|
||||
paths from the top to the bottom row.
|
||||
'''
|
||||
return reduce(
|
||||
lambda xs, ys: list(starmap(
|
||||
lambda a, b, c: a + max(b, c),
|
||||
zip(ys, xs, xs[1:])
|
||||
)),
|
||||
lambda xs, ys: [
|
||||
a + max(b, c) for (a, b, c) in zip(ys, xs, xs[1:])
|
||||
],
|
||||
reversed(rows[:-1]), rows[-1]
|
||||
)[0]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue