day1_common.carbon 657 B

1234567891011121314151617181920212223
  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/1
  5. library "day1_common";
  6. import library "io_utils";
  7. // Read a sequence of lines each containing a pair of numbers into two arrays.
  8. // Returns the number of lines read.
  9. fn ReadInputs(ap: [i32; 1000]*, bp: [i32; 1000]*) -> i32 {
  10. var n: i32 = 0;
  11. var a: i32;
  12. var b: i32;
  13. while (n < 1000 and ReadInt(&a) and SkipSpaces() and ReadInt(&b) and SkipNewline()) {
  14. (*ap)[n] = a;
  15. (*bp)[n] = b;
  16. ++n;
  17. }
  18. return n;
  19. }