2022-12-08 15:39:18 -08:00
|
|
|
|
using System;
|
2022-12-15 16:11:38 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-12-08 15:39:18 -08:00
|
|
|
|
|
2022-12-22 14:41:35 -08:00
|
|
|
|
namespace AdventOfCode.Common
|
2022-12-08 15:39:18 -08:00
|
|
|
|
{
|
|
|
|
|
public static class AOCExtensions
|
|
|
|
|
{
|
|
|
|
|
public static int ToInt(this string str)
|
|
|
|
|
{
|
2022-12-30 22:39:56 -08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Convert.ToInt32(str);
|
|
|
|
|
}catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-08 15:39:18 -08:00
|
|
|
|
}
|
2022-12-15 16:11:38 -08:00
|
|
|
|
|
|
|
|
|
public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunksize)
|
|
|
|
|
{
|
|
|
|
|
while (source.Any())
|
|
|
|
|
{
|
|
|
|
|
yield return source.Take(chunksize);
|
|
|
|
|
source = source.Skip(chunksize);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-22 14:41:35 -08:00
|
|
|
|
|
|
|
|
|
public static void PrintSquareArray(this int[,] arr)
|
|
|
|
|
{
|
|
|
|
|
for (int x = 0; x < arr.GetLength(0); x++)
|
|
|
|
|
{
|
|
|
|
|
for (int y = 0; y < arr.GetLength(1); y++)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(arr[x,y] + " ");
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-08 15:39:18 -08:00
|
|
|
|
}
|
|
|
|
|
}
|