My solution in Rust
fn part_a(mut input: Vec<u32>) -> u32 { input[1] = 12; input[2] = 2; let mut i: usize = 0; while i < input.len() { if i % 4 == 0 { let opcode = input[i]; if opcode == 99 { break; } let index_1 = input[i + 1] as usize; let index_2 = input[i + 2] as usize; let index_3 = input[i + 3] as usize; if opcode == 1 { input[index_3] = input[index_1] + input[index_2]; } else if opcode == 2 { input[index_3] = input[index_1] * input[index_2]; } } i = i + 1; } input[0] } fn part_b(input: Vec<u32>) -> u32 { let mut i = 0; let mut j = 0; while i < 100 { let mut input = input.clone(); if exec_intcode_program(input, i, j) == 19690720 { return 100 * i + j; break; } if j == 99 { i = i + 1; j = 0; } j = j + 1; } 0 } fn exec_intcode_program(input: Vec<u32>, addl_inp_1: u32, addl_inp_2: u32) -> u32 { let mut input = input.clone(); input[1] = addl_inp_1; input[2] = addl_inp_2; let mut i: usize = 0; while i < input.len() { if i % 4 == 0 { let opcode = input[i]; if opcode == 99 { break; } let index_1 = input[i + 1] as usize; let index_2 = input[i + 2] as usize; let index_3 = input[i + 3] as usize; if opcode == 1 { input[index_3] = input[index_1] + input[index_2]; } else if opcode == 2 { input[index_3] = input[index_1] * input[index_2]; } } i = i + 1; } input[0] }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My solution in Rust