mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
In line with the proposal in #4682, this changes the array syntax to be array(T, N). `array` is a builtin keyword which must be followed by parens containing two expressions and a separating comma. The array type expression is still fully builtin, it does not forward to a Core.Array library type yet. It merely adds the `ArrayType` instruction, as was done with the previous syntax. Followup work will change the instruction to reference to Core.Array, once the library type exists and can be used directly. --------- Co-authored-by: zygoloid <richard@metafoo.co.uk>
34 lines
710 B
Plaintext
34 lines
710 B
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
// https://adventofcode.com/2024/day/1
|
|
|
|
import Core library "io";
|
|
|
|
import library "day1_common";
|
|
import library "sort";
|
|
|
|
fn Run() {
|
|
var a: array(i32, 1000);
|
|
var b: array(i32, 1000);
|
|
var n: i32 = ReadInputs(&a, &b);
|
|
Quicksort(&a, 0, n);
|
|
Quicksort(&b, 0, n);
|
|
|
|
var i: i32 = 0;
|
|
var j: i32 = 0;
|
|
var similarity: i32 = 0;
|
|
while (i < n and j < n) {
|
|
if (a[i] < b[j]) {
|
|
++i;
|
|
} else {
|
|
if (a[i] == b[j]) {
|
|
similarity += b[j];
|
|
}
|
|
++j;
|
|
}
|
|
}
|
|
Core.Print(similarity);
|
|
}
|