aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/day1.rs6
-rw-r--r--src/day2.rs6
-rw-r--r--src/day3.rs2
-rw-r--r--src/day4.rs14
-rw-r--r--src/day6.rs6
5 files changed, 16 insertions, 18 deletions
diff --git a/src/day1.rs b/src/day1.rs
index 2383df8..91ea0bf 100644
--- a/src/day1.rs
+++ b/src/day1.rs
@@ -40,7 +40,7 @@ enum FrequencyOperation {
/// Starting with a frequency of zero, what is the resulting frequency after all of the changes in frequency have been applied?
pub fn part1() {
let input = crate::common::read_stdin_to_string();
- let changes = build_changes(input);
+ let changes = build_changes(&input);
let mut frequency: i64 = 0;
for change in changes.iter() {
@@ -77,7 +77,7 @@ pub fn part1() {
/// What is the first frequency your device reaches twice?
pub fn part2() {
let input = crate::common::read_stdin_to_string();
- let changes = build_changes(input);
+ let changes = build_changes(&input);
let mut frequency: i64 = 0;
let mut frequency_seen: BTreeSet<i64> = BTreeSet::new();
@@ -97,7 +97,7 @@ pub fn part2() {
println!("the first duplicate resulting frequency: {}", frequency);
}
-fn build_changes(input: String) -> Vec<FrequencyChange> {
+fn build_changes(input: &str) -> Vec<FrequencyChange> {
let mut changes = Vec::new();
for line in input.lines() {
diff --git a/src/day2.rs b/src/day2.rs
index da2bb89..6f92604 100644
--- a/src/day2.rs
+++ b/src/day2.rs
@@ -42,7 +42,7 @@ pub fn part1() {
let mut seen_two = false;
let mut seen_three = false;
- for (_, count) in &seen_letter_counts {
+ for count in seen_letter_counts.values() {
if !seen_two && *count == 2 {
seen_two = true;
two_letter_checksum_component += 1;
@@ -82,7 +82,7 @@ pub fn part1() {
pub fn part2() {
let input = crate::common::read_stdin_to_string();
- let matches = find_part2_matches(input).expect("No matches found");
+ let matches = find_part2_matches(&input).expect("No matches found");
let common_letters: String = matches
.0
@@ -98,7 +98,7 @@ pub fn part2() {
);
}
-fn find_part2_matches(input: String) -> Option<(String, String)> {
+fn find_part2_matches(input: &str) -> Option<(String, String)> {
for box_id_1 in input.lines() {
'test_inner: for box_id_2 in input.lines() {
if box_id_1 == box_id_2 {
diff --git a/src/day3.rs b/src/day3.rs
index a41506a..434de69 100644
--- a/src/day3.rs
+++ b/src/day3.rs
@@ -96,7 +96,7 @@ pub fn part2() {
for w in 0..claim.width {
for h in 0..claim.height {
let index = (claim.pos_x + w, claim.pos_y + h);
- if *fabric.get(&index).unwrap() > 1 {
+ if fabric[&index] > 1 {
continue 'claim_loop;
}
}
diff --git a/src/day4.rs b/src/day4.rs
index f3a7593..7c1bf2e 100644
--- a/src/day4.rs
+++ b/src/day4.rs
@@ -70,7 +70,7 @@ pub fn part1() {
.1;
let mut slept_minutes: BTreeMap<i64, i64> = BTreeMap::new();
- for minute in &sleep_schedule.get(&most_slept_guard).unwrap().1 {
+ for minute in &sleep_schedule[&most_slept_guard].1 {
*slept_minutes.entry(*minute).or_insert(0) += 1;
}
@@ -147,12 +147,11 @@ fn build_part_1_sleep_schedule<'a, T: IntoIterator<Item = &'a str>>(
.parse::<i64>()
.unwrap();
- match line.split(' ').skip(2).next().unwrap() {
+ match line.split(' ').nth(2).unwrap() {
"Guard" => {
guard = line
.split(' ')
- .skip(3)
- .next()
+ .nth(3)
.unwrap()
.chars()
.skip(1)
@@ -198,12 +197,11 @@ fn build_part_2_sleep_schedule<'a, T: IntoIterator<Item = &'a str>>(
.parse::<i64>()
.unwrap();
- match line.split(' ').skip(2).next().unwrap() {
+ match line.split(' ').nth(2).unwrap() {
"Guard" => {
guard = line
.split(' ')
- .skip(3)
- .next()
+ .nth(3)
.unwrap()
.chars()
.skip(1)
@@ -215,7 +213,7 @@ fn build_part_2_sleep_schedule<'a, T: IntoIterator<Item = &'a str>>(
last_minute = minute;
}
"wakes" => {
- let guard_entry = sleep_schedule.entry(guard).or_insert(BTreeMap::new());
+ let guard_entry = sleep_schedule.entry(guard).or_insert_with(BTreeMap::new);
let mut minutes_slept = minute - last_minute;
while minutes_slept < 0 {
minutes_slept = 60 - minutes_slept;
diff --git a/src/day6.rs b/src/day6.rs
index 4cf93e1..a8a1202 100644
--- a/src/day6.rs
+++ b/src/day6.rs
@@ -55,7 +55,7 @@ use std::i64;
pub fn part1() {
let input = crate::common::read_stdin_to_string();
- let coords = input_to_coords(input);
+ let coords = input_to_coords(&input);
let bounds = get_bounds(&coords);
let areas = calculate_areas(&coords, bounds);
@@ -102,7 +102,7 @@ pub fn part1() {
pub fn part2() {
let input = crate::common::read_stdin_to_string();
- let coords = input_to_coords(input);
+ let coords = input_to_coords(&input);
let bounds = get_bounds(&coords);
let region_size = calculate_region_size(&coords, bounds);
@@ -112,7 +112,7 @@ pub fn part2() {
);
}
-fn input_to_coords(input: String) -> Vec<(i64, i64)> {
+fn input_to_coords(input: &str) -> Vec<(i64, i64)> {
input
.lines()
.map(|line| {