adventofcode/2015/day07/problem

100 lines
3.2 KiB
Plaintext
Raw Permalink Normal View History

2018-03-15 16:24:23 +00:00
Advent of Code
2016-12-16 22:21:15 +00:00
--- Day 7: Some Assembly Required ---
2018-03-15 16:24:23 +00:00
This year, Santa brought little Bobby Tables a set of wires and bitwise
logic gates! Unfortunately, little Bobby is a little under the recommended
age range, and he needs help assembling the circuit.
2016-12-16 22:21:15 +00:00
2018-03-15 16:24:23 +00:00
Each wire has an identifier (some lowercase letters) and can carry a 16-bit
signal (a number from 0 to 65535). A signal is provided to each wire by a
gate, another wire, or some specific value. Each wire can only get a signal
from one source, but can provide its signal to multiple destinations. A gate
provides no signal until all of its inputs have a signal.
2016-12-16 22:21:15 +00:00
2018-03-15 16:24:23 +00:00
The included instructions booklet describes how to connect the parts
together: x AND y -> z means to connect wires x and y to an AND gate, and
then connect its output to wire z.
2016-12-16 22:21:15 +00:00
For example:
 123 -> x means that the signal 123 is provided to wire x.
2018-03-15 16:24:23 +00:00
 x AND y -> z means that the bitwise AND of wire x and wire y is provided
to wire z.
 p LSHIFT 2 -> q means that the value from wire p is left-shifted by 2
and then provided to wire q.
 NOT e -> f means that the bitwise complement of the value from wire e is
provided to wire f.
Other possible gates include OR (bitwise OR) and RSHIFT (right-shift). If,
for some reason, you'd like to emulate the circuit instead, almost all
programming languages (for example, C, JavaScript, or Python) provide
operators for these gates.
2016-12-16 22:21:15 +00:00
For example, here is a simple circuit:
123 -> x
456 -> y
x AND y -> d
x OR y -> e
x LSHIFT 2 -> f
y RSHIFT 2 -> g
NOT x -> h
NOT y -> i
After it is run, these are the signals on the wires:
d: 72
e: 507
f: 492
g: 114
h: 65412
i: 65079
x: 123
y: 456
2018-03-15 16:24:23 +00:00
In little Bobby's kit's instructions booklet (provided as your puzzle
input), what signal is ultimately provided to wire a?
2016-12-16 22:21:15 +00:00
Your puzzle answer was 16076.
--- Part Two ---
2018-03-15 16:24:23 +00:00
Now, take the signal you got on wire a, override wire b to that signal, and
reset the other wires (including wire a). What new signal is ultimately
provided to wire a?
2016-12-16 22:21:15 +00:00
Your puzzle answer was 2797.
Both parts of this puzzle are complete! They provide two gold stars: **
2018-03-15 16:24:23 +00:00
At this point, you should return to your advent calendar and try another
puzzle.
2016-12-16 22:21:15 +00:00
If you still want to see it, you can get your puzzle input.
References
Visible links
. http://adventofcode.com/
. http://adventofcode.com/about
. http://adventofcode.com/stats
. http://adventofcode.com/leaderboard
. http://adventofcode.com/settings
. http://adventofcode.com/auth/logout
. https://en.wikipedia.org/wiki/Bitwise_operation
. https://en.wikipedia.org/wiki/16-bit
. https://en.wikipedia.org/wiki/Bitwise_operation#AND
. https://en.wikipedia.org/wiki/Logical_shift
. https://en.wikipedia.org/wiki/Bitwise_operation#NOT
. https://en.wikipedia.org/wiki/Bitwise_operation#OR
. https://en.wikipedia.org/wiki/Logical_shift
. https://en.wikipedia.org/wiki/Bitwise_operations_in_C
. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
. https://wiki.python.org/moin/BitwiseOperators
. http://adventofcode.com/
. http://adventofcode.com/day/7/input