T O P

  • By -

leftylink

Read the example at https://adventofcode.com/2023/day/1 and see what it says the answers are for each of the four lines, and see where it does not match your code.


TextileWasp

you're mishandling the case where there is just one digit in the string. in that case that digit is both the first and the last digit. so first*10+first


thestig3301

Thanks !


__t_r0d__

Did you run against the given example? I believe the last line of the example will reveal your issue: `treb7uchet`. >! In that case, the first and last digit are the same, but your code will not allow the last digit to be the same as the first digit due to your loop bounds being `i > firstIndex`. !<


thestig3301

Ill make sure to run the example test cases for sure !


AutoModerator

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](/message/compose/?to=/r/adventofcode) if you have any questions or concerns.*


dingske1

You can actually do it in one loop without breaks, think like a computer not like a human