Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #my try on https://projecteuler.net/problem=18
- #error:
- #/home/x3nu/Dev/euler/problem18.rb:12:in `block in <main>': undefined method `>' for nil:NilClass (NoMethodError)
- #from /home/x3nu/Dev/euler/problem18.rb:5:in `each_line'
- #from /home/x3nu/Dev/euler/problem18.rb:5:in `<main>'
- #75
- #blaaaaaa
- #[Finished in 0.1s with exit code 1]
- position = 0
- sum = 75
- array = []
- File.open("18.txt", "r").each_line do |line|
- puts line
- array = line.split(",").map { |s| s.to_i }
- posA = position
- posB = position + 1
- if array[posB] != false
- puts "blaaaaaa"
- if array[posB] > array[posA]
- sum += array[posB]
- position = posB
- else
- sum += array[posA]
- position = posA
- end
- else
- sum += array[posA]
- position = posA
- end
- end
- puts position
- puts sum
Advertisement
Add Comment
Please, Sign In to add comment