day4_part2.carbon 849 B

1234567891011121314151617181920212223242526272829
  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 Core library "range";
  7. import library "day4_common";
  8. import library "io_utils";
  9. fn Run() {
  10. var search: Wordsearch = Wordsearch.Read();
  11. var mas: array(i32, 3) = (0x4D, 0x41, 0x53);
  12. var found: i32 = 0;
  13. for (y: i32 in Core.InclusiveRange(1, 138)) {
  14. for (x: i32 in Core.InclusiveRange(1, 138)) {
  15. if ((search.Check3(mas, x - 1, y - 1, 1, 1) or
  16. search.Check3(mas, x + 1, y + 1, -1, -1)) and
  17. (search.Check3(mas, x - 1, y + 1, 1, -1) or
  18. search.Check3(mas, x + 1, y - 1, -1, 1))) {
  19. ++found;
  20. }
  21. }
  22. }
  23. Core.Print(found);
  24. }