-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday5.html
121 lines (99 loc) · 2.92 KB
/
day5.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<meta content="width=device-width, initial-scale=1, maximum-scale=1.0" name="viewport"/>
<title>Advent Of Code 2020 - Day 5</title>
<!-- CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="css/materialize.css" media="screen,projection" rel="stylesheet" type="text/css"/>
<link href="css/style.css" media="screen,projection" rel="stylesheet" type="text/css"/>
<link href="img/favicon.ico" rel="icon" sizes="96x96" type="image/png">
</head>
<body>
<ul class="dropdown-content" id="dropdown1">
</ul>
<nav class="green darken-4" role="navigation">
<div class="nav-wrapper">
<a class="brand-logo center" href="#">Day 5</a>
<ul class="right hide-on-med-and-down">
<!-- Dropdown Trigger -->
<a class="dropdown-trigger" data-target="dropdown1" href="#!">Altri giorni<i class="material-icons right">arrow_drop_down</i></a>
</ul>
<ul class="sidenav" id="nav-mobile">
</ul>
<a class="sidenav-trigger" data-target="nav-mobile" href="#"><i class="material-icons">menu</i></a>
</div>
</nav>
<ul class="lightrope" id="lightrope">
</ul>
<div class="container">
<br> <br> <br> <br>
<div class="section">
<div class="row center">
<div class="col input-field file-field s12">
<div class="btn light-green darken-3">
<span>Inserire l'input</span> <input id="inputfile" name="inputfile" type="file">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
</div>
<div class="row center">
<div class="col s6">
<h5>Parte 1: </h5>
<h6 id="Parte1"></h6>
</div>
<div class="col s6">
<h5>Parte 2: </h5>
<h6 id="Parte2"></h6>
</div>
</div>
</div>
</div>
<!-- Scripts-->
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="js/materialize.js"></script>
<script src="js/init.js"></script>
<script src="js/custom.js"></script>
<script>
let input
function getBinary(v) {
if (v==""){
return
}
let binaryString;
binaryString = v.replace(/F|L/g, 0)
binaryString = binaryString.replace(/B|R/g, 1)
console.log(binaryString)
return binaryString;
}
function findMySeat(seatIds) {
for (var x = 0; x < Math.max(...seatIds); x++) {
if ( seatIds.includes(x - 1) && !seatIds.includes(x) && seatIds.includes(x + 1)) {
$("#Parte2").html(x);
}
}
}
function highestSeat(){
let inputs = input.split("\n");
inputs=inputs.map( v => getBinary(v))
inputs = inputs.map(v => parseInt(v,2))
console.log(inputs)
inputs.pop()
$("#Parte1").html(Math.max(...inputs))
findMySeat(inputs)
}
function performAdvent() {
highestSeat()
}
$(document).ready(function () {
setUpNav($("#dropdown1"), $("#nav-mobile"))
$(".dropdown-trigger").dropdown();
setUpLights($("#lightrope"))
getInput(performAdvent);
});
</script>
</body>
</html>