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()); }
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()); }
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();