Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Really useful repo! Got stuck on AoC '22 #13, and the solution from this repo was not accepted (6,104). Maybe I set up the repo incorrectly, but I documented what I see the problem is and my solution to it below.
The problem:
isInOrder(left, right)
returns ties incorrectly as inOrder, while it should just continue to evaluate unless it's the end of the input. For example, take the two example inputs:#1
[[1,2,3,4], 5]
[[1,2,3,4], 3]
#2
[[1,2,3,4], 2]
[[1,2,3,4], 3]
#1 is NOT in order, #2 is in order. However,
isInOrder
returns that BOTH are in order.isInOrder
evaluates the first first element of both lists, sees they are lists. Then it recurses on the list, checking each element. After checking all elements and finding all ties, it returns true (line 138) and pops the recursion. Then line 128/135 return as true, while they should really continue checking the rest of the list since the recursed list was tied.My Solution: add a tied-indicator to
isInOrder
.I modify
isInOrder
to return two booleans, one to indicate if they are in order, the other to indicate if there is a tie. The recursive calls will now only return if an explicitly correct/incorrect ordering was found. If a tie was found,isInOrder
continues to the next element.isInOrder
only returns a tied indicator if it iterates through the whole list without finding an out of order pair and if the list lengths are equal. This returns the correct solution (5,675).