Guest User

projecteuler 18

a guest
Aug 10th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.77 KB | None | 0 0
  1. #my try on https://projecteuler.net/problem=18
  2.  
  3. #error:
  4. #/home/x3nu/Dev/euler/problem18.rb:12:in `block in <main>': undefined method `>' for nil:NilClass (NoMethodError)
  5. #from /home/x3nu/Dev/euler/problem18.rb:5:in `each_line'
  6. #from /home/x3nu/Dev/euler/problem18.rb:5:in `<main>'
  7. #75
  8. #blaaaaaa
  9. #[Finished in 0.1s with exit code 1]
  10.  
  11.  
  12. position = 0
  13. sum = 75
  14. array = []
  15.  
  16. File.open("18.txt", "r").each_line do |line|
  17.     puts line
  18.     array = line.split(",").map { |s| s.to_i }
  19.     posA = position
  20.     posB = position + 1
  21.     if array[posB] != false
  22.         puts "blaaaaaa"
  23.         if array[posB] > array[posA]
  24.             sum += array[posB]
  25.             position = posB
  26.         else
  27.             sum += array[posA]
  28.             position = posA
  29.         end
  30.     else
  31.         sum += array[posA]
  32.         position = posA
  33.     end
  34. end
  35. puts position
  36. puts sum
Advertisement
Add Comment
Please, Sign In to add comment