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,4 @@
aim:
horizontal:
depth:

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

File diff suppressed because it is too large Load Diff

38
Day 2/part-2/nav_part2.js Normal file
View File

@ -0,0 +1,38 @@
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, aim = 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);
depth += aim * Number(amount) ;
break;
case 'down':
aim += Number(amount);
break;
case 'up':
aim -= Number(amount);
break;
}
console.log(`Final Horizontal position: ${horizontalPosition}, Final depth: ${depth}, aim; ${aim}`);
}
console.log(`Final Horizontal position: ${horizontalPosition}, Final depth: ${depth}`);
console.log( `The answer is: ${horizontalPosition * depth}` )
});

View File

@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2