Skip to content

Commit bdd83f9

Browse files
committed
Setup initial days
1 parent 42acdbf commit bdd83f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1462
-0
lines changed

.gitignore

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

Cargo.lock

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[workspace]
2+
resolver = "2"
3+
members = [
4+
"aoc",
5+
"d01",
6+
"d02",
7+
"d03",
8+
"d04",
9+
"d05",
10+
"d06",
11+
"d07",
12+
"d08",
13+
"d09",
14+
"d10",
15+
"d11",
16+
"d12",
17+
"d13",
18+
"d14",
19+
"d15",
20+
"d16",
21+
"d17",
22+
"d18",
23+
"d19",
24+
"d20",
25+
"d21",
26+
"d22",
27+
"d23",
28+
"d24",
29+
"d25",
30+
]

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,55 @@
55
My first is to not give up. If start missing days I want to continue trying.
66

77
My second is work on my writing skills. Maybe creating visualizations, writing about my solutions, or just writing about my thought process.
8+
9+
## Tags
10+
11+
### [Day 1](day1/README.md)
12+
13+
### [Day 2](day2/README.md)
14+
15+
### [Day 3](day3/README.md)
16+
17+
### [Day 4](day4/README.md)
18+
19+
### [Day 5](day5/README.md)
20+
21+
### [Day 6](day6/README.md)
22+
23+
### [Day 7](day7/README.md)
24+
25+
### [Day 8](day8/README.md)
26+
27+
### [Day 9](day9/README.md)
28+
29+
### [Day 10](day10/README.md)
30+
31+
### [Day 11](day11/README.md)
32+
33+
### [Day 12](day12/README.md)
34+
35+
### [Day 13](day13/README.md)
36+
37+
### [Day 14](day14/README.md)
38+
39+
### [Day 15](day15/README.md)
40+
41+
### [Day 16](day16/README.md)
42+
43+
### [Day 17](day17/README.md)
44+
45+
### [Day 18](day18/README.md)
46+
47+
### [Day 19](day19/README.md)
48+
49+
### [Day 20](day20/README.md)
50+
51+
### [Day 21](day21/README.md)
52+
53+
### [Day 22](day22/README.md)
54+
55+
### [Day 23](day23/README.md)
56+
57+
### [Day 24](day24/README.md)
58+
59+
### [Day 25](day25/README.md)

aoc/Cargo.lock

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aoc/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "aoc"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
binary-heap-plus = "0.5.0"
10+
itertools = "0.10.5"
11+
num-traits = "0.2.15"

aoc/src/algs/binary_search.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! Module contains generic binary searching methods
2+
3+
use num_traits::Num;
4+
use std::cmp::Ordering;
5+
6+
/// Arbitrary binary search algorithm.
7+
///
8+
/// The index is generic over [`num_traits::Num`].
9+
///
10+
/// # Arguments
11+
/// t - target value
12+
/// f - function that returns value at "index" i
13+
/// start - start "index"
14+
/// end - end "index"
15+
///
16+
/// # Returns
17+
/// Ok(i) - if target value is found at "index" i
18+
/// Err(i) - if target value is not found, but it should be at "index" i
19+
///
20+
/// ```
21+
/// use aoc::algs::binary_search;
22+
///
23+
/// let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
24+
/// assert_eq!(binary_search(&5, |i: usize| v[i], 0, v.len() - 1), Ok(4));
25+
/// assert_eq!(binary_search(&0, |i: usize| v[i], 0, v.len() - 1), Err(0));
26+
/// assert_eq!(binary_search(&11, |i: usize| v[i], 0, v.len() - 1), Err(9));
27+
/// ```
28+
pub fn binary_search<N, T, F>(t: &T, f: F, mut start: N, mut end: N) -> Result<N, N>
29+
where
30+
N: Num + PartialOrd + Copy,
31+
T: std::cmp::PartialOrd,
32+
F: Fn(N) -> T,
33+
{
34+
let two = N::one() + N::one();
35+
36+
while start < end {
37+
let mid = start + (end - start) / two;
38+
let cmp = f(mid).partial_cmp(t).unwrap();
39+
40+
if cmp == Ordering::Less {
41+
start = mid + N::one();
42+
} else if cmp == Ordering::Greater {
43+
end = mid;
44+
} else {
45+
return Ok(mid);
46+
}
47+
}
48+
49+
Err(start)
50+
}

aoc/src/algs/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod binary_search;
2+
3+
pub use binary_search::binary_search;

0 commit comments

Comments
 (0)