Use builtin Enumerable.Chunk() and fix test method naming
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
baa366a62e
commit
49b2c5c515
|
@ -2,16 +2,8 @@ namespace AOC.Common;
|
|||
|
||||
public static class Extensions
|
||||
{
|
||||
public static IEnumerable<string> Chunk(this string str, int chunkSize)
|
||||
{
|
||||
for (var i = 0; i < str.Length; i += chunkSize)
|
||||
yield return str.Substring(i, chunkSize);
|
||||
}
|
||||
|
||||
public static string ToDelimitedString<T>(this IEnumerable<T> enumerable, string delimiter = "")
|
||||
{
|
||||
return string.Join(delimiter, enumerable);
|
||||
}
|
||||
public static string ToDelimitedString<T>(this IEnumerable<T> enumerable, string delimiter = "") =>
|
||||
string.Join(delimiter, enumerable);
|
||||
|
||||
public static IEnumerable<T> Repeat<T>(this IEnumerable<T> sequence, int? count = null)
|
||||
{
|
||||
|
@ -30,10 +22,8 @@ public static class Extensions
|
|||
/// </summary>
|
||||
/// <param name="stopwatch"></param>
|
||||
/// <returns></returns>
|
||||
public static double ScaleMilliseconds(this Stopwatch stopwatch)
|
||||
{
|
||||
return 1_000 * stopwatch.ElapsedTicks / (double)Stopwatch.Frequency;
|
||||
}
|
||||
public static double ScaleMilliseconds(this Stopwatch stopwatch) =>
|
||||
1_000 * stopwatch.ElapsedTicks / (double)Stopwatch.Frequency;
|
||||
|
||||
/// <summary>
|
||||
/// Given an array, it returns a rotated copy.
|
||||
|
@ -107,14 +97,10 @@ public static class Extensions
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static IEnumerable<KeyValuePair<int, T>> Indexed<T>(this IEnumerable<T> source)
|
||||
{
|
||||
return source.Select((t, i) => new KeyValuePair<int, T>(i, t));
|
||||
}
|
||||
public static IEnumerable<KeyValuePair<int, T>> Indexed<T>(this IEnumerable<T> source) =>
|
||||
source.Select((t, i) => new KeyValuePair<int, T>(i, t));
|
||||
|
||||
public static IEnumerable<KeyValuePair<TKey, TValue>> WhereValue<TKey, TValue>(
|
||||
this IEnumerable<KeyValuePair<TKey, TValue>> source, Func<TValue, bool> func)
|
||||
{
|
||||
return source.Where(pair => func(pair.Value));
|
||||
}
|
||||
this IEnumerable<KeyValuePair<TKey, TValue>> source, Func<TValue, bool> func) =>
|
||||
source.Where(pair => func(pair.Value));
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public class Test2015
|
|||
[DataRow(typeof(Day08), "1342", "2074")]
|
||||
[DataRow(typeof(Day09), "117", "909")]
|
||||
[DataRow(typeof(Day10), "492982", "6989950")]
|
||||
public void TestAllDays(Type dayType, string part1, string part2)
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ public class Test2016
|
|||
{
|
||||
[DataTestMethod]
|
||||
[DataRow(typeof(Day01), "", "")]
|
||||
public void TestAllDays(Type dayType, string part1, string part2)
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ public class Test2017
|
|||
{
|
||||
[DataTestMethod]
|
||||
[DataRow(typeof(Day01), "", "")]
|
||||
public void TestAllDays(Type dayType, string part1, string part2)
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ public class Test2018
|
|||
{
|
||||
[DataTestMethod]
|
||||
[DataRow(typeof(Day01), "", "")]
|
||||
public void TestAllDays(Type dayType, string part1, string part2)
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class Test2019
|
|||
[DataRow(typeof(Day06), "145250", "274")]
|
||||
[DataRow(typeof(Day07), "19650", "35961106")]
|
||||
[DataRow(typeof(Day08), "2413",
|
||||
"\nxxx xx xxx xxxx xxx \nx x x x x x x x x \nxxx x x x x xxx \nx x x xxx x x x \nx x x x x x x x \nxxx xx x xxxx xxx ")]
|
||||
"xxx xx xxx xxxx xxx \nx x x x x x x x x \nxxx x x x x xxx \nx x x xxx x x x \nx x x x x x x x \nxxx xx x xxxx xxx ")]
|
||||
[DataRow(typeof(Day09), "3409270027", "82760")]
|
||||
[DataRow(typeof(Day10), "260", "608")]
|
||||
[DataRow(typeof(Day11), "2054",
|
||||
|
@ -33,7 +33,7 @@ public class Test2019
|
|||
[DataRow(typeof(Day23), "23626", "19019")]
|
||||
//[DataRow(typeof(Day24), "", "")]
|
||||
//[DataRow(typeof(Day25), "", "")]
|
||||
public void TestAllDays(Type dayType, string part1, string part2)
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class Test2022
|
|||
[DataRow(typeof(Day01), "24000", "45000")]
|
||||
[DataRow(typeof(Day02), "15", "12")]
|
||||
[DataRow(typeof(Day03), "157", "70")]
|
||||
public void TestAllDays(Type dayType, string part1, string part2)
|
||||
public void CheckTestInputs(Type dayType, string part1, string part2)
|
||||
{
|
||||
Day.UseTestInput = true;
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
|
|
|
@ -17,7 +17,7 @@ public sealed class Day08 : Day
|
|||
|
||||
public override string Part2()
|
||||
{
|
||||
return "\n" + Enumerable.Range(0, 25 * 6)
|
||||
return Enumerable.Range(0, 25 * 6)
|
||||
.Select(p => Enumerable.Range(0, _photo.Count)
|
||||
.Select(l => _photo[l][p])
|
||||
.Aggregate('2', (acc, next) =>
|
||||
|
@ -26,6 +26,7 @@ public sealed class Day08 : Day
|
|||
)
|
||||
.ToDelimitedString()
|
||||
.Chunk(25)
|
||||
.Select(s => new string(s))
|
||||
.ToDelimitedString("\n")
|
||||
.Replace('1', 'x');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue