Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void day13()
- {
- Dictionary<int, Dictionary<int,int>> map = new Dictionary<int, Dictionary<int, int>>();
- Func<int, int, int> get = (xp, yp) =>
- {
- if( !map.ContainsKey(yp)) return 0;
- if( !map[yp].ContainsKey(xp)) return 0;
- return map[yp][xp];
- };
- int blocks = 0;
- int currentoutput = 0;
- int lastballx = int.MinValue;
- int lastpaddlex = int.MinValue;
- int wait = 1;
- Action<int, int, int> set = (xp, yp, c) =>
- {
- if( !map.ContainsKey(yp) ) map.Add(yp, new Dictionary<int, int>());
- map[yp][xp] = c;
- Console.SetCursorPosition(xp, yp);
- if( c == 0 ) Console.Write( " ");
- if( c == 1 ) Console.Write("#");
- if( c == 2 )
- {
- Console.Write("=");
- blocks++;
- }
- if( c == 3 )
- {lastpaddlex = xp;
- Console.Write("-");
- }
- if( c == 4 )
- {
- lastballx =xp;
- Console.Write("o");
- }
- };
- runicomputertestharness();
- string data = "";
- System.IO.File.ReadAllLines(@"G:\Workspace\AdventOfCode2019\Input\day13.txt").ToList().ForEach((s) =>
- {
- data += s;
- });
- int ans = int.MinValue;
- var computer = new icomputer(data.Split(',').Select(datum => BigInteger.Parse(datum)).ToList());
- int n = 0;
- int x = 0;
- int y = 0;
- int score = 0;
- computer.putOutput = (o) =>
- {
- if( n == 0 ) x = (int)o;
- if( n == 1 ) y = (int)o;
- if( n == 2 )
- {
- if( x == -1 && y == 0 )
- {
- score = (int)o;
- if( score > 0 )
- {
- ;
- }
- }
- else
- {
- set(x, y, (int)o);
- }
- }
- n++;
- if( n >= 3 ) n = 0;
- };
- computer.getInput = () =>
- {
- if (Console.KeyAvailable)
- {
- Console.WriteLine(score);
- ;
- }
- if ( lastpaddlex < lastballx ) return 1;
- if (lastpaddlex > lastballx) return -1;
- return 0;
- return currentoutput;
- };
- while( true )
- computer.Run();
- int answer = 0;
- foreach( var r in map )
- {
- foreach( var c in r.Value )
- {
- if( c.Value == 2 ) answer++;
- }
- }
- Console.WriteLine("==answer==");
- Console.WriteLine(answer);
- Console.ReadKey(true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement