Count != 0 is preferred over empty Any() call
This commit is contained in:
parent
dce7542b2b
commit
e7d1481a89
|
@ -13,7 +13,7 @@ public sealed class Day13() : Day(2019, 13, "Care Package")
|
|||
|
||||
private void PrintBoard()
|
||||
{
|
||||
var coords = _updatedCoordinates.Any() ? _updatedCoordinates : _board.Keys.ToList();
|
||||
var coords = _updatedCoordinates.Count != 0 ? _updatedCoordinates : _board.Keys.ToList();
|
||||
foreach (var (x, y) in coords)
|
||||
{
|
||||
if (x < 0 || y < 0) continue;
|
||||
|
@ -55,7 +55,7 @@ public sealed class Day13() : Day(2019, 13, "Care Package")
|
|||
{
|
||||
haltType = _vm.Run();
|
||||
if (printBoard) _updatedCoordinates.Clear();
|
||||
while (_vm.Output.Any())
|
||||
while (_vm.Output.Count != 0)
|
||||
{
|
||||
long x = _vm.Result, y = _vm.Result;
|
||||
_board[(x, y)] = _vm.Result;
|
||||
|
|
|
@ -14,7 +14,7 @@ public sealed class Day17() : Day(2019, 17, "Set and Forget")
|
|||
_vm!.Reset();
|
||||
_vm.Run();
|
||||
var sb = new StringBuilder();
|
||||
while (_vm.Output.Any())
|
||||
while (_vm.Output.Count != 0)
|
||||
sb.Append((char)_vm.Result);
|
||||
// Console.Write(sb);
|
||||
var grid = sb.ToString().Trim().Split().Select(s => s.ToCharArray()).ToArray();
|
||||
|
|
|
@ -19,7 +19,7 @@ public sealed class Day23() : Day(2019, 23, "Category Six")
|
|||
while (true)
|
||||
foreach (var vm in vms)
|
||||
{
|
||||
while (vm.Output.Any())
|
||||
while (vm.Output.Count != 0)
|
||||
{
|
||||
var destination = (int)vm.Result;
|
||||
var x = vm.Result;
|
||||
|
@ -52,7 +52,7 @@ public sealed class Day23() : Day(2019, 23, "Category Six")
|
|||
foreach (var vm in vms)
|
||||
{
|
||||
var isIdle = true;
|
||||
while (vm.Output.Any())
|
||||
while (vm.Output.Count != 0)
|
||||
{
|
||||
var destination = (int)vm.Result;
|
||||
var x = vm.Result;
|
||||
|
|
|
@ -103,7 +103,7 @@ public class IntCodeVM
|
|||
_i += 4;
|
||||
break;
|
||||
case 3:
|
||||
if (!_input.Any())
|
||||
if (_input.Count == 0)
|
||||
return HaltType.Waiting;
|
||||
Set(1, _input.Dequeue());
|
||||
_i += 2;
|
||||
|
|
|
@ -31,7 +31,7 @@ public sealed class Day06() : Day(2020, 6, "Custom Customs")
|
|||
lines.Add(line);
|
||||
}
|
||||
|
||||
if (s.Any())
|
||||
if (s.Count != 0)
|
||||
{
|
||||
_countPart1 += s.Count;
|
||||
_countPart2 += alphabet.Count(a => lines.All(l => l.Contains(a)));
|
||||
|
|
|
@ -46,7 +46,7 @@ public sealed class Day07() : Day(2020, 7, "Handy Haversacks")
|
|||
if (contained.Any(i => i.HasValue && i.Value.Name == node) && p.Add(container))
|
||||
start.Enqueue(container);
|
||||
|
||||
if (!start.Any()) break;
|
||||
if (start.Count == 0) break;
|
||||
}
|
||||
|
||||
return p.Count;
|
||||
|
|
|
@ -75,7 +75,7 @@ public sealed class Day14() : Day(2020, 14, "Docking Data")
|
|||
break;
|
||||
}
|
||||
|
||||
if (floats.Any())
|
||||
if (floats.Count != 0)
|
||||
{
|
||||
var combos = new List<ulong> { addr };
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public sealed class Day22() : Day(2020, 22, "Crab Combat")
|
|||
var seen1 = new HashSet<string>();
|
||||
var seen2 = new HashSet<string>();
|
||||
|
||||
while (deck1.Any() && deck2.Any())
|
||||
while (deck1.Count != 0 && deck2.Count != 0)
|
||||
{
|
||||
if (recursive)
|
||||
{
|
||||
|
@ -92,13 +92,13 @@ public sealed class Day22() : Day(2020, 22, "Crab Combat")
|
|||
public override object Part1()
|
||||
{
|
||||
var (deck1, deck2) = Play(_deck1, _deck2);
|
||||
return CalculateScore(deck1.Any() ? deck1 : deck2);
|
||||
return CalculateScore(deck1.Count == 0 ? deck2 : deck1);
|
||||
}
|
||||
|
||||
public override object Part2()
|
||||
{
|
||||
Reset();
|
||||
var (deck1, deck2) = Play(_deck1, _deck2, recursive: true);
|
||||
return CalculateScore(deck1.Any() ? deck1 : deck2);
|
||||
return CalculateScore(deck1.Count == 0 ? deck2 : deck1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public sealed class Day04() : Day(2021, 4, "Giant Squid")
|
|||
.Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
|
||||
}
|
||||
|
||||
if (currentBoard.Any()) _boards.Add(currentBoard);
|
||||
if (currentBoard.Count != 0) _boards.Add(currentBoard);
|
||||
_size = (int)Math.Sqrt(currentBoard.Count);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ public sealed class Day10() : Day(2021, 10, "Syntax Scoring")
|
|||
|
||||
if (corrupt) continue;
|
||||
var score2 = 0L;
|
||||
while (s.Any())
|
||||
while (s.Count != 0)
|
||||
{
|
||||
score2 *= 5;
|
||||
score2 += ScoresPart2[s.Pop()];
|
||||
|
|
|
@ -41,7 +41,7 @@ public sealed class Day05() : Day(2022, 5, "Supply Stacks")
|
|||
}
|
||||
|
||||
private static string PeekStackTops(IEnumerable<Stack<char>> stacks) =>
|
||||
stacks.Where(s => s.Any()).Aggregate("", (result, stack) => result + stack.Peek());
|
||||
stacks.Where(s => s.Count != 0).Aggregate("", (result, stack) => result + stack.Peek());
|
||||
|
||||
public override object Part1()
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ public sealed class Day05() : Day(2022, 5, "Supply Stacks")
|
|||
var crane = new Stack<char>(quantity);
|
||||
Enumerable.Range(0, quantity).ForEach(_ => crane.Push(_stacksPart2![from].Pop()));
|
||||
|
||||
while (crane.Any()) _stacksPart2![to].Push(crane.Pop());
|
||||
while (crane.Count != 0) _stacksPart2![to].Push(crane.Pop());
|
||||
}
|
||||
|
||||
return PeekStackTops(_stacksPart2!);
|
||||
|
|
|
@ -20,7 +20,7 @@ public sealed class Day11() : Day(2022, 11, "Monkey in the Middle")
|
|||
{
|
||||
foreach (var monkey in _monkeys!)
|
||||
{
|
||||
while (monkey.Items.Any())
|
||||
while (monkey.Items.Count != 0)
|
||||
{
|
||||
var item = monkey.Items.Dequeue();
|
||||
item = monkey.Operation(item);
|
||||
|
|
|
@ -35,7 +35,7 @@ public sealed class Day12() : Day(2022, 12, "Hill Climbing Algorithm")
|
|||
var seen = new HashSet<(int x, int y)> { startCoord };
|
||||
queue.Enqueue((startCoord.x, startCoord.y, 0));
|
||||
|
||||
while (queue.Any())
|
||||
while (queue.Count != 0)
|
||||
{
|
||||
var (x, y, steps) = queue.Dequeue();
|
||||
if (destCoord == (x, y) || (destVal != null && _grid[(x, y)] == destVal)) return steps;
|
||||
|
|
Loading…
Reference in New Issue