Hacker News new | past | comments | ask | show | jobs | submit login

Compare this with two python solutions. The first was when I was learning python and is similar to how I would solve it in C. The second is a copy of that haskell solution:

  tri = [[75],[95, 64]...]
  maxes = [x[:] for x in tri]
  for y in range(len(maxes)-2, -1, -1):
    for x in range(len(maxes[y])-1, -1, -1):
      maxes[y][x] = maxes[y][x] + max(maxes[y+1][x], maxes[y+1][x+1])
  print maxes[0][0]

  print reduce(
    lambda y, x: map(
      lambda(t): t[0] + max(t[1], t[2]),
      zip(x, y, y[1:])),
    tri[::-1])[0]
I find the first one much easier to comprehend even though they do the same thing and use the same general algorithm of reduce()ing the rows. In general, I find procedural code much easier to read when I take a look at it months down the line.



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: