Files
carbon-lang/examples/advent2024/day11_common.carbon
T
Richard SmithandJon Ross-Perkins d2d5c5520b Solutions for advent of code, day 4 - 13. (#4750)
A collection of additional Carbon examples demonstrating current
language capabilities and some limitations of the current state of the
toolchain.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-01-07 19:42:40 +00:00

32 lines
800 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/11
library "day11_common";
import Core library "io";
import library "io_utils";
fn Next(n: i64) -> (i64, i64) {
if (n == 0) { return (1, -1); }
var pow10: i64 = 10;
var pow100: i64 = 1;
while (n / pow100 >= 100) {
pow100 = pow100 * 100;
pow10 = pow10 * 10;
}
if (n / pow100 >= 10) {
return (n / pow10, n % pow10);
}
return (n * 2024, -1);
}
fn Count(n: i64, depth: i32) -> i32 {
if (n == -1) { return 0; }
if (depth == 0) { return 1; }
let next: (i64, i64) = Next(n);
return Count(next.0, depth - 1) + Count(next.1, depth - 1);
}