Skip to content

Commit

Permalink
chore(fmt): code formating
Browse files Browse the repository at this point in the history
  • Loading branch information
BRAVO68WEB committed Dec 22, 2023
1 parent a0ba38f commit 6045ba4
Show file tree
Hide file tree
Showing 81 changed files with 2,290 additions and 2,425 deletions.
12 changes: 6 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// This configuration only applies to the package manager root.
/** @type {import("eslint").Linter.Config} */
module.exports = {
ignorePatterns: ["apps/**", "packages/**"],
extends: ["@repo/eslint-config/library.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
ignorePatterns: ["apps/**", "packages/**"],
extends: ["@repo/eslint-config/library.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
};
40 changes: 20 additions & 20 deletions .github/workflows/runner-rs.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
name: AoC Test Runner (Rust)
on:
push:
branches: [main]
pull_request:
branches: [main]
push:
branches: [main]
pull_request:
branches: [main]
jobs:
rust:
name: Test Rust Solutions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v1
- run: bun i -g turbo@latest
- name: Installing Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Building with Cargo
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Testing with Cargo
run: bun rs
rust:
name: Test Rust Solutions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v1
- run: bun i -g turbo@latest
- name: Installing Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Building with Cargo
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Testing with Cargo
run: bun rs
26 changes: 13 additions & 13 deletions .github/workflows/runner-ts.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: AoC Test Runner (Typescript)
on:
push:
branches: [main]
pull_request:
branches: [main]
push:
branches: [main]
pull_request:
branches: [main]
jobs:
typescript:
name: Test Typescript Solutions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v1
- run: bun i
- run: bun i -g turbo@latest
- run: bun ts
typescript:
name: Test Typescript Solutions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v1
- run: bun i
- run: bun i -g turbo@latest
- run: bun ts
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This is my repository for the [Advent of Code 2023](https://adventofcode.com/202

Languages used:

- [TypeScript + Bun](https://bun.sh/)
- [Rust](https://www.rust-lang.org/)
- [TypeScript + Bun](https://bun.sh/)
- [Rust](https://www.rust-lang.org/)

## Usage

Expand All @@ -25,28 +25,28 @@ Check [README.md](code/rs/README.md) in the `rs` directory.

## Checklists

- [x] Day 1
- [x] Day 2
- [x] Day 3
- [x] Day 4
- [x] Day 5
- [x] Day 6
- [x] Day 7
- [x] Day 8
- [x] Day 9
- [x] Day 10
- [x] Day 11
- [x] Day 12
- [x] Day 13
- [x] Day 14
- [x] Day 15
- [x] Day 16
- [x] Day 17
- [x] Day 18
- [x] Day 19
- [x] Day 20
- [x] Day 21
- [x] Day 22
- [ ] Day 23
- [ ] Day 24
- [ ] Day 25
- [x] Day 1
- [x] Day 2
- [x] Day 3
- [x] Day 4
- [x] Day 5
- [x] Day 6
- [x] Day 7
- [x] Day 8
- [x] Day 9
- [x] Day 10
- [x] Day 11
- [x] Day 12
- [x] Day 13
- [x] Day 14
- [x] Day 15
- [x] Day 16
- [x] Day 17
- [x] Day 18
- [x] Day 19
- [x] Day 20
- [x] Day 21
- [x] Day 22
- [ ] Day 23
- [ ] Day 24
- [ ] Day 25
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion code/rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This is my repository for the [Advent of Code 2023](https://adventofcode.com/202

### Prerequisites

- [Rustup](https://rustup.rs/)
- [Rustup](https://rustup.rs/)

### Run

Expand Down
20 changes: 10 additions & 10 deletions code/rs/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "rs",
"version": "1.0.0",
"description": "Rust Cargo Runner",
"scripts": {
"rust": "cargo run"
},
"keywords": [],
"author": "BRAVO68WEB",
"license": "ISC"
}
"name": "rs",
"version": "1.0.0",
"description": "Rust Cargo Runner",
"license": "ISC",
"author": "BRAVO68WEB",
"scripts": {
"rust": "cargo run"
},
"keywords": []
}
117 changes: 56 additions & 61 deletions code/ts/01/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,80 @@ const input = await Bun.file(`${import.meta.dir}/../../../input/1.txt`).text();

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

const sp1 = lines.map((line) => {
let firstDigit: string | undefined;
let lastDigit: string | undefined;
for (let i = 0; i < line.length; i++) {
const maybeFirstDigit = line[i]!;
const maybeLastDigit = line[line.length - i - 1]!;
const sp1 = lines.map(line => {
let firstDigit: string | undefined;
let lastDigit: string | undefined;
for (let i = 0; i < line.length; i++) {
const maybeFirstDigit = line[i]!;
const maybeLastDigit = line[line.length - i - 1]!;

if (firstDigit === undefined && /\d/.test(maybeFirstDigit)) {
firstDigit = maybeFirstDigit;
}
if (firstDigit === undefined && /\d/.test(maybeFirstDigit)) {
firstDigit = maybeFirstDigit;
}

if (lastDigit === undefined && /\d/.test(maybeLastDigit)) {
lastDigit = maybeLastDigit;
}
if (lastDigit === undefined && /\d/.test(maybeLastDigit)) {
lastDigit = maybeLastDigit;
}

if (firstDigit !== undefined && lastDigit !== undefined) {
break;
if (firstDigit !== undefined && lastDigit !== undefined) {
break;
}
}
}

return (firstDigit ?? "") + (lastDigit ?? "");
return (firstDigit ?? "") + (lastDigit ?? "");
});

export const partone = sp1.reduce((acc, curr) => acc + parseInt(curr, 10), 0);

const numbers = {
one: "1",
"1": "1",
two: "2",
"2": "2",
three: "3",
"3": "3",
four: "4",
"4": "4",
five: "5",
"5": "5",
six: "6",
"6": "6",
seven: "7",
"7": "7",
eight: "8",
"8": "8",
nine: "9",
"9": "9",
one: "1",
"1": "1",
two: "2",
"2": "2",
three: "3",
"3": "3",
four: "4",
"4": "4",
five: "5",
"5": "5",
six: "6",
"6": "6",
seven: "7",
"7": "7",
eight: "8",
"8": "8",
nine: "9",
"9": "9",
} as const;

const numbersAsKeys = Object.keys(numbers) as (keyof typeof numbers)[];

const sp2 = lines.map((line) => {
let firstDigit: string | undefined;
let lastDigit: string | undefined;
for (let i = 0; i < line.length; i++) {
if (firstDigit === undefined) {
const maybeFirstDigit = line.slice(i, i + 5);
const firstTextNumber = numbersAsKeys.find((key) =>
maybeFirstDigit.startsWith(key),
);
if (firstTextNumber) {
firstDigit = numbers[firstTextNumber];
}
}
const sp2 = lines.map(line => {
let firstDigit: string | undefined;
let lastDigit: string | undefined;
for (let i = 0; i < line.length; i++) {
if (firstDigit === undefined) {
const maybeFirstDigit = line.slice(i, i + 5);
const firstTextNumber = numbersAsKeys.find(key => maybeFirstDigit.startsWith(key));
if (firstTextNumber) {
firstDigit = numbers[firstTextNumber];
}
}

if (lastDigit === undefined) {
const maybeDigit = line.slice(
Math.max(line.length - i - 5, 0),
line.length - i,
);
if (lastDigit === undefined) {
const maybeDigit = line.slice(Math.max(line.length - i - 5, 0), line.length - i);

const textNumber = numbersAsKeys.find((key) => maybeDigit.endsWith(key));
if (textNumber) {
lastDigit = numbers[textNumber];
}
}
const textNumber = numbersAsKeys.find(key => maybeDigit.endsWith(key));
if (textNumber) {
lastDigit = numbers[textNumber];
}
}

if (firstDigit !== undefined && lastDigit !== undefined) {
break;
if (firstDigit !== undefined && lastDigit !== undefined) {
break;
}
}
}
return (firstDigit ?? "") + (lastDigit ?? "");
return (firstDigit ?? "") + (lastDigit ?? "");
});

export const parttwo = sp2.reduce((acc, curr) => acc + parseInt(curr, 10), 0);
28 changes: 14 additions & 14 deletions code/ts/01/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "01",
"module": "code.ts",
"type": "module",
"devDependencies": {
"bun-types": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"scripts": {
"build": "tsc",
"dev": "bun run code.ts"
}
}
"name": "01",
"type": "module",
"module": "code.ts",
"scripts": {
"build": "tsc",
"dev": "bun run code.ts"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"devDependencies": {
"bun-types": "latest"
}
}
Loading

0 comments on commit 6045ba4

Please sign in to comment.