day5_part1.carbon 635 B

1234567891011121314151617181920212223242526
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. // https://adventofcode.com/2024/day/5
  5. import Core library "io";
  6. import library "day5_common";
  7. import library "io_utils";
  8. fn Run() {
  9. var rules: Rules = Rules.Read();
  10. SkipNewline();
  11. var total: i32 = 0;
  12. while (true) {
  13. var page_list: PageList = PageList.Read();
  14. if (page_list.num_pages == 0) {
  15. break;
  16. }
  17. if (page_list.FollowsRules(rules)) {
  18. total += page_list.MiddlePage();
  19. }
  20. }
  21. Core.Print(total);
  22. }