Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Magiczne committed Dec 1, 2024
1 parent a0b34e6 commit 005edfb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
6 changes: 2 additions & 4 deletions 2023/11/solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { resolve } from 'node:path'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { solutionExample, solutionPart1 } from '../util/index.ts'
import { Space } from './space.ts';
import { Space } from './space.ts'

const __dirname = fileURLToPath(new URL('.', import.meta.url))



const part1 = (file: string) => {
const data = readFileSync(resolve(__dirname, file), 'utf-8').trim()
const space = Space.fromString(data, 2)
Expand All @@ -18,7 +16,7 @@ const part1 = (file: string) => {
const galaxiesAfterExpansion = galaxies.map(galaxy => {
return {
x: expandedX.get(galaxy.x),
y: expandedY.get(galaxy.y)
y: expandedY.get(galaxy.y),
}
})

Expand Down
25 changes: 10 additions & 15 deletions 2023/11/space.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const enum SpaceObject {
Nothing = '.',
Galaxy = '#'
Galaxy = '#',
}

interface Point {
Expand All @@ -11,17 +11,14 @@ interface Point {
class Space {
protected constructor(
private image: Array<Array<SpaceObject>>,
private expansionFactor: number
) {
}
private expansionFactor: number,
) {}

expand(points: Array<number>): Map<number, number> {
points = [...new Set(points)]
points.sort()

return new Map(
points.map((point, index) => [point, this.expansionFactor * (point - index) + index])
)
return new Map(points.map((point, index) => [point, this.expansionFactor * (point - index) + index]))
}

galaxies(): ReadonlyArray<Point> {
Expand All @@ -30,7 +27,7 @@ class Space {
.map((object, x) => {
return {
object,
x
x,
}
})
.filter(data => {
Expand All @@ -39,23 +36,23 @@ class Space {
.map(data => {
return {
x: data.x,
y
y,
}
})
})
}

routesBetween(galaxies: ReadonlyArray<Point>): ReadonlyArray<{ from: Point, to: Point }> {
routesBetween(galaxies: ReadonlyArray<Point>): ReadonlyArray<{ from: Point; to: Point }> {
return galaxies.reduce((routes, galaxy, index) => {
const nextGalaxies = galaxies.slice(index + 1)

return routes.concat(
nextGalaxies.map(nextGalaxy => {
return {
from: { ...galaxy },
to: { ...nextGalaxy }
to: { ...nextGalaxy },
}
})
}),
)
}, [])
}
Expand All @@ -67,9 +64,7 @@ class Space {
}

static fromString(data: string, expansionFactor: number): Space {
const image: Array<Array<SpaceObject>> = data
.split('\n')
.map(line => line.split('')) as Array<Array<SpaceObject>>
const image: Array<Array<SpaceObject>> = data.split('\n').map(line => line.split('')) as Array<Array<SpaceObject>>

return new Space(image, expansionFactor)
}
Expand Down
1 change: 0 additions & 1 deletion 2023/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"extends": "../tsconfig.json"
}

0 comments on commit 005edfb

Please sign in to comment.