mirror of
https://github.com/supleed2/advent-of-code-2022.git
synced 2024-12-22 05:45:47 +00:00
Replace .split('\n') with
.lines()`
This commit is contained in:
parent
2cb4be5758
commit
5b4f4f4150
|
@ -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>()
|
||||
})
|
||||
|
|
|
@ -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)>()
|
||||
})
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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![];
|
||||
|
|
Loading…
Reference in a new issue