1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
use std::io;
use std::io::BufRead;
use crate::device::*;
#[allow(dead_code)]
fn optimise(mut instrs: Vec<Instr>, ip_reg: usize) -> Vec<Instr> {
for i in 0..instrs.len() {
instrs[i].inline_reg(ip_reg, Oper::Num(i));
}
instrs
}
#[allow(dead_code)]
fn run_program(instrs: &[Instr], r0: usize, ip_reg: usize) -> usize {
let mut m = Machine { regs: [r0, 0, 0, 0, 0, 0] };
m.exec_program(&instrs, ip_reg);
m.regs[0]
}
fn divisor_sum(n: i64) -> i64 {
(1..n+1).filter(|&d| n % d == 0).sum()
}
fn main_alt() -> (String, String) {
(divisor_sum(948).to_string(), divisor_sum(10551348).to_string())
}
pub fn main<T: BufRead>(_reader: T) -> io::Result<(String, String)> {
Ok(main_alt())
/* let (ip_reg, instrs) = parse_program(reader)?;
// for instr in &instrs { println!("{}", instr); }
let instrs = optimise(instrs, ip_reg);
for instr in &instrs { println!("{}", instr); }
// let part1 = run_program(&instrs, 0);
let part2 = run_program(&instrs, 1, ip_reg);
// Ok((part1.to_string(), part2.to_string()))
Ok((String::new(), String::new())) */
}
|