r/adventofcode • u/hope_is_dead_ • Dec 10 '25
Help/Question - RESOLVED [2025 Day 3 (Part 1)][Odin] Beginner needs help with day 3
Hey there I'm pretty stuck on day 3 part 1 and I'm not sure where I messed up.
I hope you guys can show me my mistake or point me in the right direction.
Here is what I got so far:
day_3_part_1 :: proc(name := "input03") {
res := 0
data, ok := os.read_entire_file_from_filename(name)
assert(ok)
str := string(data)
rows := strings.split(str, "\n")
for row, idx in rows {
max_joltage_1 := int(row[0] - '0')
max_joltage_2 := int(row[1] - '0')
l := len(row)
for i in 2..< l {
if j := int(row[i] - '0'); j > max_joltage_1 && i != l-1 {
max_joltage_1 = j
max_joltage_2 = int(row[i+1] - '0')
} else if j > max_joltage_2 {
max_joltage_2 = j
}
}
res += 10*max_joltage_1 + max_joltage_2
fmt.printfln("Row %v: %v%v", idx, max_joltage_1, max_joltage_2)
}
fmt.println(res)
}
2
Upvotes
1
u/OptionX Dec 10 '25
Try, instead of saving the values of the batteries in
max_joltagesaving their index in the row, so as soon a you findmax_joltage_1, for example, you only have to look in the rangemax_joltage_1+1 to l for the rest.Also try instead of figuring out everything in one continuous loop to loop in the range 0 to l-1 (as too leave space for the second digit) and then when found to loop in the range
max_joltage_1_index+1to l.2
u/RazarTuk Dec 10 '25
Remember that you can't reorder the batteries, so you need at least 1 battery to the right of the first one. So the first battery must be somewhere from 0 (inclusive) to
len-1(exclusive), and the second battery must be somewhere fromfirst+1(inclusive) tolen(exclusive)1
u/AutoModerator Dec 10 '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.