-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.html
163 lines (133 loc) · 3.8 KB
/
day2.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!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 2</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 rel="icon" type="image/png" sizes="96x96" href="img/favicon.ico">
</head>
<body>
<ul class="dropdown-content" id="dropdown1">
</ul>
<nav class="green darken-4" role="navigation">
<div class="nav-wrapper">
<a href="#" class="brand-logo center">Day 2</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 checkValidPassword(min, max, letterToSearch, password) {
let count=0;
for (const s of password) {
if (s==letterToSearch){
count++
}
}
return (count >= min && count <= max)
}
function findPassword() {
let count = 0
let inputs = input.split("\n");
for (const input1 of inputs) {
console.log(input1)
if (input1==""){
break
}
let regexedInput = input1.match(/([0-9]+)-([0-9]+) ([a-z]{1}): ([a-z]+)/);
let min = regexedInput[1];
let max = regexedInput[2];
let letterToSearch = regexedInput[3];
let password = regexedInput[4];
if (checkValidPassword(min,max, letterToSearch, password)){
count ++
}
}
console.log(count, inputs.length)
$("#Parte1").html(count)
}
function checkValidPasswordAgain(x, y, letterToSearch, password) {
if (password[x] == letterToSearch && password [y] == letterToSearch)
return false
if (password[x]!=letterToSearch && password [y] != letterToSearch)
return false
return true;
}
function findPasswordAgain(){
let count = 0
let inputs = input.split("\n");
for (const input1 of inputs) {
console.log(input1)
if (input1==""){
break
}
let regexedInput = input1.match(/([0-9]+)-([0-9]+) ([a-z]{1}): ([a-z]+)/);
let x = regexedInput[1];
let y = regexedInput[2];
let letterToSearch = regexedInput[3];
let password = regexedInput[4];
if (checkValidPasswordAgain(x-1,y-1, letterToSearch, password)){
count ++
}
}
console.log(count, inputs.length)
$("#Parte2").html( count)
}
function performAdvent(){
findPassword()
findPasswordAgain()
}
$(document).ready(function () {
setUpNav($("#dropdown1"), $("#nav-mobile"))
$(".dropdown-trigger").dropdown();
setUpLights($("#lightrope"))
getInput(performAdvent);
});
</script>
</body>
</html>