Skip to content

Commit

Permalink
AOC day 10 11 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadej Koderman authored and Tadej Koderman committed Dec 12, 2022
1 parent ca39db8 commit dbe8588
Show file tree
Hide file tree
Showing 2 changed files with 414 additions and 12 deletions.
21 changes: 15 additions & 6 deletions AoCCore/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,35 @@ public static IEnumerable<string> StringBatch()
}
}

public static IEnumerable<T> Batch<T>() where T : IParsable<T> => StringBatch().Select(x => T.Parse(x, null));

public static IEnumerable<IEnumerable<T>> Batches<T>() where T : IParsable<T>
public static IEnumerable<string[]> StringBatches()
{
while (true) yield return Batch<T>();
while (true)
{
var batch = StringBatch().ToArray();

if (batch.Length == 0) yield break;

yield return batch;
}
}

public static IEnumerable<T> Batch<T>() where T : IParsable<T> => StringBatch().Select(x => T.Parse(x, null));

public static IEnumerable<T[]> Batches<T>() where T : IParsable<T> => StringBatches().Select(x => x.Select(v => T.Parse(v, null)).ToArray());

public static int Int() => Value<int>();

public static bool TryInt(out int value) => Try(out value);

public static IEnumerable<int> IntBatch() => Batch<int>();

public static IEnumerable<IEnumerable<int>> IntBatches() => Batches<int>();
public static IEnumerable<int[]> IntBatches() => Batches<int>();

public static long Long() => Value<long>();

public static bool TryLong(out long value) => Try(out value);

public static IEnumerable<long> LongBatch() => Batch<long>();

public static IEnumerable<IEnumerable<long>> LongBatches() => Batches<long>();
public static IEnumerable<long[]> LongBatches() => Batches<long>();
}
Loading

0 comments on commit dbe8588

Please sign in to comment.