Day Two - Received all stars | 02/12/2021

This commit is contained in:
2021-12-02 11:39:32 +01:00
parent 4c5be2279b
commit 7cf5344e77
9 changed files with 2151 additions and 0 deletions

View File

@ -0,0 +1,5 @@
final depth: 8
final horizontal: 5
horizontal * depth
5 * 8 = 40

1000
Day 2/part-1/data.txt Normal file

File diff suppressed because it is too large Load Diff

36
Day 2/part-1/nav_part1.js Normal file
View File

@ -0,0 +1,36 @@
const fs = require("fs");
const filePath = "data.txt";
fs.readFile( filePath, 'UTF-8', (err, data )=>{
let CommandsList = data.split("\n");
let horizontalPosition = 0 , depth= 0;
for( let i =0 ; i < CommandsList.length; i++){
let [Command , amount] = CommandsList[i].split(" ");
console.log(Command);
console.log(amount);
switch (Command){
case 'forward':
horizontalPosition += Number(amount);
break;
case 'down':
depth += Number(amount);
break;
case 'up':
depth -= Number(amount);
break;
}
}
console.log(`Final depth: ${depth}, Final Horizontal position: ${horizontalPosition}`);
console.log( `The answer is: ${horizontalPosition * depth}` )
});

View File

@ -0,0 +1,7 @@
down 4
down 1
forward 5
down 7
down 3
up 2
up 5