day 18. Simply magical. template struct ins_t { F op; int64_t* to, * from; };template auto make_duet(string_view input, const F& snd, const F& rcv){ static const F set = +[](int64_t* to, int64_t* from, int pc){ *to = *from; return pc + 1; }, add = +[](int64_t* to, int64_t* from, int pc){ *to += *from; return pc + 1; }, mul = +[](int64_t* to, int64_t* from, int pc){ *to *= *from; return pc + 1; }, mod = +[](int64_t* to, int64_t* from, int pc){ *to %= *from; return pc + 1; }, jgz = +[](int64_t* to, int64_t* from, int pc){ return *to > 0 ? pc + (int)*from : pc + 1; }; unordered_map data; int cur_data = 0; vector prog; for (string_view line : input | split(by_line)){ switch (line[1]){ break; case 'n': { auto [x, _] = parse_n(line.substr(4), by_word); prog.push_back({snd, &data[0], isalpha(x[0]) ? &data[x[0]] : &(data[cur_data++] = to(x))}); } break; case 'e': { auto [x, y, _] = parse_n(line.substr(4), by_word); prog.push_back({set, &data[x[0]], isalpha(y[0]) ? &data[y[0]] : &(data[cur_data++] = to(y))}); } break; case 'd': { auto [x, y, _] = parse_n(line.substr(4), by_word); prog.push_back({add, &data[x[0]], isalpha(y[0]) ? &data[y[0]] : &(data[cur_data++] = to(y))}); } break; case 'u': { auto [x, y, _] = parse_n(line.substr(4), by_word); prog.push_back({mul, &data[x[0]], isalpha(y[0]) ? &data[y[0]] : &(data[cur_data++] = to(y))}); } break; case 'o': { auto [x, y, _] = parse_n(line.substr(4), by_word); prog.push_back({mod, &data[x[0]], isalpha(y[0]) ? &data[y[0]] : &(data[cur_data++] = to(y))}); } break; case 'c': { auto [x, _] = parse_n(line.substr(4), by_word); prog.push_back({rcv, &data[0], isalpha(x[0]) ? &data[x[0]] : &(data[cur_data++] = to(x))}); } break; case 'g': { auto [x, y, _] = parse_n(line.substr(4), by_word); prog.push_back({jgz, isalpha(x[0]) ? &data[x[0]] : &(data[cur_data++] = to(x)), isalpha(y[0]) ? &data[y[0]] : &(data[cur_data++] = to(y))}); } } } return pair(move(data), move(prog));}void duet1(string_view input){ auto [data, prog] = make_duet(input, +[](int64_t* to, int64_t* from, int pc){ *to = *from; return pc + 1; },+[](int64_t* to, int64_t* from, int pc){ static bool b = false; if (*from && !b) return cout = prog[0].size()){ status[oldcur] = dead; cur = !oldcur; } else pc[oldcur] = updatedpc; } cout