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
.split("\n\n")
.map(|elf| {
elf.split('\n')
elf.lines()
.map(|s| s.parse::<usize>().expect("Failed to parse input"))
.sum::<usize>()
})

View file

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

View file

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

View file

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