Skip to content

Commit

Permalink
🎉 Set up new project
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbrennanfr committed Dec 2, 2024
0 parents commit 398f831
Show file tree
Hide file tree
Showing 14 changed files with 265 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
example.ts
input.ts
!src/00/example.ts
!src/00/input.ts
node_modules/
private/
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bun lint
bun format
bun check
bun test
git add --all
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 🎄 Advent of Code 2024 🎄

Welcome to my **Advent of Code 2024** repository! Built with **TypeScript** and grounded in **functional programming** and **immutability**.

---

## ⚡ Why Bun?

This project uses **Bun**, a fast JavaScript runtime ideal for Advent of Code:

- **Tail Call Optimization (TCO)**: Enables deep recursion without stack overflow.
- **High Performance**: Optimized JIT for complex Advent of Code computations.
- **Built-In Test Runner**: Allows easy test setup and validation of solutions.
- **Native TypeScript Support**: Type-safe coding without extra compilation.

For more, visit [Bun's website](https://bun.sh/).

## 📦 Getting Started

1. **Clone the Repository:**

```sh
git clone https://github.com/andrewbrennanfr/advent-of-code-2024.git
cd advent-of-code-2024
```

2. **Install Dependencies:**

```sh
bun install
```

3. **Set Up Git Hooks (using Husky):**
```sh
bun husky
```

## 🚀 Key Scripts

- **`bun check`** – TypeScript type-checking.
- **`bun format`** – Code formatting with Prettier.
- **`bun lint`** – Linting with ESLint.
- **`bun new NN`** – Creates a new puzzle directory and starts tests.
- **`bun start`** – Runs all tests in watch mode.
- **`bun start NN`** – Runs tests in directory `NN` in watch mode.
- **`bun test`** – Runs all tests once.
- **`bun test NN`** – Runs tests in directory `NN` once.

---

## 📁 Puzzle Inputs

Puzzle input files are excluded from version control per [Advent of Code's guidelines](https://adventofcode.com/2024/about).
---
## 📜 License
Licensed under the MIT License.
---
**🎅 Happy solving!**
Binary file added bun.lockb
Binary file not shown.
71 changes: 71 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import eslint from "@eslint/js"
import functional from "eslint-plugin-functional"
import perfectionist from "eslint-plugin-perfectionist"
import eslintPluginUnicorn from "eslint-plugin-unicorn"
import tseslint from "typescript-eslint"

export default [
eslint.configs.all,
...tseslint.configs.all,
eslintPluginUnicorn.configs["flat/all"],
perfectionist.configs["recommended-natural"],
functional.configs.all,
{ languageOptions: { parserOptions: { projectService: true } } },
{
rules: {
"@typescript-eslint/no-magic-numbers": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"functional/prefer-immutable-types": "off",
"functional/type-declaration-immutability": "off",
"max-lines": "off",
"no-ternary": "off",
"sort-imports": "off",
"unicorn/no-array-callback-reference": "off",
"unicorn/no-array-reduce": "off",
"unicorn/no-nested-ternary": "off",
"unicorn/no-unreadable-array-destructuring": "off",
},
},
{
rules: {
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
curly: ["error", "multi"],
"functional/functional-parameters": [
"error",
{ allowRestParameter: true },
],
"functional/no-conditional-statements": [
"error",
{ allowReturningBranches: true },
],
"functional/prefer-tacit": "error",
"id-length": ["error", { exceptions: ["$", "_", "U"] }],
"no-restricted-syntax": [
"error",
{
message: "Modifying a Set or Map is not allowed.",
selector: `CallExpression[callee.property.name=/^(${[
"add",
"clear",
"delete",
"set",
].join("|")})$/][callee.object.type='Identifier']`,
},
],
"one-var": ["error", "never"],
},
},
{
files: ["eslint.config.js"],
rules: { "@typescript-eslint/naming-convention": "off" },
},
{
files: ["**/*.spec.ts"],
rules: {
"functional/functional-parameters": "off",
"functional/no-expression-statements": "off",
"functional/no-return-void": "off",
},
},
]
10 changes: 10 additions & 0 deletions new.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ -z "$1" ] || [ -e "./src/$1" ] || ! [[ "$1" =~ ^0[1-9]$|^1[0-9]$|^2[0-5]$ ]] && exit 1

cp -r "./src/00" "./src/$1"

sed -i "" "s/00/$1/g" ./src/$1/*

open -a "Google Chrome" https://adventofcode.com/2024/day/$((10#$1))
open -a "Google Chrome" https://adventofcode.com/2024/day/$((10#$1))/input

bun start $1
36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "advent-of-code-2024",
"version": "1.0.0",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/andrewbrennanfr/advent-of-code-2024.git"
},
"author": {
"name": "Andrew Brennan",
"url": "https://github.com/andrewbrennanfr"
},
"license": "MIT",
"scripts": {
"check": "tsc -p ./tsconfig.json",
"format": "prettier --write ./",
"husky": "husky",
"lint": "eslint ./ --fix",
"new": "bash ./new.sh",
"start": "bun test --watch"
},
"devDependencies": {
"@eslint/js": "^9.16.0",
"@tsconfig/strictest": "^2.0.5",
"@types/bun": "^1.1.14",
"@types/eslint__js": "^8.42.3",
"eslint": "^9.16.0",
"eslint-plugin-functional": "^7.1.0",
"eslint-plugin-perfectionist": "^4.1.2",
"eslint-plugin-unicorn": "^56.0.1",
"husky": "^9.1.7",
"prettier": "^3.4.1",
"typescript": "^5.7.2",
"typescript-eslint": "^8.17.0"
}
}
1 change: 1 addition & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { experimentalTernaries: true, semi: false, tabWidth: 4 }
3 changes: 3 additions & 0 deletions src/00/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const EXAMPLE_01 = `
`
26 changes: 26 additions & 0 deletions src/00/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { part01, part02 } from "@/00"
import { EXAMPLE_01 } from "@/00/example"
import { INPUT_01 } from "@/00/input"
import { describe, expect, test } from "bun:test"

describe("00", () => {
describe("part01", () => {
test("EXAMPLE_01", () => {
expect(part01(EXAMPLE_01)).toBe(1)
})

test.todo("INPUT_01", () => {
expect(part01(INPUT_01)).toBe(1)
})
})

describe.todo("part02", () => {
test("EXAMPLE_01", () => {
expect(part02(EXAMPLE_01)).toBe(1)
})

test.todo("INPUT_01", () => {
expect(part02(INPUT_01)).toBe(1)
})
})
})
19 changes: 19 additions & 0 deletions src/00/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as U from "@/utils"

const parse = (input: string): string[] => U.lines(input)

/* --------------------------------- part01 --------------------------------- */

export const part01 = (input: string): number => {
const data = parse(input)

return data.length
}

/* --------------------------------- part02 --------------------------------- */

export const part02 = (input: string): number => {
const data = parse(input)

return data.length
}
3 changes: 3 additions & 0 deletions src/00/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const INPUT_01 = `
`
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** Memoizes a function by caching results based on a hash of its arguments. */
export const $ =
<T extends unknown[], U>(
function_: (...arguments_: T) => U,
hash: (arguments_: T) => string = JSON.stringify,
cache: Record<string, U> = {},
): typeof function_ =>
(...arguments_) =>
(cache[hash(arguments_)] ??= function_(...arguments_)) // eslint-disable-line functional/immutable-data

/** Splits a string into an array of lines. */
export const lines = (string: string): string[] => string.trim().split("\n")
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@tsconfig/strictest/tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
"noEmit": true,
"paths": { "@/*": ["./src/*"] },
"target": "ESNext"
}
}

0 comments on commit 398f831

Please sign in to comment.