fix lint rules and small readme improve

This commit is contained in:
wieerwill 2023-12-06 21:05:52 +01:00
parent fa1bb19623
commit 2f35776696
12 changed files with 73 additions and 63 deletions

View File

@ -1,4 +1,8 @@
module.exports = {
env: {
node: true, // Indicates that the code runs in a Node.js environment
es2021: true
},
root: true,
parser: "@typescript-eslint/parser",
parserOptions: {

View File

@ -33,7 +33,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '16'
# Lint JavaScript files
- name: Lint JavaScript

View File

@ -1,26 +1,29 @@
# Performance Analytics
## Day01
| Language | Status | Real Time | User Time | Sys Time |
| --- | --- | --- | --- | --- |
| Python | 0 | 0m0,071s | 0m0,060s | 0m0,008s |
| Rust | 0 | 0m0,078s | 0m0,052s | 0m0,026s |
| JavaScript | 0 | 0m0,089s | 0m0,085s | 0m0,012s |
| TypeScript | 0 | 0m1,001s | 0m2,188s | 0m0,158s |
| Language | Status | Real Time | User Time | Sys Time |
| ---------- | ------- | --------- | --------- | -------- |
| Python | Success | 0m0,090s | 0m0,073s | 0m0,017s |
| Rust | Success | 0m0,057s | 0m0,049s | 0m0,008s |
| JavaScript | Success | 0m0,080s | 0m0,068s | 0m0,020s |
| TypeScript | Failed | - | - | - |
## Day02
| Language | Status | Real Time | User Time | Sys Time |
| --- | --- | --- | --- | --- |
| Python | 0 | 0m0,032s | 0m0,016s | 0m0,016s |
| Rust | 0 | 0m0,063s | 0m0,044s | 0m0,020s |
| JavaScript | 0 | 0m0,044s | 0m0,032s | 0m0,012s |
| TypeScript | 0 | 0m1,013s | 0m2,059s | 0m0,160s |
| Language | Status | Real Time | User Time | Sys Time |
| ---------- | ------- | --------- | --------- | -------- |
| Python | Success | 0m0,047s | 0m0,039s | 0m0,008s |
| Rust | Success | 0m0,059s | 0m0,032s | 0m0,028s |
| JavaScript | Success | 0m0,046s | 0m0,031s | 0m0,015s |
| TypeScript | Failed | - | - | - |
## Day03
| Language | Status | Real Time | User Time | Sys Time |
| --- | --- | --- | --- | --- |
| Python | 0 | 0m0,054s | 0m0,043s | 0m0,011s |
| Rust | 0 | 0m0,059s | 0m0,032s | 0m0,024s |
| JavaScript | 0 | 0m0,067s | 0m0,036s | 0m0,032s |
| TypeScript | 0 | 0m1,014s | 0m2,128s | 0m0,155s |
| Language | Status | Real Time | User Time | Sys Time |
| ---------- | ------- | --------- | --------- | -------- |
| Python | Success | 0m0,042s | 0m0,033s | 0m0,008s |
| Rust | Success | 0m0,066s | 0m0,054s | 0m0,012s |
| JavaScript | Success | 0m0,076s | 0m0,061s | 0m0,016s |
| TypeScript | Failed | - | - | - |
## Day04
| Language | Status | Real Time | User Time | Sys Time |
| --- | --- | --- | --- | --- |
| Python | 0 | 0m16,137s | 0m16,020s | 0m0,117s |
| -------- | ------ | --------- | --------- | -------- |

View File

@ -15,12 +15,10 @@ function extractDigits(line) {
let digitsFound = [];
let i = 0;
while (i < line.length) {
let matched = false;
for (const [word, digit] of Object.entries(digitMap)) {
if (line.startsWith(word, i)) {
digitsFound.push(digit);
i += word.length - 1; // Advance the index
matched = true;
i += word.length - 1;
break;
}
}

View File

@ -14,12 +14,10 @@ function extractDigits(line: string): number[] {
const digitsFound: number[] = [];
let i = 0;
while (i < line.length) {
let matched = false;
for (const [word, digit] of Object.entries(digitMap)) {
if (line.startsWith(word, i)) {
digitsFound.push(digit);
i += word.length - 1;
matched = true;
break;
}
}

View File

@ -47,9 +47,13 @@ function processFile(filePath: string): number | null {
const lines = data.trim().split('\n');
const cards = lines.map(parseCardData);
return processCards(cards);
} catch (error: any) {
console.error(`Error processing file ${filePath}: ${error.message}`);
return null;
} catch (error) {
if (error instanceof Error) {
console.error(`Error processing file ${filePath}: ${error.message}`);
return null;
} else {
console.error(`An unknown error occurred`);
}
}
}
@ -67,8 +71,12 @@ function main() {
test();
const totalCards = processFile('../input.txt');
console.log(`Total cards from input.txt: ${totalCards}`);
} catch (error: any) {
console.error(`An error occurred: ${error.message}`);
} catch (error) {
if (error instanceof Error) {
console.error(`An error occurred: ${error.message}`);
} else {
console.error(`An unknown error occurred`);
}
}
}

View File

@ -29,7 +29,7 @@ function processCategories(seedsNumbers: number[][], categories: number[][][]):
console.log('Processing categories');
categories.forEach((category, index) => {
console.log(`Processing category ${index + 1}`);
let sources: number[][] = [];
const sources: number[][] = [];
while (seedsNumbers.length) {
const seedPair = seedsNumbers.pop();
if (!seedPair) {

View File

@ -1,5 +1,10 @@
# 🎄 Advent of Code 2023 🎄
![Build Status](https://github.com/wieerwill/advent_of_code_2023/actions/workflows/lint.yml/badge.svg)
![Coverage](https://codecov.io/gh/wieerwill/advent_of_code_2023/branch/main/graph/badge.svg)
![Dependencies Status](https://david-dm.org/wieerwill/advent_of_code_2023.svg)
![License](https://img.shields.io/github/license/wieerwill/advent_of_code_2023.svg)
Welcome to my repository where I share my solutions for the [Advent of Code 2023](https://adventofcode.com/2023). Advent of Code is an annual online event where participants solve a series of programming puzzles released daily from December 1st until December 25th. Each puzzle is a fun and unique challenge designed to test problem-solving skills.
## Structure

View File

@ -17,44 +17,26 @@ measure_execution_time() {
echo "Running $language script for $day: $runner $script_dir$script_name"
local real_time=""
local user_time=""
local sys_time=""
local EXEC_STATUS=""
cd "$script_dir"
if [ "$language" == "Rust" ]; then
if [ -d "$script_dir" ]; then
exec 3>&1 4>&2
TIME_RESULT=$( { time $runner 1>&3 2>&4; } 2>&1 )
EXEC_STATUS=$?
exec 3>&- 4>&-
if [ -f "$script_name" ] || [ "$language" == "Rust" ]; then
exec 3>&1 4>&2
TIME_RESULT=$( { time $runner $script_name 1>&3 2>&4; } 2>&1 )
EXEC_STATUS=$?
exec 3>&- 4>&-
if [ $EXEC_STATUS -eq 0 ]; then
real_time=$(echo "$TIME_RESULT" | grep real | awk '{print $2}')
user_time=$(echo "$TIME_RESULT" | grep user | awk '{print $2}')
sys_time=$(echo "$TIME_RESULT" | grep sys | awk '{print $2}')
echo "| $language | $EXEC_STATUS | $real_time | $user_time | $sys_time |" >> "$ROOT_DIR/$ANALYTICS_FILE"
echo "| $language | Success | $real_time | $user_time | $sys_time |" >> "$ROOT_DIR/$ANALYTICS_FILE"
else
echo "| $language | rust not executable | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE"
echo "Warning: $language script for $day not found or not executable"
echo "| $language | Failed | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE"
echo "Warning: $language script for $day failed with status $EXEC_STATUS"
fi
else
if [ -f "$script_name" ]; then
exec 3>&1 4>&2
TIME_RESULT=$( { time $runner $script_name 1>&3 2>&4; } 2>&1 )
EXEC_STATUS=$?
exec 3>&- 4>&-
real_time=$(echo "$TIME_RESULT" | grep real | awk '{print $2}')
user_time=$(echo "$TIME_RESULT" | grep user | awk '{print $2}')
sys_time=$(echo "$TIME_RESULT" | grep sys | awk '{print $2}')
echo "| $language | $EXEC_STATUS | $real_time | $user_time | $sys_time |" >> "$ROOT_DIR/$ANALYTICS_FILE"
else
echo "| $language | Not Found or Not Executable | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE"
echo "Warning: $language script for $day not found or not executable"
fi
echo "| $language | Not Found or Not Executable | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE"
echo "Warning: $language script for $day not found or not executable"
fi
cd "$ROOT_DIR"
}
@ -62,7 +44,8 @@ measure_execution_time() {
# Loop through each DayXX folder
for day_folder in $ROOT_DIR/Day*/; do
day=$(basename "$day_folder")
echo "\n## $day" >> $ANALYTICS_FILE
echo "" >> $ANALYTICS_FILE
echo "## $day" >> $ANALYTICS_FILE
echo "| Language | Status | Real Time | User Time | Sys Time |" >> $ANALYTICS_FILE
echo "| --- | --- | --- | --- | --- |" >> $ANALYTICS_FILE

8
package-lock.json generated
View File

@ -8,6 +8,9 @@
"name": "adventofcode2023",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"fs": "^0.0.1-security"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
@ -837,6 +840,11 @@
"integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==",
"dev": true
},
"node_modules/fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
},
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",

View File

@ -15,5 +15,8 @@
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"eslint": "^8.55.0"
},
"dependencies": {
"fs": "^0.0.1-security"
}
}

View File

@ -6,6 +6,6 @@
"esModuleInterop": true
},
"include": [
"Day**/{js,ts}/*.ts"
"Day**/ts/*.ts"
]
}