Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.27 KB | None | 0 0
  1. public static void day13()
  2.         {
  3.             Dictionary<int, Dictionary<int,int>> map = new Dictionary<int, Dictionary<int, int>>();
  4.             Func<int, int, int> get = (xp, yp) =>
  5.             {
  6.                 if( !map.ContainsKey(yp)) return 0;
  7.                 if( !map[yp].ContainsKey(xp)) return 0;
  8.  
  9.                 return map[yp][xp];
  10.             };
  11.  
  12.             int blocks = 0;
  13.  
  14.             int currentoutput = 0;
  15.  
  16.             int lastballx = int.MinValue;
  17.             int lastpaddlex = int.MinValue;
  18.             int wait = 1;
  19.             Action<int, int, int> set = (xp, yp, c) =>
  20.             {
  21.                 if( !map.ContainsKey(yp) ) map.Add(yp,  new Dictionary<int, int>());
  22.                 map[yp][xp] = c;
  23.  
  24.                 Console.SetCursorPosition(xp, yp);
  25.                 if( c == 0 ) Console.Write( " ");
  26.                 if( c == 1 ) Console.Write("#");
  27.                 if( c == 2 )
  28.                 {
  29.                     Console.Write("=");
  30.                     blocks++;
  31.                 }
  32.                 if( c == 3 )
  33.                 {lastpaddlex = xp;
  34.                     Console.Write("-");
  35.                 }
  36.                 if( c == 4 )
  37.                 {
  38.                     lastballx =xp;
  39.  
  40.                     Console.Write("o");
  41.                 }
  42.             };
  43.  
  44.             runicomputertestharness();
  45.  
  46.             string data = "";
  47.             System.IO.File.ReadAllLines(@"G:\Workspace\AdventOfCode2019\Input\day13.txt").ToList().ForEach((s) =>
  48.             {
  49.                 data += s;
  50.             });
  51.  
  52.             int ans = int.MinValue;
  53.  
  54.             var computer = new icomputer(data.Split(',').Select(datum => BigInteger.Parse(datum)).ToList());
  55.  
  56.             int n = 0;
  57.             int x = 0;
  58.             int y = 0;
  59.             int score = 0;
  60.  
  61.  
  62.             computer.putOutput = (o) =>
  63.             {
  64.                 if( n == 0 ) x = (int)o;
  65.                 if( n == 1 ) y = (int)o;
  66.                 if( n == 2 )
  67.                 {
  68.                     if( x == -1 && y == 0 )
  69.                     {
  70.                         score = (int)o;
  71.                         if( score > 0 )
  72.                         {
  73.                             ;
  74.                         }
  75.                     }
  76.                     else
  77.                     {
  78.                         set(x, y, (int)o);
  79.  
  80.                     }
  81.                 }
  82.  
  83.                 n++;
  84.                 if( n >= 3 ) n = 0;
  85.             };
  86.  
  87.             computer.getInput = () =>
  88.             {
  89.                 if (Console.KeyAvailable)
  90.                 {
  91.                     Console.WriteLine(score);
  92.                     ;
  93.                 }
  94.                 if ( lastpaddlex < lastballx ) return 1;
  95.                 if (lastpaddlex > lastballx) return -1;
  96.                 return 0;
  97.                 return currentoutput;
  98.             };
  99.  
  100.             while( true )
  101.             computer.Run();
  102.  
  103.             int answer = 0;
  104.             foreach( var r in map )
  105.             {
  106.                 foreach( var c in r.Value )
  107.                 {
  108.                     if( c.Value == 2 ) answer++;
  109.                 }
  110.             }
  111.            
  112.  
  113.             Console.WriteLine("==answer==");
  114.             Console.WriteLine(answer);
  115.             Console.ReadKey(true);
  116.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement