@@ -9,12 +9,12 @@ fn main() {
99}
1010
1111/// Do part 1 of the puzzle
12- fn part1 ( data : & str ) -> usize {
13- data. split ( '\n' ) . fold ( 0 , |acc, line| acc + expand_v1 ( line) . len ( ) )
12+ fn part1 ( data : & str ) -> u64 {
13+ data. split ( '\n' ) . fold ( 0 , |acc, line| acc + expand_v1 ( line) . len ( ) as u64 )
1414}
1515
1616/// Do part 2 of the puzzle
17- fn part2 ( data : & str ) -> usize {
17+ fn part2 ( data : & str ) -> u64 {
1818 data. split ( '\n' ) . fold ( 0 , |acc, line| acc + expand_v2 ( line) )
1919}
2020
@@ -53,12 +53,12 @@ fn expand_v1(s: &str) -> String {
5353}
5454
5555/// ``expand_v2`` returns the length of expanded string according to the format v2.
56- fn expand_v2 ( s : & str ) -> usize {
56+ fn expand_v2 ( s : & str ) -> u64 {
5757 expand ( s, 2 )
5858}
5959
6060/// ``expand`` returns the length of the expanded string (v1 or v2).
61- fn expand ( s : & str , version : u8 ) -> usize {
61+ fn expand ( s : & str , version : u8 ) -> u64 {
6262 let mut new_len = 0 ;
6363 let mut chars = s. chars ( ) ;
6464
@@ -76,13 +76,13 @@ fn expand(s: &str, version: u8) -> usize {
7676 . by_ref ( )
7777 . take_while ( |c| * c != ')' )
7878 . collect :: < String > ( )
79- . parse :: < usize > ( )
79+ . parse :: < u64 > ( )
8080 . unwrap ( ) ;
8181
8282 let taken = chars. by_ref ( ) . take ( take) ;
8383
8484 let count = if version == 1 {
85- taken. count ( )
85+ taken. count ( ) as u64
8686 } else {
8787 expand ( taken. collect :: < String > ( ) . as_str ( ) , version)
8888 } ;
@@ -101,7 +101,7 @@ fn expand(s: &str, version: u8) -> usize {
101101fn test_expand_v1 ( ) {
102102 fn test_v1 ( s : & str , expected : & str ) {
103103 assert_eq ! ( expand_v1( s) , expected) ;
104- assert_eq ! ( expand( s, 1 ) , expected. len( ) ) ;
104+ assert_eq ! ( expand( s, 1 ) , expected. len( ) as u64 ) ;
105105 }
106106 test_v1 ( "ADVENT" , "ADVENT" ) ;
107107 test_v1 ( "A(1x5)BC" , "ABBBBBC" ) ;
0 commit comments