From c6aed71a2a4ec0b101a45f4e8457ad54d3537501 Mon Sep 17 00:00:00 2001
From: Pascal Syma
Date: Wed, 2 Dec 2026 16:48:29 +0100
Subject: [PATCH] Solve 2026-02
---
2026/02/2026-02.run.xml | 7 ++++++
2026/02/index.test.ts | 17 ++++++++++++++
2026/02/index.ts | 51 +++++++++++++++++++++++++++++++++++++++++
2026/02/run.ts | 12 ++++++++++
4 files changed, 87 insertions(+)
create mode 100644 2026/02/2026-02.run.xml
create mode 100644 2026/02/index.test.ts
create mode 100644 2026/02/index.ts
create mode 100644 2026/02/run.ts
diff --git a/2026/02/2026-02.run.xml b/2026/02/2026-02.run.xml
new file mode 100644
index 0000000..30931a9
--- /dev/null
+++ b/2026/02/2026-02.run.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/2026/02/index.test.ts b/2026/02/index.test.ts
new file mode 100644
index 0000000..b3c673c
--- /dev/null
+++ b/2026/02/index.test.ts
@@ -0,0 +1,17 @@
+import { describe, expect, it } from 'bun:test';
+import { solveFirst, solveSecond } from './index.ts';
+
+describe('2026-02', () => {
+ it('first', () => {
+ expect(solveFirst(`obbvb`)).toBe(16);
+ expect(solveFirst(`roygbv`)).toBe(11);
+ expect(solveFirst(`vbgyor`)).toBe(30);
+ expect(solveFirst(`vvvvvv`)).toBe(35);
+ });
+ it('second', () => {
+ expect(solveSecond(`rybryb`)).toBe(32);
+ expect(solveSecond(`vrvbvg`)).toBe(33);
+ expect(solveSecond(`groovyyoyo`)).toBe(55);
+ expect(solveSecond(`roygbvroygbvroygbv`)).toBe(103);
+ });
+});
diff --git a/2026/02/index.ts b/2026/02/index.ts
new file mode 100644
index 0000000..726e725
--- /dev/null
+++ b/2026/02/index.ts
@@ -0,0 +1,51 @@
+import { groupBy } from '../../utils/array.ts';
+
+export function solveFirst(input: string): number {
+ const waypoints = 'roygbv';
+ const instr = input.split('');
+
+ let position = 0;
+ let distance = 0;
+
+ for (let i of instr) {
+ const offset = waypoints.indexOf(i);
+ if (offset > position) {
+ distance += offset - position;
+ } else {
+ distance += 6 - position + offset;
+ }
+ // console.log(distance);
+ position = offset;
+ }
+
+ // console.log(instr.map((i) => waypoints.indexOf(i)));
+
+ return distance;
+}
+
+export function solveSecond(input: string): number {
+ const waypoints = 'oygbvr';
+ const instr = input.split('');
+ const groups = groupBy(instr, (e) => e).toSorted(
+ (a, b) => waypoints.indexOf(b.key) - waypoints.indexOf(a.key)
+ );
+
+ let position = 0;
+ let distance = 0;
+ const waypoints2 = 'roygbv';
+ for (let g of groups) {
+ const offset = waypoints2.indexOf(g.key);
+ if (offset > position) {
+ distance += offset - position;
+ } else {
+ distance += 6 - position + offset;
+ }
+ distance += 6 * (g.elements.length - 1);
+ position = offset;
+ }
+ return distance;
+
+ // const newInstr = groups.map((g) => g.elements.join('')).join('');
+ //
+ // return solveFirst(newInstr);
+}
diff --git a/2026/02/run.ts b/2026/02/run.ts
new file mode 100644
index 0000000..88783cd
--- /dev/null
+++ b/2026/02/run.ts
@@ -0,0 +1,12 @@
+import { join } from 'path';
+import { solveFirst, solveSecond } from './index.ts';
+
+const input = await Bun.file(join(__dirname, 'input.txt')).text();
+
+const firstAnswer = solveFirst(input);
+
+console.log(firstAnswer);
+
+const secondAnswer = solveSecond(input);
+
+console.log(secondAnswer);