commit 034e1907a51f0a8acb362d59376513aba33fd25b Author: Kienan Stewart Date: Sat Dec 4 21:56:42 2021 -0500 Day 1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6dd29b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/ \ No newline at end of file diff --git a/day1/input b/day1/input new file mode 100644 index 0000000..e4f99d2 --- /dev/null +++ b/day1/input @@ -0,0 +1,100 @@ +85644 +52584 +72349 +83834 +56593 +108492 +94585 +97733 +62732 +103113 +133259 +132647 +52460 +51299 +115749 +121047 +69451 +54737 +62738 +116686 +57293 +97273 +128287 +139440 +97583 +130263 +79307 +118198 +82514 +70679 +64485 +119346 +136281 +114724 +73580 +76314 +126198 +97635 +114655 +104195 +99469 +70251 +82815 +79531 +58135 +80625 +73106 +139806 +138478 +136605 +111472 +149915 +95928 +126905 +70496 +147999 +148501 +114025 +75716 +113473 +95390 +104466 +138715 +53053 +79502 +98601 +115139 +122315 +88402 +124332 +140107 +50912 +104885 +142005 +145938 +118556 +101858 +51142 +94100 +99421 +84544 +137234 +126374 +107333 +82439 +125373 +51212 +99358 +82821 +89913 +67513 +136907 +133707 +139988 +96914 +130672 +66474 +120729 +50131 +67475 diff --git a/day1/main.rs b/day1/main.rs new file mode 100644 index 0000000..41a74ba --- /dev/null +++ b/day1/main.rs @@ -0,0 +1,29 @@ +fn main() { + let contents = std::fs::read_to_string("input") + .expect("Failed to read file 'input'"); + let it = contents.split("\n"); + let mut sum: u64 = 0; + let mut sum2: u64 = 0; + for val in it { + if val == "" { + continue; + } + let mut x = val.parse::().unwrap(); + x /= 3; + x -= 2; + sum += x; + sum2 += x; + while x > 0 { + x /= 3; + if x < 2 { + x = 0; + } + else { + x -= 2; + } + sum2 += x; + } + } + println!("[Part 1] The sum is {}", sum); + println!("[Part 2] The sum is {}", sum2); +}