day3_part1.carbon 642 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/3
  5. import Core library "io";
  6. import library "day3_common";
  7. import library "io_utils";
  8. fn Run() {
  9. var total: i32 = 0;
  10. while (PeekChar() != Core.EOF()) {
  11. if (PeekChar() == 0x6D) {
  12. // TODO: Use `if let` when available.
  13. let result: (bool, i32, i32) = ReadMul();
  14. if (result.0) {
  15. total += result.1 * result.2;
  16. }
  17. } else {
  18. ReadChar();
  19. }
  20. }
  21. Core.Print(total);
  22. }