rename type

This commit is contained in:
Adam Jeniski 2022-12-04 18:44:10 -05:00
parent ee1a97f61a
commit 00bd0cfbde
4 changed files with 18 additions and 17 deletions

View File

@ -1,17 +1,17 @@
type Input = Vec<Vec<i32>>;
type Data = Vec<Vec<i32>>;
fn parse(input: &str) -> Input {
fn parse(input: &str) -> Data {
input
.split("\n\n")
.map(|lines| lines.lines().map(|line| line.parse().unwrap()).collect())
.collect()
}
fn part_one(data: Input) -> i32 {
fn part_one(data: Data) -> i32 {
data.iter().map(|cals| cals.iter().sum()).max().unwrap()
}
fn part_two(data: Input) -> i32 {
fn part_two(data: Data) -> i32 {
let mut cals: std::collections::BinaryHeap<i32> =
data.iter().map(|cals| cals.iter().sum()).collect();
cals.pop().unwrap() + cals.pop().unwrap() + cals.pop().unwrap()

View File

@ -1,7 +1,5 @@
use Shape::*;
type Input = Vec<Vec<char>>;
#[derive(Debug, PartialEq, Eq)]
enum Shape {
Rock,
@ -39,13 +37,16 @@ impl Shape {
}
}
}
fn parse(input: &str) -> Input {
type Data = Vec<Vec<char>>;
fn parse(input: &str) -> Data {
input
.lines()
.map(|line| line.split(' ').map(|s| s.chars().next().unwrap()).collect())
.collect()
}
fn part_one(data: Input) -> i32 {
fn part_one(data: Data) -> i32 {
data.iter()
.map(|round| {
let my_move = Shape::from_char(round[1]);
@ -61,7 +62,7 @@ fn part_one(data: Input) -> i32 {
})
.sum()
}
fn part_two(data: Input) -> i32 {
fn part_two(data: Data) -> i32 {
data.iter()
.map(|round| match round[1] {
'X' => Shape::from_char(round[0]).wins_to().as_int(),

View File

@ -1,4 +1,4 @@
type Input = Vec<String>;
type Data = Vec<String>;
fn get_priority(c: char) -> i32 {
match c {
@ -7,10 +7,10 @@ fn get_priority(c: char) -> i32 {
_ => panic!("expected letter"),
}
}
fn parse(input: &str) -> Input {
fn parse(input: &str) -> Data {
input.lines().map(str::to_owned).collect()
}
fn part_one(data: Input) -> i32 {
fn part_one(data: Data) -> i32 {
data.iter()
.map(|s| {
use std::collections::HashSet;
@ -20,7 +20,7 @@ fn part_one(data: Input) -> i32 {
})
.sum()
}
fn part_two(data: Input) -> i32 {
fn part_two(data: Data) -> i32 {
data.as_slice()
.chunks(3)
.map(|c| {

View File

@ -1,6 +1,6 @@
type Input = Vec<Vec<i32>>;
type Data = Vec<Vec<i32>>;
fn parse(input: &str) -> Input {
fn parse(input: &str) -> Data {
input
.lines()
.map(|line| {
@ -15,7 +15,7 @@ fn parse(input: &str) -> Input {
})
.collect()
}
fn part_one(data: Input) -> i32 {
fn part_one(data: Data) -> i32 {
data.into_iter().fold(0, |acc, curr| {
if (curr[0] <= curr[2] && curr[1] >= curr[3]) || (curr[2] <= curr[0] && curr[3] >= curr[1])
{
@ -25,7 +25,7 @@ fn part_one(data: Input) -> i32 {
}
})
}
fn part_two(data: Input) -> i32 {
fn part_two(data: Data) -> i32 {
data.into_iter().fold(0, |acc, curr| {
if (curr[0] >= curr[2] && curr[0] <= curr[3])
|| (curr[1] >= curr[2] && curr[1] <= curr[3])