summaryrefslogtreecommitdiff
path: root/day06
diff options
context:
space:
mode:
Diffstat (limited to 'day06')
-rw-r--r--day06/.gitignore3
-rw-r--r--day06/Cargo.lock7
-rw-r--r--day06/Cargo.toml6
-rw-r--r--day06/src/main.rs103
4 files changed, 119 insertions, 0 deletions
diff --git a/day06/.gitignore b/day06/.gitignore
new file mode 100644
index 0000000..9cd70c0
--- /dev/null
+++ b/day06/.gitignore
@@ -0,0 +1,3 @@
+/target
+/input.txt
+/example*.txt \ No newline at end of file
diff --git a/day06/Cargo.lock b/day06/Cargo.lock
new file mode 100644
index 0000000..5148a23
--- /dev/null
+++ b/day06/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "day06"
+version = "0.1.0"
diff --git a/day06/Cargo.toml b/day06/Cargo.toml
new file mode 100644
index 0000000..6613f87
--- /dev/null
+++ b/day06/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "day06"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/day06/src/main.rs b/day06/src/main.rs
new file mode 100644
index 0000000..e5fd0fa
--- /dev/null
+++ b/day06/src/main.rs
@@ -0,0 +1,103 @@
+use std::io;
+
+fn main() {
+ let mut rows = Vec::new();
+ let mut ops = Vec::new();
+
+ /* Part 1
+ loop {
+ let mut buffer = String::new();
+ let bytes = io::stdin().read_line(&mut buffer).unwrap();
+ if bytes == 0 {
+ break;
+ }
+ let mut iter = buffer.trim_end().split_ascii_whitespace();
+ let first = iter.next().unwrap();
+ match first.parse::<i64>() {
+ Ok(number) => {
+ let mut numbers = Vec::new();
+ numbers.push(number);
+ numbers.extend(iter.map(|x| x.parse::<i64>().unwrap()));
+ rows.push(numbers);
+ },
+ Err(_) => {
+ ops.push(first.to_string());
+ ops.extend(iter.map(|x| x.to_string()));
+ }
+ }
+ }
+ */
+
+ let mut lines = Vec::new();
+
+ loop {
+ let mut buffer = String::new();
+ let bytes = io::stdin().read_line(&mut buffer).unwrap();
+ if bytes == 0 {
+ break;
+ }
+ buffer.pop();
+ lines.push(buffer.to_string());
+ }
+
+ ops.extend(
+ lines
+ .pop()
+ .unwrap()
+ .split_ascii_whitespace()
+ .map(|x| x.to_string()),
+ );
+
+ let lines2: Vec<Vec<char>> = lines.iter().map(|x| x.chars().collect()).collect();
+
+ let mut row = Vec::<i64>::new();
+
+ for col in (0..lines2[0].len()).rev() {
+ let mut numbers = Vec::new();
+ for line in &lines2 {
+ if line[col] != ' ' {
+ numbers.push(line[col].to_digit(10).unwrap());
+ }
+ }
+ match numbers.pop() {
+ Some(number) => {
+ let mut tmp = number;
+ let mut tmp2 = 10;
+ while let Some(number) = numbers.pop() {
+ tmp += number * tmp2;
+ tmp2 *= 10;
+ }
+ row.push(tmp.into());
+ }
+ None => {
+ rows.insert(0, row);
+ row = Vec::new();
+ }
+ }
+ }
+
+ rows.insert(0, row);
+
+ let mut column = Vec::new();
+
+ for col in 0..ops.len() {
+ let mut result = 0;
+ match ops[col].as_str() {
+ "+" => {
+ for row in &rows[col] {
+ result += row;
+ }
+ }
+ "*" => {
+ result = 1;
+ for row in &rows[col] {
+ result *= row;
+ }
+ }
+ &_ => todo!(),
+ }
+ column.push(result);
+ }
+
+ println!("{}", column.iter().sum::<i64>())
+}