Skip to content

Commit

Permalink
[Rust/2015/03] Add solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Defelo committed Sep 20, 2024
1 parent c552db2 commit 8576c8d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@
|[**19**](https://adventofcode.com/2016/day/19) [<img height=12 src=".assets/py.svg">](Python/2016/19.py "Python solution for 2016/19")|[**20**](https://adventofcode.com/2016/day/20) [<img height=12 src=".assets/py.svg">](Python/2016/20.py "Python solution for 2016/20")|[**21**](https://adventofcode.com/2016/day/21) [<img height=12 src=".assets/py.svg">](Python/2016/21.py "Python solution for 2016/21")|[**22**](https://adventofcode.com/2016/day/22) [<img height=12 src=".assets/py.svg">](Python/2016/22.py "Python solution for 2016/22")|[**23**](https://adventofcode.com/2016/day/23) [<img height=12 src=".assets/py.svg">](Python/2016/23.py "Python solution for 2016/23")|[**24**](https://adventofcode.com/2016/day/24) [<img height=12 src=".assets/py.svg">](Python/2016/24.py "Python solution for 2016/24")|[**25**](https://adventofcode.com/2016/day/25) [<img height=12 src=".assets/py.svg">](Python/2016/25.py "Python solution for 2016/25")|
|26|27|28|29|30|31||

## [2015](https://adventofcode.com/2015) ([<img height=18 src=".assets/py.svg"> Python](Python/2015): 25/25 | [<img height=18 src=".assets/ua.png"> Uiua](Uiua/2015): 3/25 | [<img height=18 src=".assets/rs.svg"> Rust](Rust/2015): 2/25)
## [2015](https://adventofcode.com/2015) ([<img height=18 src=".assets/py.svg"> Python](Python/2015): 25/25 | [<img height=18 src=".assets/rs.svg"> Rust](Rust/2015): 3/25 | [<img height=18 src=".assets/ua.png"> Uiua](Uiua/2015): 3/25)
|Mo|Tu|We|Th|Fr|Sa|Su|
|-|-|-|-|-|-|-|
||[**1**](https://adventofcode.com/2015/day/1) [<img height=12 src=".assets/rs.svg">](Rust/2015/01.rs "Rust solution for 2015/01") [<img height=12 src=".assets/py.svg">](Python/2015/01.py "Python solution for 2015/01") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgotwqwuPUAoCuKKgygrMeKKl8KvMVwrKS8rCg== "Uiua solution for 2015/01")|[**2**](https://adventofcode.com/2015/day/2) [<img height=12 src=".assets/rs.svg">](Rust/2015/02.rs "Rust solution for 2015/02") [<img height=12 src=".assets/py.svg">](Python/2015/02.py "Python solution for 2015/02") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipwo4oqc4ouV4omgQHguKeKJoEBcbi4KCuKIqSgvKyspIOKJoeKKgygvw5d8w5cyLeKKgy_ihqUvK3zDt-KKgy_ihqUvw5d8w5cyLyviiaEvw5fil6sy4oavWzRdKQo= "Uiua solution for 2015/02")|[**3**](https://adventofcode.com/2015/day/3) [<img height=12 src=".assets/py.svg">](Python/2015/03.py "Python solution for 2015/03") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgrilr3iiIosInZePD4iCuKItSjiioLiioMoLeKIqT1AXixAdikoLeKIqT1APCxAPikpCgriiKko4qe74oqdKSDiioMo4oqC4oipKFwr4oqCMF8wKSDiiKko4o2J4oqiKeKHjC7ijYnihq_iioI6Ml8yw7cy4qe7LikgKFwr4oqCMF8wKQo= "Uiua solution for 2015/03")|[**4**](https://adventofcode.com/2015/day/4) [<img height=12 src=".assets/py.svg">](Python/2015/04.py "Python solution for 2015/04")|[**5**](https://adventofcode.com/2015/day/5) [<img height=12 src=".assets/py.svg">](Python/2015/05.py "Python solution for 2015/05")|[**6**](https://adventofcode.com/2015/day/6) [<img height=12 src=".assets/py.svg">](Python/2015/06.py "Python solution for 2015/06")|
||[**1**](https://adventofcode.com/2015/day/1) [<img height=12 src=".assets/rs.svg">](Rust/2015/01.rs "Rust solution for 2015/01") [<img height=12 src=".assets/py.svg">](Python/2015/01.py "Python solution for 2015/01") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgotwqwuPUAoCuKKgygrMeKKl8KvMVwrKS8rCg== "Uiua solution for 2015/01")|[**2**](https://adventofcode.com/2015/day/2) [<img height=12 src=".assets/rs.svg">](Rust/2015/02.rs "Rust solution for 2015/02") [<img height=12 src=".assets/py.svg">](Python/2015/02.py "Python solution for 2015/02") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipwo4oqc4ouV4omgQHguKeKJoEBcbi4KCuKIqSgvKyspIOKJoeKKgygvw5d8w5cyLeKKgy_ihqUvK3zDt-KKgy_ihqUvw5d8w5cyLyviiaEvw5fil6sy4oavWzRdKQo= "Uiua solution for 2015/02")|[**3**](https://adventofcode.com/2015/day/3) [<img height=12 src=".assets/rs.svg">](Rust/2015/03.rs "Rust solution for 2015/03") [<img height=12 src=".assets/py.svg">](Python/2015/03.py "Python solution for 2015/03") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgrilr3iiIosInZePD4iCuKItSjiioLiioMoLeKIqT1AXixAdikoLeKIqT1APCxAPikpCgriiKko4qe74oqdKSDiioMo4oqC4oipKFwr4oqCMF8wKSDiiKko4o2J4oqiKeKHjC7ijYnihq_iioI6Ml8yw7cy4qe7LikgKFwr4oqCMF8wKQo= "Uiua solution for 2015/03")|[**4**](https://adventofcode.com/2015/day/4) [<img height=12 src=".assets/py.svg">](Python/2015/04.py "Python solution for 2015/04")|[**5**](https://adventofcode.com/2015/day/5) [<img height=12 src=".assets/py.svg">](Python/2015/05.py "Python solution for 2015/05")|[**6**](https://adventofcode.com/2015/day/6) [<img height=12 src=".assets/py.svg">](Python/2015/06.py "Python solution for 2015/06")|
|[**7**](https://adventofcode.com/2015/day/7) [<img height=12 src=".assets/py.svg">](Python/2015/07.py "Python solution for 2015/07")|[**8**](https://adventofcode.com/2015/day/8) [<img height=12 src=".assets/py.svg">](Python/2015/08.py "Python solution for 2015/08")|[**9**](https://adventofcode.com/2015/day/9) [<img height=12 src=".assets/py.svg">](Python/2015/09.py "Python solution for 2015/09")|[**10**](https://adventofcode.com/2015/day/10) [<img height=12 src=".assets/py.svg">](Python/2015/10.py "Python solution for 2015/10")|[**11**](https://adventofcode.com/2015/day/11) [<img height=12 src=".assets/py.svg">](Python/2015/11.py "Python solution for 2015/11")|[**12**](https://adventofcode.com/2015/day/12) [<img height=12 src=".assets/py.svg">](Python/2015/12.py "Python solution for 2015/12")|[**13**](https://adventofcode.com/2015/day/13) [<img height=12 src=".assets/py.svg">](Python/2015/13.py "Python solution for 2015/13")|
|[**14**](https://adventofcode.com/2015/day/14) [<img height=12 src=".assets/py.svg">](Python/2015/14.py "Python solution for 2015/14")|[**15**](https://adventofcode.com/2015/day/15) [<img height=12 src=".assets/py.svg">](Python/2015/15.py "Python solution for 2015/15")|[**16**](https://adventofcode.com/2015/day/16) [<img height=12 src=".assets/py.svg">](Python/2015/16.py "Python solution for 2015/16")|[**17**](https://adventofcode.com/2015/day/17) [<img height=12 src=".assets/py.svg">](Python/2015/17.py "Python solution for 2015/17")|[**18**](https://adventofcode.com/2015/day/18) [<img height=12 src=".assets/py.svg">](Python/2015/18.py "Python solution for 2015/18")|[**19**](https://adventofcode.com/2015/day/19) [<img height=12 src=".assets/py.svg">](Python/2015/19.py "Python solution for 2015/19")|[**20**](https://adventofcode.com/2015/day/20) [<img height=12 src=".assets/py.svg">](Python/2015/20.py "Python solution for 2015/20")|
|[**21**](https://adventofcode.com/2015/day/21) [<img height=12 src=".assets/py.svg">](Python/2015/21.py "Python solution for 2015/21")|[**22**](https://adventofcode.com/2015/day/22) [<img height=12 src=".assets/py.svg">](Python/2015/22.py "Python solution for 2015/22")|[**23**](https://adventofcode.com/2015/day/23) [<img height=12 src=".assets/py.svg">](Python/2015/23.py "Python solution for 2015/23")|[**24**](https://adventofcode.com/2015/day/24) [<img height=12 src=".assets/py.svg">](Python/2015/24.py "Python solution for 2015/24")|[**25**](https://adventofcode.com/2015/day/25) [<img height=12 src=".assets/py.svg">](Python/2015/25.py "Python solution for 2015/25")|26|27|
Expand Down
37 changes: 37 additions & 0 deletions Rust/2015/03.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#![feature(test)]

use aoc::grid::Direction;
use rustc_hash::FxHashSet;

type Input = Vec<Direction>;

fn setup(input: &str) -> Input {
input.trim().chars().map(|b| b.into()).collect()
}

fn part1(input: &Input) -> usize {
input
.iter()
.scan((0, 0), |acc, &x| {
*acc = x.step_signed(*acc);
Some(*acc)
})
.chain([(0, 0)])
.collect::<FxHashSet<_>>()
.len()
}

fn part2(input: &Input) -> usize {
input
.iter()
.scan(((0, 0), (0, 0)), |(a, b), &x| {
std::mem::swap(a, b);
*a = x.step_signed(*a);
Some(*a)
})
.chain([(0, 0)])
.collect::<FxHashSet<_>>()
.len()
}

aoc::main!(2015, 3, ex: 1);
2 changes: 1 addition & 1 deletion Rust/2015/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
aoc::year! {
"01.rs",
"02.rs",
// "03.rs",
"03.rs",
// "04.rs",
// "05.rs",
// "06.rs",
Expand Down
3 changes: 3 additions & 0 deletions Rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ path = "2015/01.rs"
[[bin]]
name = "2015_02"
path = "2015/02.rs"
[[bin]]
name = "2015_03"
path = "2015/03.rs"

# 2020
[[bin]]
Expand Down

0 comments on commit 8576c8d

Please sign in to comment.