repo.or.cz
/
aoc_eblake.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
day 15 part 1 optimize
[aoc_eblake.git]
/
2015
/
advent2.sh
blob
e76ff23f15c320c6d238fe701778a661558f13e1
1
wrap
=
0
# part 1
2
ribbon
=
0
# part 2
3
while
read
line
;
do
4
x
=
${line%%x*}
5
t
=
${line#*x}
6
t
=
${t%%x*}
7
if
test
$t
-gt
$x
;
then
8
y
=
$t
9
else
10
y
=
$x
11
x
=
$t
12
fi
13
t
=
${line##*x}
14
if
test
$t
-gt
$y
;
then
15
z
=
$t
16
else
17
z
=
$y
18
y
=
$t
19
fi
20
wrap
=
$
((
wrap
+
3
*
x
*
y
+
2
*
x
*
z
+
2
*
y
*
z
))
21
ribbon
=
$
((
ribbon
+
2
*(
x
+
y
) +
x
*
y
*
z
))
22
done
23
echo
$wrap $ribbon