Reading files using delimiters/terminators

oddp oddp at posteo.de
Sun Dec 27 13:27:49 UTC 2020


On 27.12.20 01:13, Rekel via Digitalmars-d-learn wrote:
> For context, I'm trying this with the puzzle input of day 6 of this year's advent of code. 
> (https://adventofcode.com/)

For that specific puzzle I simply did:

foreach (group; readText("input").splitter("\n\n")) { ... }

Since the input is never that big, I prefer reading in the whole thing and then do the processing.

Also, on other days, when the input is more uniform, there's always 
https://dlang.org/library/std/file/slurp.html which makes reading it in even easier, e.g. day02:

alias Record = Tuple!(int, "low", int, "high", char, "needle", string, "hay");
auto input = slurp!Record("input", "%d-%d %s: %s");

P.S.: would've loved to have had multiwayIntersection in the stdlib for day06 part2, especially when 
there's already multiwayUnion in setops. fold!setIntersection felt a bit clunky.


More information about the Digitalmars-d-learn mailing list