-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2.php
More file actions
executable file
·42 lines (31 loc) · 1015 Bytes
/
day2.php
File metadata and controls
executable file
·42 lines (31 loc) · 1015 Bytes
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
<?php
$inputFile = fopen("input2.txt",'r');
$celkovyRibbon = $celkovaSuma = 0;
while ($row = fgets($inputFile)) {
// var_dump(trim($row));
$dimenzions = explode('x', trim($row));
if (sort($dimenzions) === false) {
throw new \RuntimeException("unable sort");
};
$ribbonWrap = $dimenzions[0] * 2 + $dimenzions[1] * 2;
$ribbonBow = $dimenzions[0] * $dimenzions[1] * $dimenzions[2];
$celkovyRibbon = $celkovyRibbon + $ribbonWrap + $ribbonBow;
$sides = array(
$dimenzions[0] * $dimenzions[1],
$dimenzions[1] * $dimenzions[2],
$dimenzions[2] * $dimenzions[0],
);
if (sort($sides) === false) {
throw new \RuntimeException("unable sort");
};
$smallestSide = $sides[0];
$suma = 0;
foreach ($sides as $obsahStrany) {
$suma = $suma + (2 * $obsahStrany);
}
$suma = $suma + $smallestSide;
$celkovaSuma = $celkovaSuma + $suma;
}
var_dump($celkovaSuma);
var_dump($celkovyRibbon);
fclose($inputFile);