-
• #452
What would your solution produce for
oneight
? -
• #453
I had a similar problem and figured this was what caught me out, but I've done nothing to try and fix it yet.
-
• #454
Produces 18, originally didn't, but refactored it to after seeing it was a case that needed covering. Really stumped on what's up with it.
-
• #455
What would you produce for
aaa1bbb
-
• #456
Here were my test cases:-
// Provided examples {"1abc2", 1, 1, 2}, {"pqr3stu8vwx", 1, 3, 8}, {"a1b2c3d4e5f", 1, 1, 5}, {"treb7uchet", 1, 7, 7}, {"two1nine", 2, 2, 9}, {"eightwothree", 2, 8, 3}, {"abcone2threexyz", 2, 1, 3}, {"xtwone3four", 2, 2, 4}, {"4nineeightseven2", 2, 4, 2}, {"zoneight234", 2, 1, 4}, {"7pqrstsixteen", 2, 7, 6}, // Edge cases {"two1abc2three", 1, 1, 2}, {"threeightwo", 2, 3, 2}, {"oneight", 2, 1, 8},
Each test entry is a string, then either
1
or2
depending on whether it is for part1 or part2, then the first and last numbers that should be found.So a line like
{"two1abc2three", 1, 1, 2},
should ignore thetwo
at the start and thethree
at the end as they're not searched for in part 1. -
• #457
Even further behind, but I finally got day 1 part 1 done in Z80 assembler: https://github.com/rhowe/aoc/tree/main/2023/01
Part 2 shouldn't be so bad
-
• #458
good god
-
• #459
These are my test cases, with what they produce:
two1nine 29 eightwothree 83 abcone2threexyz 13 xtwone3four 24 4nineeightseven2 42 zoneight234 14 7pqrstsixteen 76 oneight 18 one 1 eightwo 82 1 1 aaa1bbb 1 threeightwo 32
I think I'm ok with just being "done" with day1 now. I will just not have that star. Day2 was nice and smooth.
-
• #460
one 1
there's your problem. Something likeaaa1bbb
should map to11
not1
-
• #461
That caught me out too
-
• #462
My solution to day 1 part two inspired by https://en.wikipedia.org/wiki/Five_(group)
(replace all 'five' with '5ive' in the input, etc)
-
• #463
oh ffs. Thanks! I intentionally guarded against that as well...
-
• #464
Spoke too soon, updated that, updated test cases, ran with actual data, incorrect answer. RIP.
-
• #465
In case anyone has morbid fascination, gist with my code (javascript): https://gist.github.com/ZooeyMiller/aaaf22e14fc5401f06dcd16c3ed8b605
Last year I tried it in haskell, thought I'd make my life easier by doing it in JS this year 🙃
-
• #466
Day 7: ugly code but got there with only a few stumbles, will clean it up once I've had a chance to think of a cleaner way of doing it all.
-
• #467
I might be way off the mark with this, it's a long time since I did anything with JavaScript but does your use of indexof fail when there is only one number in the input string? As cyclotron mentioned an input of "1" and "one" should both produce 11, indexof will only find the first index and you need to also find the last index (which in this case is the same).
-
• #468
The short answer is no, it still works.
The flow is it takes the string, pulls the number (word) or number (int) occurrences out into an object, then organises them into an array in the order they occurred in the original string, and then maps them to the relevant number. Then takes the first and last element of that array and concatenates them together. So
1
will result in an array of ['1'], so concatenating the first and last element of that array together results in 11.But ty for the thought.
-
• #469
Don't have time to go through your code (and I've never really done
.js
) but if you post your input in a gist and the individual numbers each line produces I can see what mine does differently and give you a hint.(You obviously don't just want to be told what the answer should be as there's no fun in that.)
-
• #470
Might require some refactoring, but
findIndex
andfindLastIndex
might be useful, as it means you don't need to care about any of the matches in between. Avoids most of the edge cases. -
• #471
I think your problem is here:
Object.keys(strNumMap).reduce((res, key) => { const index = str.indexOf(key); if (index > -1) { res[key] = index; } return res; }
It's not handling strings with multiple of the same number correctly. E.g.
121
is getting mapped to12
instead of11
. -
• #472
Nice one, that's definitely it.
-
• #473
Yep, that was it. Refactored to get arr of all indexes rather than just the first and got the right answer. Thank you!
Would have been nice to have an example in the test data with that structure, but oh well!
-
• #474
Finally got round to getting day 1 part 2 done (again, Z80 assembler): https://github.com/rhowe/aoc/blob/main/2023/01/part2.S
-
• #475
Definitely lagging behind this year, but enjoyed the Lagrange interpolation solution today.
Running behind, but, day 1 part 2 has stumped me. refactored to account for all edge cases I could think of, solution still wrong, stole a solution from reddit, just to see what the result was, maybe to get an idea of where to go wrong, stolen solution from reddit also doesn't work. Dang.