-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6.html
126 lines (101 loc) · 3.12 KB
/
day6.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
<!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 6</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 6</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
let groups
function countNumberOfYes() {
let allSizes = groups.map(v => new Set(v.replace(/[\r\n\x0B\x0C\u0085\u2028\u2029]+/g, "").split("")).size)
let count = allSizes.reduce((tot, v) => v + tot)
$("#Parte1").html(count)
}
function howManyAllYes(answers, n) {
let count = 0
for (let key in answers) {
if (answers[key] == n) {
count++
}
}
return count
}
function countNumberOfYesEqualsOnAGroup() {
let allYesAnswers = 0;
for (const group of groups) {
let answers = {}
let people = group.split(/[\r\n\x0B\x0C\u0085\u2028\u2029]+/g);
people.forEach(v => new Set(v.split("")).forEach(w => answers[w] = (answers[w] || 0) + 1) )
allYesAnswers += howManyAllYes(answers, people.length)
}
$("#Parte2").html(allYesAnswers)
}
function performAdvent() {
input += "\n\n"
groups = input.split("\n\n");
countNumberOfYes()
countNumberOfYesEqualsOnAGroup()
}
$(document).ready(function () {
$(".dropdown-trigger").dropdown();
setUpLights($("#lightrope"))
setUpNav($("#dropdown1"), $("#nav-mobile"))
getInput(performAdvent);
});
</script>
</body>
</html>