Day 21 minor cleanup

This commit is contained in:
Stefan Forstenlechner 2021-12-21 22:25:27 +01:00
parent 52d2edc0fe
commit 68d2c20e00
1 changed files with 4 additions and 17 deletions

View File

@ -1,26 +1,17 @@
#define Day21 #define Day21
using System.Diagnostics;
using System.Threading.Channels;
using AoC2021;
#if Day21 #if Day21
using AoC2021;
var states = File.ReadAllLines("day21/input") var states = File.ReadAllLines("day21/input")
.Select(l => new State() {pos = int.Parse(l[l.Length-1].ToString()) - 1, score = 0}) .Select(l => new State() {pos = int.Parse(l[l.Length-1].ToString()) - 1, score = 0})
.ToList(); .ToList();
// states = new List<State>() {
// new State() {pos = 3, score = 0},
// new State() {pos = 7, score = 0},
// };
var states2 = states.Select(s => s.Copy()).ToList(); var states2 = states.Select(s => s.Copy()).ToList();
var bla = Enumerable.Range(1, 3).SelectMany(x => var diceCombinations = Enumerable.Range(1, 3).SelectMany(x =>
Enumerable.Range(1, 3).SelectMany(y => Enumerable.Range(1, 3).Select(z => new {x = x, y = y, z = z}))) Enumerable.Range(1, 3).SelectMany(y => Enumerable.Range(1, 3).Select(z => new {x = x, y = y, z = z})))
.Select(p => p.x + p.y + p.z).GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()); //ForEachAsList(p => Console.WriteLine(p)); .Select(p => p.x + p.y + p.z).GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
bla.ForEachAsList(b => Console.WriteLine($"{b.Key}: {b.Value}")); diceCombinations.ForEachAsList(b => Console.WriteLine($"{b.Key}: {b.Value}"));
// System.Environment.Exit(0);
int curPlayer = 0; int curPlayer = 0;
int dieThrows = 0; int dieThrows = 0;
@ -41,8 +32,6 @@ Console.WriteLine(minScore * dieThrows);
//------------------ //------------------
Stopwatch sw = new Stopwatch();
sw.Start();
Stack<CompleteState> stack = new Stack<CompleteState>(); Stack<CompleteState> stack = new Stack<CompleteState>();
stack.Push(new CompleteState(0, new StateRec(states2[0].pos, states2[0].score), new StateRec(states2[1].pos, states2[1].score), 1)); stack.Push(new CompleteState(0, new StateRec(states2[0].pos, states2[0].score), new StateRec(states2[1].pos, states2[1].score), 1));
@ -60,8 +49,6 @@ while (stack.Count > 0) {
AddState(Add(curP, 8), cur, p0, p1, winTimes * 3); AddState(Add(curP, 8), cur, p0, p1, winTimes * 3);
AddState(Add(curP, 9), cur, p0, p1, winTimes * 1); AddState(Add(curP, 9), cur, p0, p1, winTimes * 1);
} }
sw.Stop();
Console.WriteLine(sw.Elapsed);
Console.WriteLine(countWin0); Console.WriteLine(countWin0);
Console.WriteLine(countWin1); Console.WriteLine(countWin1);