Compare commits
3 Commits
8dd7831caa
...
8158db3ed4
| Author | SHA1 | Date | |
|---|---|---|---|
| 8158db3ed4 | |||
| 0f2024c474 | |||
| d229bb7889 |
BIN
.aoc_tiles/tiles/2025/01.png
Normal file
BIN
.aoc_tiles/tiles/2025/01.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
BIN
.aoc_tiles/tiles/2025/02.png
Normal file
BIN
.aoc_tiles/tiles/2025/02.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
30
.pre-commit-config.yaml
Normal file
30
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
repos:
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: rust-linting
|
||||||
|
name: Rust linting
|
||||||
|
entry: cargo fmt --all --
|
||||||
|
pass_filenames: true
|
||||||
|
types: [file, rust]
|
||||||
|
language: system
|
||||||
|
- id: rust-clippy
|
||||||
|
name: Rust clippy
|
||||||
|
entry: cargo clippy --lib --all-features --tests -- -D warnings
|
||||||
|
pass_filenames: false
|
||||||
|
types: [file, rust]
|
||||||
|
language: system
|
||||||
|
- repo: https://github.com/LiquidFun/aoc_tiles
|
||||||
|
rev: 0.6.4
|
||||||
|
hooks:
|
||||||
|
- id: aoc-tiles
|
||||||
|
# Optionally use these arguments. Auto add tiles to git adds the tiles to git,
|
||||||
|
# possibly amends your commit by creating the tile images and updating the README.
|
||||||
|
# Language sorting shows the preference of the order of the languages to use.
|
||||||
|
# Exclude paterns are globs which can be used to exclude files when creating
|
||||||
|
# the tiles. See the customization section in the README for more flags.
|
||||||
|
# Simply remove the comments (#) below for args and the flags you want.
|
||||||
|
args:
|
||||||
|
- --auto-add-tiles-to-git=amend
|
||||||
|
- --overwrite-year=2025
|
||||||
|
# - --language-sorting=jl,kt,py,rs
|
||||||
|
# - --exclude-patterns=2021/*/*.apl,2021/*/*.py,2021/*/*.cpp
|
||||||
11
README.md
Normal file
11
README.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!-- AOC TILES BEGIN -->
|
||||||
|
<h1 align="center">
|
||||||
|
2025 - 4 ⭐ - Rust
|
||||||
|
</h1>
|
||||||
|
<a href="src/day1.rs">
|
||||||
|
<img src=".aoc_tiles/tiles/2025/01.png" width="161px">
|
||||||
|
</a>
|
||||||
|
<a href="src/day2.rs">
|
||||||
|
<img src=".aoc_tiles/tiles/2025/02.png" width="161px">
|
||||||
|
</a>
|
||||||
|
<!-- AOC TILES END -->
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
use aoc_runner_derive::aoc;
|
use aoc_runner_derive::aoc;
|
||||||
use std::io::{BufRead, BufReader, Lines};
|
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
// PROBLEM 1 solution
|
// PROBLEM 1 solution
|
||||||
#[aoc(day1, part1)]
|
#[aoc(day1, part1)]
|
||||||
@@ -16,7 +14,7 @@ pub fn part1(input: &str) -> u64 {
|
|||||||
let add_val = match sign.as_bytes()[0] {
|
let add_val = match sign.as_bytes()[0] {
|
||||||
b'R' => num_val,
|
b'R' => num_val,
|
||||||
b'L' => mod_val - (num_val % mod_val),
|
b'L' => mod_val - (num_val % mod_val),
|
||||||
c => panic!("Invalid direction {}", c),
|
c => panic!("Invalid direction {c}"),
|
||||||
};
|
};
|
||||||
val = (val + add_val) % mod_val;
|
val = (val + add_val) % mod_val;
|
||||||
if val == 0 {
|
if val == 0 {
|
||||||
@@ -65,7 +63,7 @@ pub fn part2(input: &str) -> i64 {
|
|||||||
let (new_val, add_pass) = match sign.as_bytes()[0] {
|
let (new_val, add_pass) = match sign.as_bytes()[0] {
|
||||||
b'R' => advance::<100>(val, num_val),
|
b'R' => advance::<100>(val, num_val),
|
||||||
b'L' => advance::<100>(val, -num_val),
|
b'L' => advance::<100>(val, -num_val),
|
||||||
c => panic!("Invalid direction {}", c),
|
c => panic!("Invalid direction {c}"),
|
||||||
};
|
};
|
||||||
val = new_val;
|
val = new_val;
|
||||||
pass += add_pass;
|
pass += add_pass;
|
||||||
@@ -77,7 +75,7 @@ pub fn part2(input: &str) -> i64 {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use crate::day1::*;
|
use crate::day1::*;
|
||||||
|
|
||||||
const EXAMPLE: &str = &"L68
|
const EXAMPLE: &str = "L68
|
||||||
L30
|
L30
|
||||||
R48
|
R48
|
||||||
L5
|
L5
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use aoc_runner_derive::{aoc, aoc_generator};
|
use aoc_runner_derive::{aoc, aoc_generator};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::cmp::{max, min};
|
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
|
|
||||||
#[aoc_generator(day2)]
|
#[aoc_generator(day2)]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
mod day1;
|
||||||
mod day2;
|
mod day2;
|
||||||
pub mod day1;
|
|
||||||
|
|
||||||
use aoc_runner_derive::aoc_lib;
|
use aoc_runner_derive::aoc_lib;
|
||||||
|
|
||||||
|
|||||||
@@ -321,7 +321,13 @@ impl<T: Clone + Eq + PartialEq + Debug> Grid<T> {
|
|||||||
self.data
|
self.data
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.find_map(|(pos, val)| if val == haystack { Some(pos as i64) } else { None })
|
.find_map(|(pos, val)| {
|
||||||
|
if val == haystack {
|
||||||
|
Some(pos as i64)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
.unwrap_or(-1),
|
.unwrap_or(-1),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -330,7 +336,10 @@ impl<T: Clone + Eq + PartialEq + Debug> Grid<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn forward_slice<C: AsCoord2d>(&self, start: &C, len: i64) -> Option<&[T]> {
|
pub fn forward_slice<C: AsCoord2d>(&self, start: &C, len: i64) -> Option<&[T]> {
|
||||||
let pos = (self.valid_pos(start), self.valid_pos(&(start.x() + len - 1, start.y())));
|
let pos = (
|
||||||
|
self.valid_pos(start),
|
||||||
|
self.valid_pos(&(start.x() + len - 1, start.y())),
|
||||||
|
);
|
||||||
match pos {
|
match pos {
|
||||||
(Some(pos1), Some(pos2)) => Some(&self.data[pos1..pos2 + 1]),
|
(Some(pos1), Some(pos2)) => Some(&self.data[pos1..pos2 + 1]),
|
||||||
_ => None,
|
_ => None,
|
||||||
@@ -406,7 +415,10 @@ impl Display for Grid<u8> {
|
|||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
for y in 0..self.height() {
|
for y in 0..self.height() {
|
||||||
for x in 0..self.width() {
|
for x in 0..self.width() {
|
||||||
f.write_fmt(format_args!("{}", *self.get(&(x as i64, y as i64)).unwrap() as char))?;
|
f.write_fmt(format_args!(
|
||||||
|
"{}",
|
||||||
|
*self.get(&(x as i64, y as i64)).unwrap() as char
|
||||||
|
))?;
|
||||||
}
|
}
|
||||||
f.write_char('\n')?;
|
f.write_char('\n')?;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user