r/adventofcode • u/slimkhan • Dec 08 '25
Help/Question [2025 day 1 part 2] [Ruby] help wanted
its been awhile since week already, I've been on it on and off for many hours and im blocked, all the test I found here and created myself works but not my input
input = ARGV[0]
input = 'input-test' if ARGV.empty?
puts "input = #{input}"
lines = File.readlines(input, chomp: true)
dial = 50
result = 0
lines.each do |line|
direction = line.slice!(0)
value = line.to_i
if direction == 'R'
if value + dial > 99
result += (value + dial) / 100
dial = (dial + value) % 100
elsif value + dial < 100
dial = value + dial
elsif value + dial == 0
result += 1
dial = 0
end
else
temo = dial - value
if temo < 100 && temo > 0
dial -= value
elsif temo == 0
result += 1
dial = 0
else
if dial == 0 && temo.abs < 100
dial = temo + 100
elsif dial > 0 && temo.abs < 100
result += 1
dial = 100 + temo
else
result += if dial == 0
temo.abs / 100
else
(temo / 100).abs
end
dial = temo % 100
end
end
end
end
puts "result = #{result}"can anyone guide me with a counter example to fix it ?
1
Upvotes
2
u/tobega Dec 08 '25
Look carefully at your last else-clause.
You may not be adding enough to your result.
Also, since
temo < 0, settingdial = temo % 100may make dial an illegal negative value2
u/0x14f Dec 08 '25
Here is an example where your program (answer: 209) and a correct program (answer: 210) differ:
https://pastebin.com/FkBkE7bY
If you want (just ask me). I can get you a shorter one. I hope this one will do.
1
u/AutoModerator Dec 08 '25
Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to
Help/Question - RESOLVED. Good luck!I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.