Replace .split('\n') with .lines()`

This commit is contained in:
Aadi Desai 2023-10-14 14:52:19 +01:00
parent 2cb4be5758
commit 5b4f4f4150
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
4 changed files with 7 additions and 7 deletions

View file

@ -4,7 +4,7 @@ fn main() -> anyhow::Result<()> {
let mut elves = INPUT let mut elves = INPUT
.split("\n\n") .split("\n\n")
.map(|elf| { .map(|elf| {
elf.split('\n') elf.lines()
.map(|s| s.parse::<usize>().expect("Failed to parse input")) .map(|s| s.parse::<usize>().expect("Failed to parse input"))
.sum::<usize>() .sum::<usize>()
}) })

View file

@ -4,7 +4,7 @@ const INPUT: &str = include_str!("../input/d3.txt");
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
let p1 = INPUT let p1 = INPUT
.split('\n') .lines()
.map(|s| s.split_at(s.len() / 2)) .map(|s| s.split_at(s.len() / 2))
.map(|(l, r)| { .map(|(l, r)| {
l.chars().find(|ch| { l.chars().find(|ch| {
@ -15,7 +15,7 @@ fn main() -> anyhow::Result<()> {
.sum::<usize>(); .sum::<usize>();
println!("{p1}"); println!("{p1}");
let p2 = INPUT let p2 = INPUT
.split('\n') .lines()
.batching(|it| { .batching(|it| {
it.next_tuple::<(&str,&str,&str)>() it.next_tuple::<(&str,&str,&str)>()
}) })

View file

@ -2,13 +2,13 @@ const INPUT: &str = include_str!("../input/d4.txt");
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
let p1 = INPUT let p1 = INPUT
.split('\n') .lines()
.map(Pair::from) .map(Pair::from)
.filter(ranges_contain_each_other) .filter(ranges_contain_each_other)
.count(); .count();
println!("{p1}"); println!("{p1}");
let p2 = INPUT let p2 = INPUT
.split('\n') .lines()
.map(Pair::from) .map(Pair::from)
.filter(ranges_overlap) .filter(ranges_overlap)
.count(); .count();

View file

@ -19,7 +19,7 @@ fn main() -> anyhow::Result<()> {
]; ];
let mut p1c = input.clone(); let mut p1c = input.clone();
let p1m = moves let p1m = moves
.split('\n') .lines()
.map(Move::from); .map(Move::from);
for mv in p1m { for mv in p1m {
for _ in 0..mv.0 { for _ in 0..mv.0 {
@ -34,7 +34,7 @@ fn main() -> anyhow::Result<()> {
println!("{p1}"); println!("{p1}");
let mut p2c = input; let mut p2c = input;
let p2m = moves let p2m = moves
.split('\n') .lines()
.map(Move::from); .map(Move::from);
for mv in p2m { for mv in p2m {
let mut temp = vec![]; let mut temp = vec![];