Skip to content

Commit 7dc5977

Browse files
committed
2015 Day 10
1 parent 7b228df commit 7dc5977

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
1313
| [2025](aoc2025) | 14/24 |
1414
| [2024](aoc2024) | 50/50 |
1515
| [2023](aoc2023) | 50/50 |
16-
| [2015](aoc2015) | 18/50 |
16+
| [2015](aoc2015) | 20/50 |
1717

1818
---
1919

aoc2015/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
1515
| [Day 7](https://adventofcode.com/2024/day/7) | [code](src/bin/07.rs) |||
1616
| [Day 8](https://adventofcode.com/2024/day/8) | [code](src/bin/08.rs) |||
1717
| [Day 9](https://adventofcode.com/2024/day/9) | [code](src/bin/09.rs) |||
18-
| [Day 10](https://adventofcode.com/2024/day/10) | [code](src/bin/10.rs) | _ | _ |
18+
| [Day 10](https://adventofcode.com/2024/day/10) | [code](src/bin/10.rs) | | |
1919
| [Day 11](https://adventofcode.com/2024/day/11) | [code](src/bin/11.rs) | _ | _ |
2020
| [Day 12](https://adventofcode.com/2024/day/12) | [code](src/bin/12.rs) | _ | _ |
2121
| [Day 13](https://adventofcode.com/2024/day/13) | [code](src/bin/13.rs) | _ | _ |

aoc2015/data/examples/10.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
211

aoc2015/src/bin/10.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
advent_of_code::solution!(10);
2+
3+
fn run_n_times(input: &str, n: usize) -> String {
4+
let mut curr = input.trim().to_string();
5+
let mut new = String::new();
6+
for _ in 0..n {
7+
let mut chars = curr.chars();
8+
let mut curr_char = chars.next().expect("Should never have empty string");
9+
let mut curr_count = 1;
10+
for c in chars {
11+
if c != curr_char {
12+
new += &format!("{curr_count}{curr_char}");
13+
curr_char = c;
14+
curr_count = 1;
15+
} else {
16+
curr_count += 1;
17+
}
18+
}
19+
curr = new + &format!("{curr_count}{curr_char}");
20+
new = String::new();
21+
}
22+
curr
23+
}
24+
25+
pub fn part_one(input: &str) -> Option<u64> {
26+
let res = run_n_times(input, 40);
27+
Some(res.len() as u64)
28+
}
29+
30+
pub fn part_two(input: &str) -> Option<u64> {
31+
let res = run_n_times(input, 50);
32+
Some(res.len() as u64)
33+
}
34+
35+
#[cfg(test)]
36+
mod tests {
37+
use super::*;
38+
39+
#[test]
40+
fn test_part_one() {
41+
let result = part_one(&advent_of_code::template::read_file("examples", DAY));
42+
assert_eq!(result, Some(86710));
43+
}
44+
45+
#[test]
46+
fn test_part_two() {
47+
let result = part_two(&advent_of_code::template::read_file("examples", DAY));
48+
assert_eq!(result, Some(1227900));
49+
}
50+
}

0 commit comments

Comments
 (0)