-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from connorslade/dev
Update daily solution definition format
- Loading branch information
Showing
81 changed files
with
2,107 additions
and
2,311 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
use common::{Answer, Solution}; | ||
use common::{solution, Answer}; | ||
|
||
pub struct Day01; | ||
solution!("Sonar Sweep", 1); | ||
|
||
impl Solution for Day01 { | ||
fn name(&self) -> &'static str { | ||
"Sonar Sweep" | ||
} | ||
fn part_a(input: &str) -> Answer { | ||
let data = input | ||
.lines() | ||
.map(|x| x.parse::<u32>().unwrap()) | ||
.collect::<Vec<u32>>(); | ||
|
||
fn part_a(&self, input: &str) -> Answer { | ||
let data = input | ||
.lines() | ||
.map(|x| x.parse::<u32>().unwrap()) | ||
.collect::<Vec<u32>>(); | ||
|
||
data.windows(2).filter(|x| x[0] < x[1]).count().into() | ||
} | ||
data.windows(2).filter(|x| x[0] < x[1]).count().into() | ||
} | ||
|
||
fn part_b(&self, input: &str) -> Answer { | ||
let d = input | ||
.lines() | ||
.map(|x| x.parse::<u32>().unwrap()) | ||
.collect::<Vec<u32>>(); | ||
fn part_b(input: &str) -> Answer { | ||
let d = input | ||
.lines() | ||
.map(|x| x.parse::<u32>().unwrap()) | ||
.collect::<Vec<u32>>(); | ||
|
||
d.windows(4).filter(|x| x[2] > x[0]).count().into() | ||
} | ||
d.windows(4).filter(|x| x[2] > x[0]).count().into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,45 @@ | ||
use common::{Answer, Solution}; | ||
use common::{solution, Answer}; | ||
|
||
pub struct Day02; | ||
solution!("Dive!", 2); | ||
|
||
impl Solution for Day02 { | ||
fn name(&self) -> &'static str { | ||
"Dive!" | ||
} | ||
|
||
fn part_a(&self, input: &str) -> Answer { | ||
let mut dep: u32 = 0; | ||
let mut hor: u32 = 0; | ||
fn part_a(input: &str) -> Answer { | ||
let mut dep: u32 = 0; | ||
let mut hor: u32 = 0; | ||
|
||
for i in input.lines() { | ||
let seg = i.split(' ').collect::<Vec<&str>>(); | ||
let x = seg[1].parse::<u32>().unwrap(); | ||
for i in input.lines() { | ||
let seg = i.split(' ').collect::<Vec<&str>>(); | ||
let x = seg[1].parse::<u32>().unwrap(); | ||
|
||
match seg[0] { | ||
"forward" => hor += x, | ||
"up" => dep -= x, | ||
"down" => dep += x, | ||
_ => {} | ||
} | ||
match seg[0] { | ||
"forward" => hor += x, | ||
"up" => dep -= x, | ||
"down" => dep += x, | ||
_ => {} | ||
} | ||
|
||
(dep * hor).into() | ||
} | ||
|
||
fn part_b(&self, input: &str) -> Answer { | ||
let mut dep: u32 = 0; | ||
let mut hor: u32 = 0; | ||
let mut aim: u32 = 0; | ||
|
||
for i in input.lines() { | ||
let seg = i.split(' ').collect::<Vec<&str>>(); | ||
let x = seg[1].parse::<u32>().unwrap(); | ||
|
||
match seg[0] { | ||
"forward" => { | ||
hor += x; | ||
dep += aim * x; | ||
} | ||
"up" => aim -= x, | ||
"down" => aim += x, | ||
_ => {} | ||
(dep * hor).into() | ||
} | ||
|
||
fn part_b(input: &str) -> Answer { | ||
let mut dep: u32 = 0; | ||
let mut hor: u32 = 0; | ||
let mut aim: u32 = 0; | ||
|
||
for i in input.lines() { | ||
let seg = i.split(' ').collect::<Vec<&str>>(); | ||
let x = seg[1].parse::<u32>().unwrap(); | ||
|
||
match seg[0] { | ||
"forward" => { | ||
hor += x; | ||
dep += aim * x; | ||
} | ||
"up" => aim -= x, | ||
"down" => aim += x, | ||
_ => {} | ||
} | ||
|
||
(dep * hor).into() | ||
} | ||
|
||
(dep * hor).into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.