day4_part1.carbon 796 B

123456789101112131415161718192021222324252627282930
  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 xmas: array(i32, 4) = (0x58, 0x4D, 0x41, 0x53);
  12. var found: i32 = 0;
  13. for (y: i32 in Core.Range(140)) {
  14. for (x: i32 in Core.Range(140)) {
  15. for (dy: i32 in Core.InclusiveRange(-1, 1)) {
  16. for (dx: i32 in Core.InclusiveRange(-1, 1)) {
  17. if (search.Check4(xmas, x, y, dx, dy)) {
  18. ++found;
  19. }
  20. }
  21. }
  22. }
  23. }
  24. Core.Print(found);
  25. }