initial upload
This commit is contained in:
6
2024/01/example.txt
Normal file
6
2024/01/example.txt
Normal file
@ -0,0 +1,6 @@
|
||||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
36
2024/01/index.js
Normal file
36
2024/01/index.js
Normal file
@ -0,0 +1,36 @@
|
||||
import fs from 'node:fs'
|
||||
|
||||
let all_deviation = 0
|
||||
|
||||
fs.readFile('input.txt', ({ encoding: 'utf-8' }), (err, data) => {
|
||||
let left_list = []
|
||||
let right_list = []
|
||||
for (let line of data.split('\n')) {
|
||||
//console.log(`${line}`)
|
||||
left_list.push(parseInt(line.split(' ')[0]))
|
||||
right_list.push(parseInt(line.split(' ')[1]))
|
||||
}
|
||||
left_list.sort()
|
||||
right_list.sort()
|
||||
|
||||
let difference = 0
|
||||
for (let i = 0; i < left_list.length; i++) {
|
||||
console.log(`left: ${left_list[i]} - right: ${right_list[i]}`)
|
||||
difference += Math.abs(left_list[i] - right_list[i])
|
||||
}
|
||||
let similarity = 0
|
||||
|
||||
|
||||
for (let i = 0; i < left_list.length; i++) {
|
||||
let found = right_list.filter(number => number === left_list[i])
|
||||
//console.log(found)
|
||||
if (found.length > 0) {
|
||||
|
||||
similarity += found.length * left_list[i]
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
console.log(`difference: ${difference}`)
|
||||
console.log(`similarity: ${similarity}`)
|
||||
})
|
1000
2024/01/input.txt
Normal file
1000
2024/01/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
11
2024/01/package.json
Normal file
11
2024/01/package.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "y",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": ""
|
||||
}
|
Reference in New Issue
Block a user