コード例 #1
0
        public async Task <string> SolvePart1Async(Stream input)
        {
            var line = await input.ReadLineAsync();

            var registers = line.Split(',').Select(x => long.Parse(x)).ToArray();

            _program.Init(registers);
            var outputChannel = Channel.CreateUnbounded <long>();
            await _program.RunAsync(await 1.ToChannelAsync(), outputChannel);

            return((await outputChannel.Reader.ReadAllAsync().LastAsync()).ToString());
        }
コード例 #2
0
        public async Task <string> SolvePart1Async(Stream input)
        {
            var line = await input.ReadLineAsync();

            var registers = line.Split(',').Select(x => long.Parse(x)).ToArray();

            _intcodeProgram.Init(registers);

            var outputChannel = Channel.CreateUnbounded <long>();
            var inputChannel  = Channel.CreateUnbounded <long>();
            await _intcodeProgram.RunAsync(inputChannel, outputChannel);

            return((await GetAlignmentParametersAsync(outputChannel)).ToString());
        }
コード例 #3
0
        public async Task <string> SolvePart2Async(Stream input)
        {
            var line = await input.ReadLineAsync();

            var registers = line.Split(',').Select(x => long.Parse(x)).ToArray();

            _intcodeProgram.Init(registers);

            var panels = await GetPaintedPanelsAsync(_intcodeProgram, PaintedColor.White);

            var s = new StringBuilder();

            for (int j = panels.Keys.Max(c => c.y); j > panels.Keys.Min(c => c.y) - 1; j--)
            {
                for (int i = panels.Keys.Min(c => c.x); i < panels.Keys.Max(c => c.x) + 1; i++)
                {
                    s.Append(panels.ContainsKey((i, j))
                        ? panels[(i, j)] == PaintedColor.White ? "#" : " "
コード例 #4
0
        public async Task <string> SolvePart1Async(Stream input)
        {
            var line = await input.ReadLineAsync();

            var registers = line.Split(',').Select(x => long.Parse(x)).ToArray();

            var map = new Dictionary <(long x, long y), long>();

            for (int x = 0; x < 50; x++)
            {
                for (int y = 0; y < 50; y++)
                {
                    var outputChannel = Channel.CreateUnbounded <long>();
                    var inputChannel  = Channel.CreateUnbounded <long>();

                    _intcodeProgram.Init(registers.ToArray()); // copy

                    await inputChannel.Writer.WriteAsync(x);

                    await inputChannel.Writer.WriteAsync(y);

                    await _intcodeProgram.RunAsync(inputChannel, outputChannel);

                    map[(x, y)] = await outputChannel.Reader.ReadAsync();