summaryrefslogtreecommitdiffstats
path: root/2015
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2023-11-20 22:52:14 -0500
committeralyx <alyx@aleteoryx.me>2023-11-20 22:52:14 -0500
commitdb4b0b541ea7484be9e0c7576b883990c67fff3a (patch)
tree298a7f0e9e5bcc5bca34be0c6f55e9fc2f249d2b /2015
parent42514d75062817fad36bceffeb5cd9be5a82db3c (diff)
downloadadventofcode-db4b0b541ea7484be9e0c7576b883990c67fff3a.tar.gz
adventofcode-db4b0b541ea7484be9e0c7576b883990c67fff3a.tar.bz2
adventofcode-db4b0b541ea7484be9e0c7576b883990c67fff3a.zip
2015.10, fix base
Diffstat (limited to '2015')
-rw-r--r--2015/rs/Cargo.lock4
-rw-r--r--2015/rs/base/Cargo.toml8
-rw-r--r--2015/rs/base/src/main.rs5
-rw-r--r--2015/rs/code/ten/Cargo.toml8
-rw-r--r--2015/rs/code/ten/src/main.rs34
5 files changed, 59 insertions, 0 deletions
diff --git a/2015/rs/Cargo.lock b/2015/rs/Cargo.lock
index 5f198ba..9395ee8 100644
--- a/2015/rs/Cargo.lock
+++ b/2015/rs/Cargo.lock
@@ -89,6 +89,10 @@ name = "six"
version = "0.1.0"
[[package]]
+name = "ten"
+version = "0.1.0"
+
+[[package]]
name = "three"
version = "0.1.0"
diff --git a/2015/rs/base/Cargo.toml b/2015/rs/base/Cargo.toml
new file mode 100644
index 0000000..6916ddc
--- /dev/null
+++ b/2015/rs/base/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "base"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/2015/rs/base/src/main.rs b/2015/rs/base/src/main.rs
new file mode 100644
index 0000000..af03856
--- /dev/null
+++ b/2015/rs/base/src/main.rs
@@ -0,0 +1,5 @@
+static INPUT: &str = include_str!("input.txt");
+
+fn main() {
+ let valueified = INPUT;
+}
diff --git a/2015/rs/code/ten/Cargo.toml b/2015/rs/code/ten/Cargo.toml
new file mode 100644
index 0000000..c39e57b
--- /dev/null
+++ b/2015/rs/code/ten/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "ten"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/2015/rs/code/ten/src/main.rs b/2015/rs/code/ten/src/main.rs
new file mode 100644
index 0000000..848c288
--- /dev/null
+++ b/2015/rs/code/ten/src/main.rs
@@ -0,0 +1,34 @@
+use std::fmt::Write;
+
+static INPUT: &str = "1113122113";
+
+fn main() {
+ let mut buf = INPUT.to_string();
+ for _ in 0..40 {
+ buf = part1(&buf);
+ }
+ println!("Final strlen @ 40: {}", buf.len());
+
+ for _ in 0..10 {
+ buf = part1(&buf);
+ }
+ println!("Final strlen @ 50: {}", buf.len());
+}
+
+fn part1(nums: &str) -> String {
+ let mut buf = String::with_capacity(nums.len() * 2); // worst-case
+ let mut chars = nums.chars();
+ let mut last = chars.next().unwrap();
+ let mut count = 1;
+ for char in chars {
+ if char == last {
+ count += 1;
+ } else {
+ let _ = write!(&mut buf, "{count}{last}");
+ last = char;
+ count = 1;
+ }
+ }
+ let _ = write!(&mut buf, "{count}{last}");
+ buf
+}