Skip to content

Commit

Permalink
2024 day 11
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Dec 11, 2024
1 parent a7b03ac commit c0d81d3
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 4 deletions.
29 changes: 29 additions & 0 deletions 2024/11/runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { readFile } from "fs/promises";
import { taskOne, taskTwo } from "./task";

async function main() {
let lastArgument = process.argv.pop() as string;
let taskNumber = 1;
let isTest = false;

if (lastArgument === "test") {
isTest = true;
taskNumber = parseInt(process.argv.pop() as string);
} else {
taskNumber = parseInt(lastArgument)
}

const fileToLoad = isTest ? "test.in" : "solve.in";
const fileContents = await readFile(fileToLoad, "utf-8")

const lines = fileContents.split("\n");

if (taskNumber === 1) {
await taskOne(lines);
}
if (taskNumber === 2) {
await taskTwo(lines);
}
}

void main();
50 changes: 50 additions & 0 deletions 2024/11/task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export async function taskOne(input: string[]): Promise<void> {
let stones = input[0].split(' ').map(Number)

for (let i = 0; i < 25; i++) {
const newStone: number[] = []

for (let j = 0; j < stones.length; j++) {
const s = stones[j].toString()
if (stones[j] == 0) newStone.push(1)
else if (s.length % 2 == 0) {
newStone.push(Number(s.substring(0, s.length/2)))
newStone.push(Number(s.substring(s.length/2)))
} else {
newStone.push(stones[j]*2024)
}
}
stones = newStone
}
console.log(stones.length)

}

export async function taskTwo(input: string[]): Promise<void> {
const memo: Record<number, Record<number, number>> = {}
let stones = input[0].split(' ').map(Number).map(n => get(n,0)).reduce((a,b)=>a+b,0)

console.log(stones)


function get(n: number, d: number): number {
if (d >= 75) return 1
if (memo[n] != undefined) {
if (memo[n][d] != undefined) return memo[n][d]
}

let v = -1
const s = n.toString()
if (n == 0) v = get(1, d+1)
else if (s.length % 2 == 0) {
v = get(Number(s.substring(0, s.length/2)),d+1)
v += get(Number(s.substring(s.length/2)),d+1)
} else {
v = get(n*2024,d+1)
}

if (memo[n] == undefined) memo[n] = {}
memo[n][d] = v
return v
}
}
5 changes: 3 additions & 2 deletions 2024/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 2024
![](https://img.shields.io/badge/stars%20⭐-20-yellow)
![](https://img.shields.io/badge/stars%20⭐-22-yellow)

|Day|Language|Leaderboard (Part 1 / Part 2)|
|--|--|--|
Expand All @@ -12,4 +12,5 @@
|7|TypeScript|291 / 177|
|8|TypeScript|763 / 1186|
|9|TypeScript|4996 / 4452|
|10|Typescript|673 / 442|
|10|Typescript|673 / 442|
|11|Typescript|414 / 803|
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# My Advent of Code Solutions

![](https://img.shields.io/badge/Total%20stars%20⭐-465yellow)
![](https://img.shields.io/badge/Total%20stars%20⭐-467yellow)

## What language do I use?
Whatever I feel like today. But it will most likely either be Java, Python, C++, Typescript or Haskell
Expand All @@ -9,7 +9,7 @@ Whatever I feel like today. But it will most likely either be Java, Python, C++,

<h3>2024</h3>

![](https://img.shields.io/badge/stars%20⭐-20-yellow)
![](https://img.shields.io/badge/stars%20⭐-22-yellow)

|Day|Language|
|--|--|
Expand All @@ -23,6 +23,7 @@ Whatever I feel like today. But it will most likely either be Java, Python, C++,
|8|TypeScript|
|9|TypeScript|
|10|TypeScript|
|11|TypeScript|


<h3><a href="2023/README.md">2023</a></h3>
Expand Down
41 changes: 41 additions & 0 deletions setup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {lcmArr, lcm, gcd, ComplexNumber, Stack, Queue, JsonSet, FunctionSet, MinHeap } from '../../base'

export async function taskOne(input: string[]): Promise<void> {

}

export async function taskTwo(input: string[]): Promise<void> {

}

/*
const grid = input.map(i => i.split(''))

for (let y = 0; y < grid.length; y++) {
for (let x = 0; x < grid[y].length; x++) {

}
}


const queue = new Queue<State>()
const visited = new Set<string>()
queue.push()

while(!queue.isEmpty()) {
const q = q.pop()
const k = q.x + '|' + q.y
if (visited.has(k)) continue
visited.add(k)

for () {
queue.push()
}
}

interface State {
x: number
y: number
}

*/

0 comments on commit c0d81d3

Please sign in to comment.