From 8f6717afdbf4284b7e0d5be8d9cdf94bcec0b8fb Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Sat, 20 Jun 2026 19:40:59 +0000 Subject: [PATCH] [Sync Iteration] cpp/grains/1 --- solutions/cpp/grains/1/grains.cpp | 17 +++++++++++++++++ solutions/cpp/grains/1/grains.h | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 solutions/cpp/grains/1/grains.cpp create mode 100644 solutions/cpp/grains/1/grains.h diff --git a/solutions/cpp/grains/1/grains.cpp b/solutions/cpp/grains/1/grains.cpp new file mode 100644 index 0000000..d1928f4 --- /dev/null +++ b/solutions/cpp/grains/1/grains.cpp @@ -0,0 +1,17 @@ +#include "grains.h" + +namespace grains { + + // Devuelve los granos en una casilla específica (1 a 64) + unsigned long long square(int index) { + // Desplazamiento de bits: 1ULL movido (index - 1) posiciones a la izquierda + return 1ULL << (index - 1); + } + + // Devuelve el total de granos en todo el tablero (2^64 - 1) + unsigned long long total() { + // En binario sin signo, invertir los bits de un 0 da el valor máximo posible + return ~0ULL; + // El operador de inversión es '~' + } +} \ No newline at end of file diff --git a/solutions/cpp/grains/1/grains.h b/solutions/cpp/grains/1/grains.h new file mode 100644 index 0000000..302af75 --- /dev/null +++ b/solutions/cpp/grains/1/grains.h @@ -0,0 +1,11 @@ +#pragma once + +namespace grains { + + // Devuelve los granos en una casilla específica (1 a 64) + unsigned long long square(int index); + + // Devuelve el total de granos en el tablero + unsigned long long total(); + +} \ No newline at end of file