File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 8888| Day | Solved | Part 1 time (ms) | Part 2 time (ms) |
8989| -----------------------------------------------------------------------------| :------:| -----------------:| -----------------:|
9090| [ Day 1: Not Quite Lisp] ( src/solutions/year2015/day01.rs ) | ⭐⭐ | 0.013 | 0.001 |
91- | [ Day 2: I Was Told There Would Be No Math] ( src/solutions/year2015/day02.rs ) | ⭐ | 0.074 | - |
91+ | [ Day 2: I Was Told There Would Be No Math] ( src/solutions/year2015/day02.rs ) | ⭐⭐ | 0.074 | 0.105 |
9292
9393# TODO
9494
Original file line number Diff line number Diff line change @@ -12,8 +12,22 @@ impl Solution for Day02 {
1212 . to_string ( )
1313 }
1414
15- fn part_two ( & self , _input : & str ) -> String {
16- String :: from ( "0" )
15+ fn part_two ( & self , input : & str ) -> String {
16+ self . parse ( input)
17+ . map ( |cuboid| {
18+ let around_perimeter = cuboid
19+ . perimeters ( )
20+ . iter ( )
21+ . sorted ( )
22+ . take ( 2 )
23+ . map ( |d| 2 * d)
24+ . sum :: < u64 > ( ) ;
25+ let bow = cuboid. perimeters ( ) . iter ( ) . product :: < u64 > ( ) ;
26+
27+ around_perimeter + bow
28+ } )
29+ . sum :: < u64 > ( )
30+ . to_string ( )
1731 }
1832}
1933
@@ -56,6 +70,10 @@ impl RectangularCuboid {
5670 fn area_length_height ( & self ) -> u64 {
5771 self . length * self . height
5872 }
73+
74+ fn perimeters ( & self ) -> [ u64 ; 3 ] {
75+ [ self . width , self . length , self . height ]
76+ }
5977}
6078
6179impl FromStr for RectangularCuboid {
@@ -85,4 +103,10 @@ mod tests {
85103 assert_eq ! ( "58" , Day02 . part_one( "2x3x4" ) ) ;
86104 assert_eq ! ( "43" , Day02 . part_one( "1x1x10" ) ) ;
87105 }
106+
107+ #[ test]
108+ fn part_two_example_test ( ) {
109+ assert_eq ! ( "34" , Day02 . part_two( "2x3x4" ) ) ;
110+ assert_eq ! ( "14" , Day02 . part_two( "1x1x10" ) ) ;
111+ }
88112}
You can’t perform that action at this time.
0 commit comments