Update lib for iterators
This commit is contained in:
parent
1b9ea6972c
commit
95875d6d2e
4 changed files with 15 additions and 11 deletions
|
|
@ -40,7 +40,7 @@ impl Visibility {
|
||||||
impl Grid {
|
impl Grid {
|
||||||
fn new(text: &str) -> Self {
|
fn new(text: &str) -> Self {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
let lines = aoc::split_lines(text);
|
let lines: Vec<&str> = aoc::lines(text).collect();
|
||||||
|
|
||||||
let rows = lines.len();
|
let rows = lines.len();
|
||||||
let cols = lines[0].len();
|
let cols = lines[0].len();
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,9 @@ struct Step {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_input(input: &str) -> Vec<Step> {
|
fn parse_input(input: &str) -> Vec<Step> {
|
||||||
aoc::split_lines(input)
|
aoc::lines(input)
|
||||||
.iter()
|
|
||||||
.map(|line| {
|
.map(|line| {
|
||||||
let words = aoc::split_words(line);
|
let words: Vec<&str> = aoc::words(line).collect();
|
||||||
|
|
||||||
let d = Direction::from_str(words[0]).unwrap();
|
let d = Direction::from_str(words[0]).unwrap();
|
||||||
let n = words[1].parse::<i64>().unwrap();
|
let n = words[1].parse::<i64>().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,9 @@ enum Instruction {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse(input: &str) -> Vec<Instruction> {
|
fn parse(input: &str) -> Vec<Instruction> {
|
||||||
aoc::split_lines(input)
|
aoc::lines(input)
|
||||||
.iter()
|
|
||||||
.map(|line| {
|
.map(|line| {
|
||||||
let w = aoc::split_words(line);
|
let w: Vec<&str> = aoc::words(line).collect();
|
||||||
match w[0] {
|
match w[0] {
|
||||||
"noop" => Instruction::Noop,
|
"noop" => Instruction::Noop,
|
||||||
"addx" => Instruction::Addx(w[1].parse().unwrap()),
|
"addx" => Instruction::Addx(w[1].parse().unwrap()),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
pub fn split_lines(s: &str) -> Vec<&str> {
|
use std::str::Split;
|
||||||
s.trim_end().split('\n').collect()
|
|
||||||
|
pub fn lines(s: &str) -> Split<char> {
|
||||||
|
s.trim_end().split('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn split_words(s: &str) -> Vec<&str> {
|
pub fn words(s: &str) -> Split<char> {
|
||||||
s.split(' ').collect()
|
s.split(' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn blocks(s: &str) -> Split<&str> {
|
||||||
|
s.split("\n\n")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue