Skip to content

Instantly share code, notes, and snippets.

@ajkamel
Last active August 29, 2015 14:07
Show Gist options
  • Save ajkamel/0b368a9a88d5a018714f to your computer and use it in GitHub Desktop.
Save ajkamel/0b368a9a88d5a018714f to your computer and use it in GitHub Desktop.

Revisions

  1. ajkamel revised this gist Oct 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion triangle_sum.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ I first found this problem when looking at a Yodle engineering challenge questio

    Basically you this takes a file with lines of numbers and finds the largest sum by totaling the largest adjacent numbers for each new line.

    ```
    ```ruby
    triangle_array = []

    f = File.open("triangle.txt", "r")
  2. ajkamel renamed this gist Oct 4, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. ajkamel renamed this gist Oct 4, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. ajkamel renamed this gist Oct 4, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. ajkamel revised this gist Oct 4, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion triangle_sum
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    I first found this problem when looking at a Yodle engineering challenge question.

    Basically this solution takes a file with lines of numbers and finds the largest sum by totaling the largest adjacent numbers for each new line.
    Basically you this takes a file with lines of numbers and finds the largest sum by totaling the largest adjacent numbers for each new line.

    ```
    triangle_array = []
  6. ajkamel revised this gist Oct 4, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion triangle_sum
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    I first found this problem when looking at a Yodle engineering challenge question.

    Basically you this takes a file with lines of numbers and finds the largest sum by totaling the largest adjacent numbers for each new line.
    Basically this solution takes a file with lines of numbers and finds the largest sum by totaling the largest adjacent numbers for each new line.

    ```
    triangle_array = []
  7. ajkamel renamed this gist Oct 4, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. ajkamel renamed this gist Oct 4, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. ajkamel revised this gist Oct 4, 2014. No changes.
  10. ajkamel revised this gist Oct 4, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    I first found this problem when looking at a Yodle engineering challenge question.

    Basically you this takes a file with lines of numbers and finds the largest sum by totaling the largest adjacent numbers for each new line.

    ```
    triangle_array = []

  11. ajkamel created this gist Oct 4, 2014.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    ```
    triangle_array = []

    f = File.open("triangle.txt", "r")
    f.each_line do |line|
    triangle_array << line.split.map(&:to_i)
    end
    f.close

    lines = triangle_array.length

    for i in (lines-2).downto(0).to_a do
    for j in (i).downto(0).to_a do
    triangle_array[i][j] += [triangle_array[i+1][j].to_i,triangle_array[i+1][j+1].to_i].max
    end
    end

    p triangle_array[0][0]

    ```