public ShuffleModel(CharMatrix matrix, WordDFA dfa) { _dfa = dfa; MatrixWords = new List <MatrixWord>(); Matrix = matrix; FindAllWords(); }
public ShuffleModel GetNextModel(char[,] matrix) { _matrix = new CharMatrix(_words, matrix); var model = new ShuffleModel(_matrix, _dfa); return(model); }
public CharMatrix(CharMatrix orig) : this(modshogunPINVOKE.new_CharMatrix__SWIG_5(CharMatrix.getCPtr(orig)), true) { if (modshogunPINVOKE.SWIGPendingException.Pending) { throw modshogunPINVOKE.SWIGPendingException.Retrieve(); } }
public void Test9() { var actual = CharMatrix.Create($"1{Environment.NewLine}2".Pastel(Color.Red), 0, 0, 1, 2); Assert.AreEqual(BeginRed + '1', actual[0, 0]); Assert.AreEqual(BeginRed + '2', actual[0, 1]); }
public ShuffleModel GetNextModel() { _matrix = new CharMatrix(_size, _words, _longwords); var model = new ShuffleModel(_matrix, _dfa); return(model); }
static void Main(string[] args) { Tile.Test(); long part1 = 0; Tile[] tiledPicture = null; int dim = 0; Performance.TimeRun("Part1", () => (part1, tiledPicture, dim) = Part1("input.txt"), 5, 10, 5); Console.WriteLine($"Part 1: {part1}"); int part2 = 0; Matrix2D <char> chart = null; Performance.TimeRun("Part2", () => (part2, chart) = Part2(tiledPicture, dim), 2, 1000, 5); Console.WriteLine($"Part 2: {part2}"); var colormap = CharMatrix.DefaultColorMap(); colormap['*'] = ConsoleColor.White; colormap['.'] = ConsoleColor.DarkBlue; colormap['#'] = ConsoleColor.Blue; colormap['O'] = ConsoleColor.Green; chart.DumpColor(colormap); }
public void Test7() { var cm1 = CharMatrix.Create($"####{Environment.NewLine}# #{Environment.NewLine}####", 0, 0, 4, 3); var cm2 = CharMatrix.Create($"?".Pastel(Color.Green), 1, 1, 1, 1); var cms = new CharMatrixStack(2); cms.Add(cm1); cms.Add(cm2); Assert.AreEqual(cms.X, 0); Assert.AreEqual(cms.Y, 0); Assert.AreEqual(cms.W, 4); Assert.AreEqual(cms.H, 3); Assert.AreEqual(ColoredStringExt.End + '#', cms[0, 0]); Assert.AreEqual(ColoredStringExt.End + '#', cms[1, 0]); Assert.AreEqual(ColoredStringExt.End + '#', cms[2, 0]); Assert.AreEqual(ColoredStringExt.End + '#', cms[3, 0]); Assert.AreEqual(ColoredStringExt.End + '#', cms[0, 1]); Assert.AreEqual(EnumerateWithColorInfoTests.BeginGreen + '?', cms[1, 1]); Assert.AreEqual(ColoredStringExt.End + ' ', cms[2, 1]); Assert.AreEqual(ColoredStringExt.End + '#', cms[3, 1]); Assert.AreEqual(ColoredStringExt.End + '#', cms[0, 2]); Assert.AreEqual(ColoredStringExt.End + '#', cms[1, 2]); Assert.AreEqual(ColoredStringExt.End + '#', cms[2, 2]); Assert.AreEqual(ColoredStringExt.End + '#', cms[3, 2]); }
public static void MyMain(string[] args) { var grille = new CharMatrix(); grille.SetSize(8, 8); grille.ReadValues(); var points = new Dictionary <char, int>(); points.Add('J', 0); points.Add('R', 0); for (var dir = 0; dir < 2; dir++) { for (var y = 0; y < 8; y++) { var x = 0; char color = '0'; var longueur = 0; while (x < 8) { var next = dir == 0 ? grille.Get(x, y) : grille.Get(y, x); if (next == color) { longueur++; } else { if (longueur >= 4) { points[color] += longueur - 3; } longueur = 1; color = next; } x++; } if (longueur >= 4) { points[color] += longueur - 3; } } } if (points['R'] > points['J']) { Console.WriteLine("R"); } else if (points['R'] < points['J']) { Console.WriteLine("J"); } else { Console.WriteLine("NOBODY"); } }
private void FindAllWords() { var allCoordinates = CharMatrix.GetAllCoordinates(Matrix.Size); foreach (var coord in allCoordinates) { FindWords(coord); } }
private static bool TryParseMessage(Point[] points, out string message) { // Don't "parse" as such, but just do a crude check for well-known // message patterns. var(minx, maxx) = (points.Min(p => p.X), points.Max(p => p.X)); var(miny, maxy) = (points.Min(p => p.Y), points.Max(p => p.Y)); var(width, height) = (maxx - minx + 1, maxy - miny + 1); var map = CharMatrix.Create(width, height, ' '); foreach (var p in points) { map[p.X - minx, p.Y - miny] = '#'; } //map.ConsoleWrite(); var parseable = new Dictionary <string, char[, ]> { { "HI", new string[] { "# # ###", "# # # ", "# # # ", "##### # ", "# # # ", "# # # ", "# # # ", "# # ###", }.ToCharMatrix() }, { "PHLGRNFK", new string[] { "##### # # # #### ##### # # ###### # #", "# # # # # # # # # ## # # # # ", "# # # # # # # # ## # # # # ", "# # # # # # # # # # # # # # ", "##### ###### # # ##### # # # ##### ## ", "# # # # # ### # # # # # # ## ", "# # # # # # # # # # # # # # ", "# # # # # # # # # ## # # # ", "# # # # # ## # # # ## # # # ", "# # # ###### ### # # # # # # # #" }.ToCharMatrix() } }; message = parseable .Where(p => map.Match(p.Value)) .Select(x => x.Key) .FirstOrDefault(); return(message != null); }
public void Test11() { var cm = CharMatrix.Create("!", 1, 1, 1, 1); Assert.AreEqual(cm.X, 1); Assert.AreEqual(cm.Y, 1); Assert.AreEqual(cm.W, 1); Assert.AreEqual(cm.H, 1); Assert.AreEqual(End + '!', cm[1, 1]); }
public void Test2() { var cm = CharMatrix.Create("!", 0, 0, 2, 1); Assert.AreEqual(cm.X, 0); Assert.AreEqual(cm.Y, 0); Assert.AreEqual(cm.W, 2); Assert.AreEqual(cm.H, 1); Assert.AreEqual(End + '!', cm[0, 0]); Assert.AreEqual(End + ' ', cm[1, 0]); }
public Matrix2D <char> GetTransformedMatrix() { bool rotate, hflip, vflip; (rotate, hflip, vflip) = DecodeTransform(CurrentOrientation); List <string> lines = new List <string>(); for (int y = 0; y < (rotate ? Width : Height); y++) { lines.Add(new string(GetTransformedLine(y, true))); } return(CharMatrix.Build(lines)); }
public void Test1() { var cm = CharMatrix.Create("!", 0, 0, 1, 1); var cms = new CharMatrixStack(1); cms.Add(cm); Assert.AreEqual(cms.X, 0); Assert.AreEqual(cms.Y, 0); Assert.AreEqual(cms.W, 1); Assert.AreEqual(cms.H, 1); Assert.AreEqual(ColoredStringExt.End + '!', cms[0, 0]); }
static void Cipher() { CipherText = new StringBuilder(); foreach (var next in CipherOrder) { int n = int.Parse(next); n--; for (int i = 0; i < CharMatrix.GetLength(0); i++) { CipherText.Append(CharMatrix[i, n]); } } }
public void Test4() { var cm = CharMatrix.Create("!".Pastel(Color.Red), 0, 0, 2, 2); Assert.AreEqual(cm.X, 0); Assert.AreEqual(cm.Y, 0); Assert.AreEqual(cm.W, 2); Assert.AreEqual(cm.H, 2); Assert.AreEqual(BeginRed + '!', cm[0, 0]); Assert.AreEqual(End + ' ', cm[1, 0]); Assert.AreEqual(End + ' ', cm[0, 1]); Assert.AreEqual(End + ' ', cm[1, 1]); }
private void CanvasControlOnDraw(CanvasControl sender, CanvasDrawEventArgs args) { for (var y = 0; y < CharMatrix.GetUpperBound(1); y++) { var finalY = (float)(y * CharHeight); for (var x = 0; x < CharMatrix.GetUpperBound(0); x++) { var text = new String(CharMatrix[x, y], 1); var position = new Vector2((float)(x * CharWidth), finalY); args.DrawingSession.DrawText(text, position, TextColor); } } }
public void Test5() { var cm = CharMatrix.Create($"12{Environment.NewLine}34".Pastel(Color.Red), 0, 0, 2, 2); Assert.AreEqual(cm.X, 0); Assert.AreEqual(cm.Y, 0); Assert.AreEqual(cm.W, 2); Assert.AreEqual(cm.H, 2); Assert.AreEqual(BeginRed + '1', cm[0, 0]); Assert.AreEqual(BeginRed + '2', cm[1, 0]); Assert.AreEqual(BeginRed + '3', cm[0, 1]); Assert.AreEqual(BeginRed + '4', cm[1, 1]); }
public void Test3() { var cm1 = CharMatrix.Create("\0!", 0, 0, 2, 1); var cm2 = CharMatrix.Create("?\0", 0, 0, 2, 1); var cms = new CharMatrixStack(2); cms.Add(cm1); cms.Add(cm2); Assert.AreEqual(cms.X, 0); Assert.AreEqual(cms.Y, 0); Assert.AreEqual(cms.W, 2); Assert.AreEqual(cms.H, 1); Assert.AreEqual(ColoredStringExt.End + '?', cms[0, 0]); Assert.AreEqual(ColoredStringExt.End + '!', cms[1, 0]); }
public void Test6() { var cm = CharMatrix.Create("0" + $"12{Environment.NewLine}34".Pastel(Color.Red) + "0", 0, 0, 3, 2); Assert.AreEqual(cm.X, 0); Assert.AreEqual(cm.Y, 0); Assert.AreEqual(cm.W, 3); Assert.AreEqual(cm.H, 2); Assert.AreEqual(End + '0', cm[0, 0]); Assert.AreEqual(BeginRed + '1', cm[1, 0]); Assert.AreEqual(BeginRed + '2', cm[2, 0]); Assert.AreEqual(BeginRed + '3', cm[0, 1]); Assert.AreEqual(BeginRed + '4', cm[1, 1]); Assert.AreEqual(End + '0', cm[2, 1]); }
public void Test5() { var cm1 = CharMatrix.Create("!!!".Pastel(Color.Red), 0, 0, 3, 1); var cm2 = CharMatrix.Create("\0?\0".Pastel(Color.Green), 0, 0, 3, 1); var cms = new CharMatrixStack(2); cms.Add(cm1); cms.Add(cm2); Assert.AreEqual(cms.X, 0); Assert.AreEqual(cms.Y, 0); Assert.AreEqual(cms.W, 3); Assert.AreEqual(cms.H, 1); Assert.AreEqual(EnumerateWithColorInfoTests.BeginRed + '!', cms[0, 0]); Assert.AreEqual(EnumerateWithColorInfoTests.BeginGreen + '?', cms[1, 0]); Assert.AreEqual(EnumerateWithColorInfoTests.BeginRed + '!', cms[2, 0]); }
static void Main(string[] args) { int count1 = 0; int iter1 = 0; int count2 = 0; int iter2 = 0; Performance.TimeRun("part1 + 2 (with IO)", () => { var input = TextFile.ReadStringList("input.txt"); var matrix = CharMatrix.Build(input); var original = matrix.Clone(); (count1, iter1) = SimulateWithAdjecency(matrix); (count2, iter2) = SimulateWithAdjecency(original, adjacencyFunc: FindClosestSeats, crowdedThreshold: 5); }, 10, 10); Console.WriteLine($"Part1: {count1} seats end up occupied ({iter1} iterations)"); Console.WriteLine($"Part2: {count2} seats end up occupied ({iter2} iterations)"); }
static void Main(string[] args) { Console.WriteLine("podaj sciezke do pliku, ktory ma zostac zaszyfrowany"); var path = Console.ReadLine(); using (StreamReader sr = new StreamReader(path)) { PlainText = sr.ReadToEnd(); } Console.WriteLine("podaj ilosc kolumn macierzy"); int columns = int.Parse(Console.ReadLine()); CreateCharMatrix(columns); bool correctOrder; do { Console.WriteLine("podaj kolejnosc kolumn, numery kolumn powinny oddzielone '-', np. 3-1-2"); SetColumnOrder(Console.ReadLine()); correctOrder = CipherOrder.Length != CharMatrix.GetLength(1); if (correctOrder) { Console.WriteLine("ilosc kolumn podana w kolejnosci nie zgadza sie z rozmiarem macierzy"); } } while (correctOrder); Cipher(); Console.WriteLine(CipherText); Console.WriteLine("czy zapisac szyfr do pliku? (y/n)"); var write = Console.ReadLine(); if (write == "y") { System.IO.StreamWriter file = new System.IO.StreamWriter(path, true); file.WriteLine(Environment.NewLine + "wiadomosc zaszyfrowana: " + Environment.NewLine + CipherText); file.Close(); } }
static (int, Matrix2D <char>) Part2(Tile[] tiledPicture, int dim) { var chart = CombineTiles(tiledPicture, dim); var seaMonsterLines = new List <string>() { " # ", "# ## ## ###", " # # # # # # ", }; var seaMonster = CharMatrix.Build(seaMonsterLines); bool found = false; Matrix2D <char> transformedChart = null; for (int orientation = 0; orientation < 8; orientation++) { chart.CurrentOrientation = orientation; transformedChart = chart.GetTransformedMatrix(); for (int y = 0; y < transformedChart.Height - seaMonster.Height; y++) { for (int x = 0; x < transformedChart.Width - seaMonster.Width; x++) { if (HasAllPixels(transformedChart, seaMonster, x, y)) { found = true; StampValue(transformedChart, seaMonster, x, y, 'O'); } } } if (found) { break; } } if (!found) { throw new ArgumentException("No sea monsters in image!"); } return(transformedChart.Array.Count(c => c == '#'), transformedChart); }
public void Test6() { var cm1 = CharMatrix.Create($"!!!{Environment.NewLine}!!!".Pastel(Color.Red), 0, 0, 3, 2); var cm2 = CharMatrix.Create($"\0?\0{Environment.NewLine}\0?\0".Pastel(Color.Green), 0, 0, 3, 2); var cms = new CharMatrixStack(2); cms.Add(cm1); cms.Add(cm2); Assert.AreEqual(cms.X, 0); Assert.AreEqual(cms.Y, 0); Assert.AreEqual(cms.W, 3); Assert.AreEqual(cms.H, 2); Assert.AreEqual(EnumerateWithColorInfoTests.BeginRed + '!', cms[0, 0]); Assert.AreEqual(EnumerateWithColorInfoTests.BeginGreen + '?', cms[1, 0]); Assert.AreEqual(EnumerateWithColorInfoTests.BeginRed + '!', cms[2, 0]); Assert.AreEqual(EnumerateWithColorInfoTests.BeginRed + '!', cms[0, 1]); Assert.AreEqual(EnumerateWithColorInfoTests.BeginGreen + '?', cms[1, 1]); Assert.AreEqual(EnumerateWithColorInfoTests.BeginRed + '!', cms[2, 1]); }
public Tile(int tileNo, List <string> lines, bool calculateEdges = true) { TileNo = tileNo; matrix = CharMatrix.Build(lines); Width = matrix.Width; Height = matrix.Height; if (calculateEdges) { //cache edges for all orientations: for (int i = 0; i < 8; i++) { bool rotate, hflip, vflip; (rotate, hflip, vflip) = DecodeTransform(i); int[] edges = new int[4]; for (int e = 0; e < 4; e++) { Edge edge = (Edge)e; edges[e] = ToInt(GetTransformedEdge(edge, rotate, hflip, vflip)); } orientedEdges[i] = edges; } } }
private static char[,] ReadScreen(string[] input) { var screen = CharMatrix.Create(Width, Height, ' '); foreach (var line in input) { // rect 49x1 // rotate row y=2 by 34 // rotate column x=44 by 1 if (line.IsRxMatch("rect %dx%d", out var captures)) { var(w, h) = captures.Get <int, int>(); for (var x = 0; x < w; x++) { for (var y = 0; y < h; y++) { screen[x, y] = '#'; } } } else if (line.IsRxMatch("rotate row y=%d by %d", out captures)) { var(row, dx) = captures.Get <int, int>(); screen.ShiftRowRight(row, dx); } else if (line.IsRxMatch("rotate column x=%d by %d", out captures)) { var(col, dy) = captures.Get <int, int>(); screen.ShiftColDown(col, dy); } else { throw new Exception($"Unhandled line '{line}'"); } } return(screen); }
public CharMatrix(CharMatrix orig) : this(modshogunPINVOKE.new_CharMatrix__SWIG_5(CharMatrix.getCPtr(orig)), true) { if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve(); }
internal static HandleRef getCPtr(CharMatrix obj) { return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr); }
protected internal override ICharMatrix GetCharMatrix(string value) { return(CharMatrix.Create(Value.Trim(), GetX(), GetY(), GetWidth(), GetHeight())); }
internal static HandleRef getCPtr(CharMatrix obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; }
public void Test8() { var actual = CharMatrix.Create("!".Pastel(Color.Red), 0, 0, 2, 1); Assert.AreEqual(BeginRed + '!', actual[0, 0]); Assert.AreEqual(End + ' ', actual[1, 0]); }