Skip to content

Commit

Permalink
2023: fix some bugs exposed by additional inputs
Browse files Browse the repository at this point in the history
Using the randomly-generated inputs from
https://questionable.engineering/posts/aoc-inputs-2023/
  • Loading branch information
yut23 committed Feb 2, 2024
1 parent 3d6f8a8 commit ff6bd86
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
*/profiling/
*/perf.data
*/perf.data.old
/2023/unofficial-aoc2023-inputs/
# clangd cache
*/.cache/
2 changes: 1 addition & 1 deletion 2023/src/day14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void solve(int argc, char **argv, bool print) {
<< "\n";
}
// skip to the final cycle iteration
step += (max_step - step) / cycle_length * cycle_length;
step += (max_step - step - 1) / cycle_length * cycle_length;
if constexpr (aoc::DEBUG) {
std::cerr << "skipped to " << step << "\n";
}
Expand Down
15 changes: 9 additions & 6 deletions 2023/src/day19.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ std::ostream &operator<<(std::ostream &os, const Range &r) {

void Range::add_condition(const Condition &cond) {
if (cond.greater) {
start = cond.threshold + 1;
start = std::max(start, cond.threshold + 1);
} else {
end = cond.threshold - 1;
end = std::min(end, cond.threshold - 1);
}
}

Expand All @@ -373,14 +373,17 @@ long Part2Solver::count_combinations(const std::deque<Condition> &conditions) {
for (const Condition &cond : conditions) {
std::cerr << " " << cond;
}
std::cerr << "\n";
}
for (const Condition &cond : conditions) {
ranges[cond.rating_idx].add_condition(cond);
}
return std::transform_reduce(ranges.begin(), ranges.end(), 1L,
std::multiplies<>{},
[](const Range &r) { return r.size(); });
long count = std::transform_reduce(ranges.begin(), ranges.end(), 1L,
std::multiplies<>{},
[](const Range &r) { return r.size(); });
if constexpr (aoc::DEBUG) {
std::cerr << ": " << count << " combinations\n";
}
return count;
}

} // namespace aoc::day19
Expand Down
2 changes: 2 additions & 0 deletions 2023/src/day21.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ long Garden::part_2() const {
es.print_stats();
}
long reachable = es.get_reachable();
#if 0
int i = es.get_iter();
if (stones.width == 131) {
if (target_distance == 2023 * 1 * stones.width + start.x) {
Expand Down Expand Up @@ -414,6 +415,7 @@ long Garden::part_2() const {
}
}
}
#endif
return reachable;
}

Expand Down
47 changes: 47 additions & 0 deletions 2023/test_unofficial_inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json
import subprocess
import sys


def test_on_input(day: int, input_name: str, expected_answers: tuple[int, int]) -> bool:
result = subprocess.run(
[
f"build/fast/day{day:02d}",
f"unofficial-aoc2023-inputs/day_{day:03d}/{input_name}",
],
check=False,
text=True,
stdout=subprocess.PIPE,
)
if result.returncode != 0:
print(f"Day {day}, {input_name}: exited with status {result.returncode}")
return False
answers = tuple(map(int, result.stdout.splitlines(keepends=False)))
correct = True
for i in range(2):
if not isinstance(expected_answers[i], int):
continue
if answers[i] != expected_answers[i]:
print(
f"Day {day}, {input_name}: part {i+1} incorrect; expected {expected_answers[i]}, got {answers[i]}"
)
correct = False
return correct


def main() -> int:
subprocess.run(["make", "-j", "fast"], check=True)
failure_count = 0
for day in range(1, 26):
with open(f"unofficial-aoc2023-inputs/day_{day:03d}/solutions.json", "r") as f:
solutions = json.load(f)
for input_name, answers in solutions.items():
if not test_on_input(
day, input_name, (answers["part_one"], answers["part_two"])
):
failure_count += 1
return failure_count


if __name__ == "__main__":
sys.exit(main())

0 comments on commit ff6bd86

Please sign in to comment.