Trying to do advent of code in Rust. I am very new to rust so please help if you see me doing something stupid!!
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

finished part 1 of day 9! gonna go back to trying to finish day 8 after a night of rest and thinking

Signed-off-by: goose.art <business@goose.art>

goose.art b9cbc042 508725da

verified
+847
+202
day9/Cargo.lock
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "anstream" 7 + version = "0.6.21" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" 10 + dependencies = [ 11 + "anstyle", 12 + "anstyle-parse", 13 + "anstyle-query", 14 + "anstyle-wincon", 15 + "colorchoice", 16 + "is_terminal_polyfill", 17 + "utf8parse", 18 + ] 19 + 20 + [[package]] 21 + name = "anstyle" 22 + version = "1.0.13" 23 + source = "registry+https://github.com/rust-lang/crates.io-index" 24 + checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" 25 + 26 + [[package]] 27 + name = "anstyle-parse" 28 + version = "0.2.7" 29 + source = "registry+https://github.com/rust-lang/crates.io-index" 30 + checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" 31 + dependencies = [ 32 + "utf8parse", 33 + ] 34 + 35 + [[package]] 36 + name = "anstyle-query" 37 + version = "1.1.5" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" 40 + dependencies = [ 41 + "windows-sys", 42 + ] 43 + 44 + [[package]] 45 + name = "anstyle-wincon" 46 + version = "3.0.11" 47 + source = "registry+https://github.com/rust-lang/crates.io-index" 48 + checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" 49 + dependencies = [ 50 + "anstyle", 51 + "once_cell_polyfill", 52 + "windows-sys", 53 + ] 54 + 55 + [[package]] 56 + name = "clap" 57 + version = "4.5.53" 58 + source = "registry+https://github.com/rust-lang/crates.io-index" 59 + checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" 60 + dependencies = [ 61 + "clap_builder", 62 + "clap_derive", 63 + ] 64 + 65 + [[package]] 66 + name = "clap_builder" 67 + version = "4.5.53" 68 + source = "registry+https://github.com/rust-lang/crates.io-index" 69 + checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" 70 + dependencies = [ 71 + "anstream", 72 + "anstyle", 73 + "clap_lex", 74 + "strsim", 75 + ] 76 + 77 + [[package]] 78 + name = "clap_derive" 79 + version = "4.5.49" 80 + source = "registry+https://github.com/rust-lang/crates.io-index" 81 + checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" 82 + dependencies = [ 83 + "heck", 84 + "proc-macro2", 85 + "quote", 86 + "syn", 87 + ] 88 + 89 + [[package]] 90 + name = "clap_lex" 91 + version = "0.7.6" 92 + source = "registry+https://github.com/rust-lang/crates.io-index" 93 + checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" 94 + 95 + [[package]] 96 + name = "colorchoice" 97 + version = "1.0.4" 98 + source = "registry+https://github.com/rust-lang/crates.io-index" 99 + checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" 100 + 101 + [[package]] 102 + name = "day9" 103 + version = "0.1.0" 104 + dependencies = [ 105 + "clap", 106 + "itertools", 107 + ] 108 + 109 + [[package]] 110 + name = "either" 111 + version = "1.15.0" 112 + source = "registry+https://github.com/rust-lang/crates.io-index" 113 + checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" 114 + 115 + [[package]] 116 + name = "heck" 117 + version = "0.5.0" 118 + source = "registry+https://github.com/rust-lang/crates.io-index" 119 + checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 120 + 121 + [[package]] 122 + name = "is_terminal_polyfill" 123 + version = "1.70.2" 124 + source = "registry+https://github.com/rust-lang/crates.io-index" 125 + checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" 126 + 127 + [[package]] 128 + name = "itertools" 129 + version = "0.14.0" 130 + source = "registry+https://github.com/rust-lang/crates.io-index" 131 + checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" 132 + dependencies = [ 133 + "either", 134 + ] 135 + 136 + [[package]] 137 + name = "once_cell_polyfill" 138 + version = "1.70.2" 139 + source = "registry+https://github.com/rust-lang/crates.io-index" 140 + checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" 141 + 142 + [[package]] 143 + name = "proc-macro2" 144 + version = "1.0.103" 145 + source = "registry+https://github.com/rust-lang/crates.io-index" 146 + checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" 147 + dependencies = [ 148 + "unicode-ident", 149 + ] 150 + 151 + [[package]] 152 + name = "quote" 153 + version = "1.0.42" 154 + source = "registry+https://github.com/rust-lang/crates.io-index" 155 + checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" 156 + dependencies = [ 157 + "proc-macro2", 158 + ] 159 + 160 + [[package]] 161 + name = "strsim" 162 + version = "0.11.1" 163 + source = "registry+https://github.com/rust-lang/crates.io-index" 164 + checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 165 + 166 + [[package]] 167 + name = "syn" 168 + version = "2.0.111" 169 + source = "registry+https://github.com/rust-lang/crates.io-index" 170 + checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" 171 + dependencies = [ 172 + "proc-macro2", 173 + "quote", 174 + "unicode-ident", 175 + ] 176 + 177 + [[package]] 178 + name = "unicode-ident" 179 + version = "1.0.22" 180 + source = "registry+https://github.com/rust-lang/crates.io-index" 181 + checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" 182 + 183 + [[package]] 184 + name = "utf8parse" 185 + version = "0.2.2" 186 + source = "registry+https://github.com/rust-lang/crates.io-index" 187 + checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 188 + 189 + [[package]] 190 + name = "windows-link" 191 + version = "0.2.1" 192 + source = "registry+https://github.com/rust-lang/crates.io-index" 193 + checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 194 + 195 + [[package]] 196 + name = "windows-sys" 197 + version = "0.61.2" 198 + source = "registry+https://github.com/rust-lang/crates.io-index" 199 + checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 200 + dependencies = [ 201 + "windows-link", 202 + ]
+8
day9/Cargo.toml
··· 1 + [package] 2 + name = "day9" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + clap = { version = "4.5.53", features = ["derive"] } 8 + itertools = "0.14.0"
+496
day9/input.txt
··· 1 + 97819,50153 2 + 97819,51361 3 + 97695,51361 4 + 97695,52560 5 + 97478,52560 6 + 97478,53816 7 + 98081,53816 8 + 98081,54975 9 + 97418,54975 10 + 97418,56200 11 + 97473,56200 12 + 97473,57459 13 + 97673,57459 14 + 97673,58694 15 + 97628,58694 16 + 97628,59810 17 + 96976,59810 18 + 96976,60944 19 + 96485,60944 20 + 96485,62061 21 + 95974,62061 22 + 95974,63248 23 + 95748,63248 24 + 95748,64662 25 + 96214,64662 26 + 96214,65764 27 + 95642,65764 28 + 95642,66755 29 + 94801,66755 30 + 94801,67896 31 + 94390,67896 32 + 94390,69110 33 + 94141,69110 34 + 94141,70168 35 + 93526,70168 36 + 93526,71446 37 + 93369,71446 38 + 93369,72267 39 + 92298,72267 40 + 92298,73226 41 + 91531,73226 42 + 91531,74355 43 + 91073,74355 44 + 91073,75528 45 + 90666,75528 46 + 90666,76633 47 + 90131,76633 48 + 90131,77691 49 + 89515,77691 50 + 89515,78771 51 + 88919,78771 52 + 88919,79538 53 + 87908,79538 54 + 87908,80478 55 + 87135,80478 56 + 87135,81550 57 + 86514,81550 58 + 86514,81966 59 + 85154,81966 60 + 85154,83369 61 + 84879,83369 62 + 84879,84065 63 + 83848,84065 64 + 83848,84550 65 + 82633,84550 66 + 82633,85553 67 + 81914,85553 68 + 81914,86608 69 + 81224,86608 70 + 81224,87400 71 + 80297,87400 72 + 80297,87882 73 + 79129,87882 74 + 79129,89069 75 + 78496,89069 76 + 78496,89747 77 + 77476,89747 78 + 77476,89792 79 + 76042,89792 80 + 76042,90412 81 + 75009,90412 82 + 75009,91317 83 + 74144,91317 84 + 74144,91746 85 + 72996,91746 86 + 72996,92544 87 + 72050,92544 88 + 72050,93038 89 + 70940,93038 90 + 70940,93570 91 + 69850,93570 92 + 69850,93848 93 + 68650,93848 94 + 68650,94995 95 + 67806,94995 96 + 67806,95319 97 + 66619,95319 98 + 66619,95177 99 + 65280,95177 100 + 65280,95556 101 + 64133,95556 102 + 64133,96445 103 + 63128,96445 104 + 63128,96494 105 + 61879,96494 106 + 61879,96939 107 + 60734,96939 108 + 60734,97073 109 + 59516,97073 110 + 59516,97437 111 + 58345,97437 112 + 58345,97884 113 + 57178,97884 114 + 57178,97310 115 + 55871,97310 116 + 55871,97628 117 + 54689,97628 118 + 54689,97534 119 + 53466,97534 120 + 53466,97639 121 + 52263,97639 122 + 52263,98179 123 + 51066,98179 124 + 51066,98009 125 + 49846,98009 126 + 49846,97587 127 + 48641,97587 128 + 48641,97442 129 + 47441,97442 130 + 47441,97554 131 + 46225,97554 132 + 46225,97865 133 + 44977,97865 134 + 44977,97399 135 + 43808,97399 136 + 43808,97907 137 + 42503,97907 138 + 42503,96814 139 + 41454,96814 140 + 41454,97405 141 + 40099,97405 142 + 40099,96388 143 + 39078,96388 144 + 39078,96382 145 + 37832,96382 146 + 37832,96415 147 + 36557,96415 148 + 36557,95283 149 + 35632,95283 150 + 35632,95832 151 + 34169,95832 152 + 34169,94609 153 + 33315,94609 154 + 33315,94140 155 + 32203,94140 156 + 32203,93620 157 + 31115,93620 158 + 31115,93612 159 + 29791,93612 160 + 29791,92816 161 + 28827,92816 162 + 28827,92854 163 + 27439,92854 164 + 27439,92120 165 + 26444,92120 166 + 26444,91350 167 + 25479,91350 168 + 25479,91029 169 + 24243,91029 170 + 24243,90150 171 + 23354,90150 172 + 23354,88965 173 + 22693,88965 174 + 22693,88616 175 + 21452,88616 176 + 21452,87622 177 + 20684,87622 178 + 20684,87088 179 + 19560,87088 180 + 19560,86108 181 + 18800,86108 182 + 18800,85166 183 + 18022,85166 184 + 18022,84526 185 + 16968,84526 186 + 16968,83798 187 + 15983,83798 188 + 15983,83275 189 + 14768,83275 190 + 14768,82119 191 + 14219,82119 192 + 14219,81229 193 + 13385,81229 194 + 13385,80353 195 + 12529,80353 196 + 12529,78959 197 + 12338,78959 198 + 12338,78258 199 + 11257,78258 200 + 11257,77432 201 + 10316,77432 202 + 10316,76306 203 + 9804,76306 204 + 9804,75257 205 + 9186,75257 206 + 9186,74070 207 + 8808,74070 208 + 8808,73346 209 + 7617,73346 210 + 7617,72112 211 + 7336,72112 212 + 7336,71130 213 + 6571,71130 214 + 6571,69839 215 + 6453,69839 216 + 6453,68884 217 + 5601,68884 218 + 5601,67730 219 + 5195,67730 220 + 5195,66371 221 + 5358,66371 222 + 5358,65433 223 + 4369,65433 224 + 4369,64085 225 + 4595,64085 226 + 4595,62951 227 + 4183,62951 228 + 4183,61942 229 + 3257,61942 230 + 3257,60761 231 + 2939,60761 232 + 2939,59474 233 + 3133,59474 234 + 3133,58235 235 + 3186,58235 236 + 3186,57057 237 + 2924,57057 238 + 2924,55964 239 + 1943,55964 240 + 1943,54727 241 + 1983,54727 242 + 1983,53526 243 + 1643,53526 244 + 1643,52258 245 + 2454,52258 246 + 2454,51063 247 + 1936,51063 248 + 1936,50143 249 + 94800,50143 250 + 94800,48628 251 + 1967,48628 252 + 1967,47420 253 + 2174,47420 254 + 2174,46235 255 + 2572,46235 256 + 2572,45009 257 + 2439,45009 258 + 2439,43789 259 + 2455,43789 260 + 2455,42617 261 + 2817,42617 262 + 2817,41320 263 + 2452,41320 264 + 2452,40171 265 + 2941,40171 266 + 2941,39071 267 + 3579,39071 268 + 3579,37926 269 + 3978,37926 270 + 3978,36593 271 + 3706,36593 272 + 3706,35458 273 + 4168,35458 274 + 4168,34184 275 + 4208,34184 276 + 4208,33283 277 + 5303,33283 278 + 5303,32050 279 + 5479,32050 280 + 5479,31124 281 + 6400,31124 282 + 6400,29843 283 + 6498,29843 284 + 6498,28596 285 + 6717,28596 286 + 6717,27511 287 + 7282,27511 288 + 7282,26340 289 + 7694,26340 290 + 7694,25288 291 + 8327,25288 292 + 8327,24719 293 + 9728,24719 294 + 9728,23535 295 + 10122,23535 296 + 10122,22481 297 + 10731,22481 298 + 10731,21219 299 + 11068,21219 300 + 11068,20260 301 + 11832,20260 302 + 11832,19402 303 + 12719,19402 304 + 12719,18681 305 + 13753,18681 306 + 13753,17399 307 + 14147,17399 308 + 14147,16842 309 + 15341,16842 310 + 15341,15813 311 + 16031,15813 312 + 16031,15227 313 + 17157,15227 314 + 17157,14012 315 + 17695,14012 316 + 17695,13399 317 + 18782,13399 318 + 18782,12438 319 + 19572,12438 320 + 19572,12015 321 + 20791,12015 322 + 20791,11392 323 + 21840,11392 324 + 21840,10247 325 + 22519,10247 326 + 22519,10010 327 + 23828,10010 328 + 23828,9084 329 + 24678,9084 330 + 24678,8491 331 + 25744,8491 332 + 25744,7863 333 + 26788,7863 334 + 26788,6987 335 + 27707,6987 336 + 27707,6573 337 + 28870,6573 338 + 28870,5960 339 + 29935,5960 340 + 29935,5408 341 + 31033,5408 342 + 31033,4964 343 + 32177,4964 344 + 32177,4548 345 + 33332,4548 346 + 33332,4435 347 + 34588,4435 348 + 34588,4188 349 + 35787,4188 350 + 35787,4063 351 + 37014,4063 352 + 37014,3490 353 + 38116,3490 354 + 38116,3175 355 + 39292,3175 356 + 39292,3040 357 + 40506,3040 358 + 40506,2347 359 + 41616,2347 360 + 41616,2950 361 + 42946,2950 362 + 42946,2088 363 + 44053,2088 364 + 44053,2542 365 + 45327,2542 366 + 45327,2293 367 + 46520,2293 368 + 46520,2372 369 + 47737,2372 370 + 47737,1604 371 + 48928,1604 372 + 48928,1823 373 + 50154,1823 374 + 50154,2178 375 + 51365,2178 376 + 51365,1738 377 + 52602,1738 378 + 52602,1788 379 + 53826,1788 380 + 53826,2273 381 + 55007,2273 382 + 55007,2068 383 + 56260,2068 384 + 56260,2614 385 + 57414,2614 386 + 57414,3231 387 + 58537,3231 388 + 58537,2920 389 + 59832,2920 390 + 59832,3681 391 + 60904,3681 392 + 60904,3946 393 + 62081,3946 394 + 62081,4131 395 + 63283,4131 396 + 63283,4652 397 + 64387,4652 398 + 64387,4844 399 + 65596,4844 400 + 65596,5340 401 + 66703,5340 402 + 66703,5487 403 + 67945,5487 404 + 67945,5728 405 + 69166,5728 406 + 69166,6794 407 + 70019,6794 408 + 70019,7116 409 + 71206,7116 410 + 71206,7226 411 + 72517,7226 412 + 72517,7707 413 + 73651,7707 414 + 73651,8446 415 + 74640,8446 416 + 74640,9118 417 + 75664,9118 418 + 75664,10000 419 + 76545,10000 420 + 76545,10362 421 + 77777,10362 422 + 77777,11195 423 + 78686,11195 424 + 78686,12344 425 + 79340,12344 426 + 79340,12818 427 + 80515,12818 428 + 80515,13383 429 + 81638,13383 430 + 81638,14591 431 + 82196,14591 432 + 82196,14977 433 + 83505,14977 434 + 83505,16181 435 + 84036,16181 436 + 84036,16826 437 + 85122,16826 438 + 85122,17980 439 + 85670,17980 440 + 85670,19070 441 + 86263,19070 442 + 86263,19578 443 + 87553,19578 444 + 87553,20767 445 + 88016,20767 446 + 88016,21839 447 + 88608,21839 448 + 88608,22815 449 + 89324,22815 450 + 89324,23773 451 + 90072,23773 452 + 90072,24865 453 + 90613,24865 454 + 90613,25784 455 + 91439,25784 456 + 91439,26819 457 + 92080,26819 458 + 92080,27995 459 + 92456,27995 460 + 92456,28855 461 + 93456,28855 462 + 93456,30075 463 + 93733,30075 464 + 93733,31143 465 + 94332,31143 466 + 94332,32193 467 + 94995,32193 468 + 94995,33560 469 + 94829,33560 470 + 94829,34660 471 + 95352,34660 472 + 95352,35816 473 + 95717,35816 474 + 95717,36836 475 + 96569,36836 476 + 96569,38156 477 + 96354,38156 478 + 96354,39394 479 + 96376,39394 480 + 96376,40441 481 + 97281,40441 482 + 97281,41617 483 + 97650,41617 484 + 97650,42900 485 + 97353,42900 486 + 97353,44047 487 + 97963,44047 488 + 97963,45312 489 + 97609,45312 490 + 97609,46476 491 + 98312,46476 492 + 98312,47743 493 + 97494,47743 494 + 97494,48929 495 + 98347,48929 496 + 98347,50153
+8
day9/smallinput.txt
··· 1 + 7,1 2 + 11,1 3 + 11,7 4 + 9,7 5 + 9,5 6 + 2,5 7 + 2,3 8 + 7,3
+55
day9/src/floortiles.rs
··· 1 + use itertools::Itertools; 2 + use std::fmt::Display; 3 + 4 + #[derive(Debug)] 5 + pub struct FloorTiles { 6 + pub red_tiles: Vec<(usize, usize)>, 7 + pub rows: usize, 8 + pub cols: usize, 9 + } 10 + 11 + impl FloorTiles { 12 + pub fn load(filename: &str) -> Self { 13 + println!("trying to read {}", filename); 14 + let contents = std::fs::read_to_string(filename).expect("unable to read file as string"); 15 + let red_tiles: Vec<(usize, usize)> = contents 16 + .lines() 17 + .map(|line| { 18 + line.split(',') 19 + .map(|num| num.parse().expect("Could not parse {num}")) 20 + .collect_tuple() 21 + .expect("Unable to parse tuple") 22 + }) 23 + .collect(); 24 + FloorTiles { 25 + rows: red_tiles.iter().fold(0, |a, b| a.max(b.0)) + 1, 26 + cols: red_tiles.iter().fold(0, |a, b| a.max(b.1)) + 1, 27 + red_tiles, 28 + } 29 + } 30 + 31 + fn build_grid(&self) -> Vec<Vec<char>> { 32 + let mut grid = vec![vec!['.'; self.rows + 1]; self.cols + 1]; 33 + for &(row, col) in &self.red_tiles { 34 + if row < self.rows && col < self.cols { 35 + grid[col][row] = '#'; 36 + } 37 + } 38 + grid 39 + } 40 + 41 + fn is_inside(&self, tile: (usize, usize)) -> bool { 42 + tile.0 < self.rows && tile.1 < self.cols 43 + } 44 + } 45 + 46 + impl Display for FloorTiles { 47 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 48 + let grid = self.build_grid(); 49 + writeln!(f)?; 50 + for row in grid { 51 + writeln!(f, "{}", row.iter().collect::<String>())?; 52 + } 53 + Ok(()) 54 + } 55 + }
+46
day9/src/main.rs
··· 1 + use clap::Parser; 2 + mod floortiles; 3 + mod rectangle; 4 + 5 + #[derive(Parser, Debug)] 6 + struct Args { 7 + #[clap(short, long)] 8 + file: String, 9 + #[clap(short, long)] 10 + debug: bool, 11 + } 12 + 13 + fn main() { 14 + let args = Args::parse(); 15 + 16 + let tiles = floortiles::FloorTiles::load(&args.file); 17 + 18 + let mut max_area = 0; 19 + for tilea in 0..tiles.red_tiles.len() { 20 + for tileb in tilea..tiles.red_tiles.len() { 21 + if tiles.red_tiles[tilea].0 == tiles.red_tiles[tileb].0 22 + || tiles.red_tiles[tilea].1 == tiles.red_tiles[tileb].1 23 + { 24 + continue; 25 + } 26 + let rect = rectangle::Rectangle::new(tiles.red_tiles[tilea], tiles.red_tiles[tileb]); 27 + if args.debug { 28 + println!( 29 + "Rectangle from {:?} to {:?} has area: {}", 30 + rect.corn_a, 31 + rect.corn_b, 32 + rect.area() 33 + ); 34 + } 35 + 36 + if rect.area() > max_area { 37 + max_area = rect.area(); 38 + } 39 + } 40 + } 41 + 42 + if args.debug { 43 + println!("Red Tile Locations: {}", tiles); 44 + } 45 + println!("Maximum Area: {}", max_area); 46 + }
+32
day9/src/rectangle.rs
··· 1 + pub struct Rectangle { 2 + pub corn_a: (usize, usize), 3 + pub corn_b: (usize, usize), 4 + pub width: usize, 5 + pub height: usize, 6 + } 7 + 8 + impl Rectangle { 9 + pub fn new(corn_a: (usize, usize), corn_b: (usize, usize)) -> Self { 10 + let width = corn_a 11 + .0 12 + .max(corn_b.0) 13 + .saturating_sub(corn_a.0.min(corn_b.0)) 14 + + 1; 15 + let height = corn_a 16 + .1 17 + .max(corn_b.1) 18 + .saturating_sub(corn_a.1.min(corn_b.1)) 19 + + 1; 20 + 21 + Self { 22 + corn_a, 23 + corn_b, 24 + width, 25 + height, 26 + } 27 + } 28 + 29 + pub fn area(&self) -> usize { 30 + self.width * self.height 31 + } 32 + }