Skip to content

Commit

Permalink
day6
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnkunstman committed Dec 8, 2023
1 parent e45d7cb commit 123bb9e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
12 changes: 12 additions & 0 deletions day6/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>day6</title>
</head>
<body>
<div id="answer"></div>
<script src="script.js"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions day6/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time: 60 80 86 76
Distance: 601 1163 1559 1300
2 changes: 2 additions & 0 deletions day6/input1_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200
60 changes: 60 additions & 0 deletions day6/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
let data = [];
let timeArray;
let distanceArray;
fetch("input.txt")
//fetch("input1_test.txt")
.then((r) =>
r.text().then((d) => {
d = d.replaceAll("\r", "");
d = d.split("\n");
timeArray = d[0]
.split(":")[1]
.split(" ")
.map((x) => parseInt(x))
.filter(Number);
distanceArray = d[1]
.split(":")[1]
.split(" ")
.map((x) => parseInt(x))
.filter(Number);
console.log(timeArray);
console.log(distanceArray);
//part 1
let solutiuonsArray = []
for (let i = 0; i < timeArray.length; i++) {
let solutions = 0;
for (let j = 1; j <= timeArray[i]; j++) {
let buttonPushTime = j;
let timeleft = timeArray[i] - j;
let distance = timeleft * buttonPushTime;
if (distance > distanceArray[i]) {
solutions++;
}
}
solutiuonsArray.push(solutions);
}
//part 2
let timep2 = Number(timeArray.join(""));
let distance2 = Number(distanceArray.join(""));
console.log(timep2);
console.log(distance2);

let solutions2 = 0;
for (let j = 1; j <= timep2; j++) {
let buttonPushTime = j;
let timeleft = timep2 - j;
let distance = timeleft * buttonPushTime;
if (distance > distance2) {
solutions2++;
}
}


//
console.log(solutiuonsArray);
console.log(solutiuonsArray.reduce((a, b) => a * b, 1));

console.log(solutions2);

})
);

0 comments on commit 123bb9e

Please sign in to comment.