let lines = ref [ in
let chan = open_in path in
try
; !lines
close_in chan;
rev !lines
and packet =
and packet_type =
| Sum
| Product
| Minimum
| Maximum
| Literal
| Greater
| Lesser
| Equal
"0000"
"0001"
"0010"
"0011"
"0100"
"0101"
"0110"
"0111"
"1000"
"1001"
"1010"
"1011"
"1100"
"1101"
"1110"
"1111"
assert false
Sum
Product
Minimum
Maximum
Literal
Greater
Lesser
Equal
assert false
let buffer = create in
add_string buffer in
iter expand_digit hex;
contents buffer
let data = hexadecimal_to_binary input in
let stop = start + length in
if position < stop
then parse
else acc
in parse init start
let value = binary_to_decimal ~init:value 4 in
let next_pos = position + 5 in
if data. == '1'
then aux next_pos value
else
in aux start 0
match n
let = parse_packet position
in aux next
in aux [
let = parse_bytes position 3 in
let = parse_bytes next 3 in
let = match packet_t let = parse_literal next in
let = parse_subpacket next in
in
let = parse_bytes start 1 in
match length_t parse_n_bytes_of_subpackets next
parse_n_subpackets next
assert false
let = parse_bytes start 15 in
let limit = count + next in
if position >= limit
then
else let = parse_packet position
in aux next
in aux [ next
in
let = parse_packet 0 in packet
match packet.body packet.version
packet.version +
match packet.packet_type
fold_left_subpackets packet
fold_left_subpackets packet
fold_left_subpackets min packet
fold_left_subpackets max packet
subpacket_compare packet
subpacket_compare packet
subpacket_compare packet
packet |> subpackets |> map evaluate_packet
let subs = evaluate_subpackets packet
in fold_left f
match evaluate_subpackets packet if f a b then 1 else 0
assert false
match packet.body x
assert false
let part1 = packet_version_sum
let part2 = evaluate_packet
let packet = read_lines argv. |> hd |> parse
let ( = printf "Part 1: %d\n"
let ( = printf "Part 2: %d\n"