File tree Expand file tree Collapse file tree 9 files changed +19
-15
lines changed Expand file tree Collapse file tree 9 files changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ pub fn solve(data: &str) -> (u32, u32) {
4343 let from = permutated[ i] ;
4444 let to = permutated[ i + 1 ] ;
4545
46- distance += distances. get ( & ( from. to_string ( ) , to. to_string ( ) ) ) . unwrap ( ) ;
46+ distance += distances. get ( & ( from. clone ( ) , to. clone ( ) ) ) . unwrap ( ) ;
4747 }
4848
4949 if distance < min_distance {
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ impl Puzzle {
4848 fn part2 ( & self ) -> i32 {
4949 let mut boot_code = self . boot_code . clone ( ) ;
5050 for ip in 0 ..boot_code. len ( ) {
51- let instr = & boot_code[ ip] . to_string ( ) ;
51+ let instr = & boot_code[ ip] . clone ( ) ;
5252
5353 let ( op, imm) = instr. split_once ( ' ' ) . unwrap ( ) ;
5454
@@ -67,7 +67,7 @@ impl Puzzle {
6767 return acc;
6868 }
6969
70- boot_code[ ip] = instr . to_string ( ) ;
70+ boot_code[ ip] . clone_from ( instr ) ;
7171 }
7272 0
7373 }
Original file line number Diff line number Diff line change @@ -80,8 +80,7 @@ pub fn solve(data: &str) -> (usize, i32) {
8080 g_scan. push ( point) ;
8181 }
8282
83- for rotation in 0 ..24 {
84- let b_scan = scanner_rotated_list[ * scanner_id] [ rotation] . clone ( ) ;
83+ for b_scan in scanner_rotated_list[ * scanner_id] . iter ( ) . take ( 24 ) {
8584
8685 let mut match_points: FxHashMap < Point , i32 > = FxHashMap :: default ( ) ;
8786
@@ -106,7 +105,7 @@ pub fn solve(data: &str) -> (usize, i32) {
106105 if count >= 12 {
107106 scanner_coords[ * scanner_id] = point. clone ( ) ;
108107
109- for p in & b_scan {
108+ for p in b_scan {
110109 let q = Point {
111110 x : point. x + p. x ,
112111 y : point. y + p. y ,
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ fn do_move(grid: &mut [Vec<u8>]) -> bool {
6060 }
6161
6262 // then the south-facing herd moves.
63+ #[ allow( clippy:: needless_range_loop) ]
6364 for y in 0 ..ny {
6465 for x in 0 ..nx {
6566 let c = grid[ y] [ x] ;
Original file line number Diff line number Diff line change @@ -84,6 +84,8 @@ fn sum(grid: &[[i32; 5]; 5]) -> i32 {
8484
8585/// `has_win` returns true if the grid has an cleared row or column
8686fn win ( grid : & [ [ i32 ; 5 ] ; 5 ] ) -> bool {
87+
88+ #[ allow( clippy:: needless_range_loop) ]
8789 for i in 0 ..5 {
8890 if grid[ i] [ 0 ] == -1
8991 && grid[ i] [ 1 ] == -1
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ pub fn solve(data: &str) -> (i32, i32) {
2727 if y1 > y2 {
2828 std:: mem:: swap ( & mut y1, & mut y2) ;
2929 }
30+
31+ #[ allow( clippy:: needless_range_loop) ]
3032 for y in y1..=y2 {
3133 grid[ x1] [ y] += 1 ;
3234 }
Original file line number Diff line number Diff line change @@ -87,14 +87,14 @@ fn part2(data: &str) -> u32 {
8787 }
8888
8989 map. insert ( zero. to_string ( ) , 0 ) ;
90- map. insert ( one. to_string ( ) , 1 ) ;
90+ map. insert ( one. clone ( ) , 1 ) ;
9191 map. insert ( two. to_string ( ) , 2 ) ;
9292 map. insert ( three. to_string ( ) , 3 ) ;
93- map. insert ( four. to_string ( ) , 4 ) ;
93+ map. insert ( four. clone ( ) , 4 ) ;
9494 map. insert ( five. to_string ( ) , 5 ) ;
9595 map. insert ( six. to_string ( ) , 6 ) ;
96- map. insert ( seven. to_string ( ) , 7 ) ;
97- map. insert ( eight. to_string ( ) , 8 ) ;
96+ map. insert ( seven. clone ( ) , 7 ) ;
97+ map. insert ( eight. clone ( ) , 8 ) ;
9898 map. insert ( nine. to_string ( ) , 9 ) ;
9999
100100 let mut r = 0 ;
Original file line number Diff line number Diff line change @@ -54,14 +54,14 @@ impl Puzzle {
5454
5555 for ( n1, n2) in & self . connections {
5656 graph
57- . entry ( n1. to_string ( ) )
57+ . entry ( n1. clone ( ) )
5858 . or_default ( )
59- . insert ( n2. to_string ( ) ) ;
59+ . insert ( n2. clone ( ) ) ;
6060
6161 graph
62- . entry ( n2. to_string ( ) )
62+ . entry ( n2. clone ( ) )
6363 . or_default ( )
64- . insert ( n1. to_string ( ) ) ;
64+ . insert ( n1. clone ( ) ) ;
6565 }
6666
6767 for ( node, neighbors) in & graph {
Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ impl Puzzle {
116116 if let Some ( & a) = wires. get ( & gate. a ) {
117117 if let Some ( & b) = wires. get ( & gate. b ) {
118118 let r = gate. op . eval ( a, b) ;
119- * wires. entry ( gate. r . to_string ( ) ) . or_default ( ) = r;
119+ * wires. entry ( gate. r . clone ( ) ) . or_default ( ) = r;
120120 continue ;
121121 }
122122 }
You can’t perform that action at this time.
0 commit comments