Created
December 1, 2021 18:30
-
-
Save digininja/509fd1bd8169d274587d1b0d6c042318 to your computer and use it in GitHub Desktop.
Solution to day 1 part 2 of advent of code challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
count = 0 | |
previous = 999999999999999 | |
current = 0 | |
block1=0 | |
block2=0 | |
block3=0 | |
pos=0 | |
File.readlines('input').each do |line| | |
num = line.to_i | |
puts "Read number is: " + line | |
puts "pos: " + pos.to_s | |
if pos % 3 == 0 | |
puts "Block 1: " + block1.to_s | |
current = block1 | |
block1 = 0 | |
end | |
if pos % 3 == 1 | |
puts "Block 2: " + block2.to_s | |
current = block2 | |
block2 = 0 | |
end | |
if pos % 3 == 2 | |
puts "Block 3: " + block3.to_s | |
current = block3 | |
block3 = 0 | |
end | |
block1 = block1 + num | |
if pos > 0 | |
block2 = block2 + num | |
end | |
if pos > 1 | |
block3 = block3 + num | |
end | |
if pos > 2 | |
if current > previous | |
count = count + 1 | |
end | |
previous = current | |
end | |
pos = pos + 1 | |
end | |
puts "Block 1: " + block1.to_s | |
puts "Block 2: " + block2.to_s | |
puts "Block 3: " + block3.to_s | |
if current > previous | |
count = count + 1 | |
end | |
puts count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment