-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday4.html
172 lines (135 loc) · 3.89 KB
/
day4.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
164
165
166
167
168
169
170
171
172
<!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 4</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 4</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 countValidPassport(){
let count = 0
let inputs = input.split("\n\n");
for (const input1 of inputs) {
if (input1==""){
break
}
let controller = [];
let singlefields=input1.split(/\n| /);
for (const field of singlefields) {
if (!/cid:([0-9])+/.test(field)){
controller.push(true)
}
}
if (controller.length >= 7 ){
count ++
}
}
$("#Parte1").html(count)
}
function countReallyValidPassport() {
let count = 0
let inputs = input.split("\n\n");
for (const input1 of inputs) {
if (input1==""){
break
}
let controller = [];
let singlefields=input1.split(/\n| /);
for (const field of singlefields) {
if (!/cid:([0-9])+/.test(field)){
if(/byr:(19([2-8])([0-9])|199([0-9])|200([0-2]))/.test(field)){
controller.push(true)
}else if (/iyr:(201([0-9])|2020)/.test(field)){
controller.push(true)
}else if(/eyr:(202([0-9])|2030)/.test(field)){
controller.push(true)
}else if (/hgt:(1[5-8][0-9]|19[0-3])cm/.test(field)) {
controller.push(true)
}else if(/hgt:(59|6[0-9]|7[0-6])+in/.test(field)){
controller.push(true)
}else if (/hcl:#[0-9a-f]{6}/.test(field)){
controller.push(true)
}else if (/ecl:(amb|blu|brn|gry|grn|hzl|oth)/.test(field)){
controller.push(true)
} else if (/pid:([0-9]{9})/.test(field)){
controller.push(true)
}
}
}
if (controller.length == 7 ){
console.log(singlefields, controller.length, singlefields.length)
//console.log("lui lo è")
count ++
}
}
$("#Parte2").html(count-1)
}
function performAdvent(){
countValidPassport();
countReallyValidPassport();
}
$(document).ready(function () {
setUpNav($("#dropdown1"), $("#nav-mobile"))
$(".dropdown-trigger").dropdown();
setUpLights($("#lightrope"))
getInput(performAdvent);
});
</script>
</body>
</html>