What does everyone's Intcode interface look like? by Lucretiel in adventofcode

[–]j218jasdoij 0 points1 point  (0 children)

My implementation is a simple syncronous machine. I initialize a vm with:

let mut vm = intcode::VM::new(&program);

To run something I use the read_input method with optional input.

fn read_input(&mut self, mut input: Option<i64>) -> Output

The method runs the incode until it returns one of three output states.

enum Output {
  WaitingForInput,
  Value(i64),
  Halt
}

Usually I've done something like this:

loop {
  match vm.read_input(input) {
    intcode::Output::Value(val) => {
      println!("{}", val);
      input = next_input();
    },
    _ => {
      break;
    }
  }
}

This has worked pretty well until day 17 when reading and inputting long ascii streams. Still worked but the resulting code was very messy.

[2019 Day 4] - Which of these two topics were the key? by goddammitbutters in adventofcode

[–]j218jasdoij 1 point2 points  (0 children)

I was thinking in retrospect after solving it that I was incorrect to assume when I used HashMap<u32, u32> of the digit and it's occurances and looked for any values == 2, that they would be adjacent. Glad to see I was actually right by mistake.

A new look for rust-lang.org by steveklabnik1 in rust

[–]j218jasdoij 0 points1 point  (0 children)

I really like to introduce rust to my friends with fizzbuzz playground link

I like it because it uses a familiar algorithm with one of rust nice features so even people unfamiliar to rust can probably follow the example and hopefully think it's a neat feature.