Skip to content

2022 day 05a - Split issues #2

@GunterSchmidt

Description

@GunterSchmidt

I really like your solution, but could not get it running on windows.

  1. \r\n is not supported and can not easily be implemented as the split requires one char only
  2. \r\n or \n can be at the end of the file, this breaks the logic.

I solved it like this:

   // let d = include_bytes!("../input.txt");
    let mut d_without_cr: Vec<u8> = input.into();
    if d_without_cr.contains(&b'\r') {
        d_without_cr.retain_mut(|it| *it != b'\r');
    };
    if d_without_cr.last().unwrap() == &b'\n' {
        d_without_cr.pop();
    }
    let d = &d_without_cr[..];

I did not want to fork as this of course has a performance impact.
But might be worse mentioning in case any other later comers like me take a look :)

Best,
G.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions