day_17
Types
pub type Computer {
Computer(
a: Int,
b: Int,
c: Int,
program: List(#(Int, Int)),
output: List(Int),
pointer: Int,
)
}
Constructors
-
Computer( a: Int, b: Int, c: Int, program: List(#(Int, Int)), output: List(Int), pointer: Int, )
Functions
pub fn adv(state: Computer) -> Computer
The adv
instruction (opcode 0
) performs division.
The numerator is the value in the A
register.
The denominator is found by raising 2
to the power of the instruction’s combo operand. (So, an operand of 2
would divide A
by 4
(2^2
); an operand of 5
would divide A
by 2^B
.)
The result of the division operation is truncated to an integer and then written to the A register.
pub fn bdv(state: Computer) -> Computer
The bdv instruction (opcode 6) works exactly like the adv instruction except that the result is stored in the B register. (The numerator is still read from the A register.)
pub fn bst(state: Computer) -> Computer
The bst instruction (opcode 2) calculates the value of its combo operand modulo 8 (thereby keeping only its lowest 3 bits), then writes that value to the B register.
pub fn bxc(state: Computer) -> Computer
The bxc instruction (opcode 4) calculates the bitwise XOR of register B and register C, then stores the result in register B. (For legacy reasons, this instruction reads an operand but ignores it.)
pub fn bxl(state: Computer) -> Computer
The bxl instruction (opcode 1) calculates the bitwise XOR of register B and the instruction’s literal operand, then stores the result in register B.
pub fn cdv(state: Computer) -> Computer
The cdv instruction (opcode 7) works exactly like the adv instruction except that the result is stored in the C register. (The numerator is still read from the A register.)
pub fn debug_diff(
new_state: Computer,
old_state: Computer,
) -> Computer
pub fn debug_instruction(
result: Int,
next_pointer: Int,
target: String,
) -> String
pub fn debug_opcode(opcode: Int) -> String
pub fn debug_state(state: Computer) -> Computer
pub fn evaluate_program(
state: Computer,
expected_output: List(Int),
) -> Result(Computer, Computer)
pub fn execute_instruction(state: Computer) -> Computer
pub fn execute_program(state: Computer) -> Computer
pub fn format_output(state: Computer) -> String
pub fn get_current_instruction(
state: Computer,
) -> #(Int, Int, Int)
pub fn get_numbers_with_prefix(prefix: Int) -> Yielder(Int)
pub fn get_raw_program(computer: Computer) -> List(Int)
pub fn jnz(state: Computer) -> Computer
The jnz instruction (opcode 3) does nothing if the A register is 0. However, if the A register is not zero, it jumps by setting the instruction pointer to the value of its literal operand; if this instruction jumps, the instruction pointer is not increased by 2 after this instruction.
pub fn list_matches(list1: List(Int), list2: List(Int)) -> Bool
Returns true if either list is a prefix of the other list.
pub fn list_matches_from_end(
list1: List(Int),
list2: List(Int),
) -> Bool
Returns true if the first list is a suffix of the second list.
pub fn list_matches_up_to(
list1: List(Int),
list2: List(Int),
) -> Bool
Returns true if the first list is a prefix of the second list.
pub fn out(state: Computer) -> Computer
The out instruction (opcode 5) calculates the value of its combo operand modulo 8, then outputs that value. (If a program outputs multiple values, they are separated by commas.)
pub fn parse_input(input: List(String)) -> Computer
pub fn part_1_with_override(a: Int) -> Nil
pub fn solve_part_2(
state: Computer,
target_output: List(Int),
base8_prefix: Int,
use_last_n: Int,
) -> List(Int)
pub fn yield_until(max: Int) -> Yielder(Int)