Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let testinput = vec![1,9,10,3,2,3,11,0,99,30,40,50];
- runp1(testinput) ;
- }
- fn runp1(input: Vec<i16>) {
- let mut instruction_list = input.clone();
- let mut index = 0;
- loop {
- let curr_ins = instruction_list[index];
- //println!("curr index: {} ", index );
- //println!("curr list: {:?} ", instruction_list );
- match curr_ins {
- 1 => {
- let x = instruction_list[ (instruction_list[index+1] as usize) ];
- let y = instruction_list[ (instruction_list[index+2] as usize) ];
- let dest = instruction_list[ (instruction_list[index+3] as usize) ];
- instruction_list[dest as usize] = x+y;
- index+=4;
- }
- 2 => {
- let x = instruction_list[ (instruction_list[index+1] as usize) ];
- let y = instruction_list[ (instruction_list[index+2] as usize) ];
- let dest = instruction_list[ (instruction_list[index+3] as usize) ];
- instruction_list[dest as usize] = x*y;
- index+=4;
- }
- 99 => {
- break;
- }
- _ => {
- println!("this shouldnt happen ...");
- }
- }
- }
- println!("{:?}", instruction_list);
- }
- /*
- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn test_run() {
- let input = [1,9,10,3,2,3,11,0,99,30,40,50];
- runp1
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement