Initial commit
This commit is contained in:
commit
4e5012e63e
9 changed files with 2093 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/target
|
||||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adventofcode2024"
|
||||
version = "0.1.0"
|
||||
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "adventofcode2024"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
1000
input/01-1.in
Normal file
1000
input/01-1.in
Normal file
File diff suppressed because it is too large
Load diff
6
input/02-0.in
Normal file
6
input/02-0.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
7 6 4 2 1
|
||||
1 2 7 8 9
|
||||
9 7 6 2 1
|
||||
1 3 2 4 5
|
||||
8 6 4 4 1
|
||||
1 3 6 7 9
|
||||
1000
input/02-1.in
Normal file
1000
input/02-1.in
Normal file
File diff suppressed because it is too large
Load diff
22
src/bin/01.rs
Normal file
22
src/bin/01.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
fn main() {
|
||||
let text = std::fs::read_to_string("input/01-1.in").unwrap();
|
||||
|
||||
let (mut vec1, mut vec2) = text
|
||||
.trim()
|
||||
.lines()
|
||||
.map(|l| l.split_once(" ").unwrap())
|
||||
.map(|(a, b)| (a.parse::<u32>().unwrap(), b.parse::<u32>().unwrap()))
|
||||
.collect::<(Vec<_>, Vec<_>)>();
|
||||
|
||||
vec1.sort();
|
||||
|
||||
vec2.sort();
|
||||
|
||||
let sum = vec1
|
||||
.iter()
|
||||
.zip(vec2.iter())
|
||||
.map(|(&a, &b)| a.abs_diff(b))
|
||||
.sum::<u32>();
|
||||
|
||||
println!("{}", sum);
|
||||
}
|
||||
50
src/bin/02.rs
Normal file
50
src/bin/02.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
fn main() {
|
||||
let text = std::fs::read_to_string("input/02-1.in").unwrap();
|
||||
|
||||
let t = text
|
||||
.lines()
|
||||
.filter(|l| {
|
||||
let mut f = l.split(' ').map(|c| c.parse::<u32>().unwrap()).peekable();
|
||||
let mut last = f.next().unwrap();
|
||||
let ascending = *f.peek().unwrap() > last;
|
||||
for c in f {
|
||||
if !(1..=3).contains(&c.abs_diff(last)) || (c > last) != ascending {
|
||||
return false;
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
true
|
||||
})
|
||||
.count();
|
||||
|
||||
println!("{}", t);
|
||||
|
||||
let t = text
|
||||
.lines()
|
||||
.filter(|l| {
|
||||
let o = l
|
||||
.split(' ')
|
||||
.map(|c| c.parse::<usize>().unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
(0..o.len()).any(|i| {
|
||||
let f = o
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(j, v)| if i != j { Some(v) } else { None });
|
||||
let mut f = f.peekable();
|
||||
let mut last = f.next().unwrap();
|
||||
let ascending = f.peek().unwrap() > &last;
|
||||
for c in f {
|
||||
if !(1..=3).contains(&c.abs_diff(*last)) || (c > last) != ascending {
|
||||
return false;
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
true
|
||||
})
|
||||
})
|
||||
.count();
|
||||
|
||||
println!("{}", t);
|
||||
}
|
||||
1
src/main.rs
Normal file
1
src/main.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue