day4_part2.carbon 868 B

123456789101112131415161718192021222324252627282930313233
  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/4
  5. import Core library "io";
  6. import library "day4_common";
  7. import library "io_utils";
  8. fn Run() {
  9. var search: Wordsearch = Wordsearch.Read();
  10. var mas: [i32; 3] = (0x4D, 0x41, 0x53);
  11. var found: i32 = 0;
  12. // TODO: Use for loops once they're implemented.
  13. var y: i32 = 1;
  14. while (y < 139) {
  15. var x: i32 = 1;
  16. while (x < 139) {
  17. if ((search.Check3(mas, x - 1, y - 1, 1, 1) or
  18. search.Check3(mas, x + 1, y + 1, -1, -1)) and
  19. (search.Check3(mas, x - 1, y + 1, 1, -1) or
  20. search.Check3(mas, x + 1, y - 1, -1, 1))) {
  21. ++found;
  22. }
  23. ++x;
  24. }
  25. ++y;
  26. }
  27. Core.Print(found);
  28. }