Skip to content

Instantly share code, notes, and snippets.

@Romain-P
Created January 3, 2018 18:14
Show Gist options
  • Select an option

  • Save Romain-P/ec37cab7d9150f9669221cb2cf657088 to your computer and use it in GitHub Desktop.

Select an option

Save Romain-P/ec37cab7d9150f9669221cb2cf657088 to your computer and use it in GitHub Desktop.
static int pyramid_path_alt(int size, int **map, int x, int y)
{
if (y == size - 1)
return (map[y][x]);
int a = pyramid_path_alt(size, map, x, y + 1);
int b = pyramid_path_alt(size, map, x + 1, y + 1);
int choosen = a < b ? a : b;
return (map[y][x] + choosen);
}
int pyramid_path(int size, int **map)
{
return (pyramid_path_alt(size, map, 0, 0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment