I finally got around to doing day 3. For part one I read the input into a matrix and added a border around the entire thing so I could go backwards or forwards in any direction by one space and not have to worry about where I was reading. The first part was easy, but life intruded and slowed me down. I doubt my solution is all that optimal either, but it works, so whatever. For part two, I made another matrix and stored the value of each number in every position it occupied, then scanned through a second time for each asterisk and where it touched two numbers. It took me far too long to think of that solution and it's even less optimal since I scan the input twice, but it works. I don't know if I'll be able to make time to work on any other days, but I'll give it a shot. I don't know what the deal is lately, but the amount of time I have to do anything fun is a dwindling supply.
The code may break if one line ends with number while the next line starts with number. It seems not to be the case for all input lines. Maybe adding a "." before flatten the inputs would be a good precaution.
Impressive, but when you create a flat vector of inputs, how come you don't concatenate the number at the very end of the line with the number at the very beginning of the next line?
Surprisingly, that doesn't happen in the input! I think there's a few tricks in there to make solving it somewhat more easy (for example, no number is in contact with two symbols). If that did happen, I would need to do something like pad zeroes on the left of the matrix, flatten into a vector and do the parsing, then mix it back into a matrix and remove the first zero from every row. A few extra characters, but not too bad.
I finally got around to doing day 3. For part one I read the input into a matrix and added a border around the entire thing so I could go backwards or forwards in any direction by one space and not have to worry about where I was reading. The first part was easy, but life intruded and slowed me down. I doubt my solution is all that optimal either, but it works, so whatever. For part two, I made another matrix and stored the value of each number in every position it occupied, then scanned through a second time for each asterisk and where it touched two numbers. It took me far too long to think of that solution and it's even less optimal since I scan the input twice, but it works. I don't know if I'll be able to make time to work on any other days, but I'll give it a shot. I don't know what the deal is lately, but the amount of time I have to do anything fun is a dwindling supply.
The code may break if one line ends with number while the next line starts with number. It seems not to be the case for all input lines. Maybe adding a "." before flatten the inputs would be a good precaution.
That’s a really elegant way to handle that case!
Can you show this in ngn/k please.
Impressive, but when you create a flat vector of inputs, how come you don't concatenate the number at the very end of the line with the number at the very beginning of the next line?
Surprisingly, that doesn't happen in the input! I think there's a few tricks in there to make solving it somewhat more easy (for example, no number is in contact with two symbols).
If that did happen, I would need to do something like pad zeroes on the left of the matrix, flatten into a vector and do the parsing, then mix it back into a matrix and remove the first zero from every row. A few extra characters, but not too bad.
I just dropped in here and..WTF is all this symbols and language
As the title says, APL.