AdventOfCode/AdventOfCode/Common/AOCExtensions.cs

44 lines
1.0 KiB
C#
Raw Normal View History

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
namespace AdventOfCode.Common
2022-12-08 15:39:18 -08:00
{
public static class AOCExtensions
{
public static int ToInt(this string str)
{
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);
}
}
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
}
}