summaryrefslogtreecommitdiffstats
path: root/src/2020/1/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/2020/1/mod.rs')
-rw-r--r--src/2020/1/mod.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/2020/1/mod.rs b/src/2020/1/mod.rs
new file mode 100644
index 0000000..8aa5290
--- /dev/null
+++ b/src/2020/1/mod.rs
@@ -0,0 +1,27 @@
+pub fn part1() -> anyhow::Result<()> {
+ let ints = crate::util::read_ints("data/1.txt")?;
+ for i in &ints {
+ for j in &ints {
+ if i + j == 2020 {
+ println!("{} * {} = {}", i, j, i * j);
+ return Ok(());
+ }
+ }
+ }
+ Err(anyhow::anyhow!("no numbers summing to 2020 found"))
+}
+
+pub fn part2() -> anyhow::Result<()> {
+ let ints = crate::util::read_ints("data/1.txt")?;
+ for i in &ints {
+ for j in &ints {
+ for k in &ints {
+ if i + j + k == 2020 {
+ println!("{} * {} * {} = {}", i, j, k, i * j * k);
+ return Ok(());
+ }
+ }
+ }
+ }
+ Err(anyhow::anyhow!("no numbers summing to 2020 found"))
+}