day4_part1.carbon 863 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 xmas: [i32; 4] = (0x58, 0x4D, 0x41, 0x53);
  11. var found: i32 = 0;
  12. // TODO: Use for loops once they're implemented.
  13. var y: i32 = 0;
  14. while (y < 140) {
  15. var x: i32 = 0;
  16. while (x < 140) {
  17. var dy: i32 = -1;
  18. while (dy <= 1) {
  19. var dx: i32 = -1;
  20. while (dx <= 1) {
  21. if (search.Check4(xmas, x, y, dx, dy)) {
  22. ++found;
  23. }
  24. ++dx;
  25. }
  26. ++dy;
  27. }
  28. ++x;
  29. }
  30. ++y;
  31. }
  32. Core.Print(found);
  33. }