Skip to content

java: add solutions for year 2016, day 22 #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2020
Merged

java: add solutions for year 2016, day 22 #115

merged 3 commits into from
Jan 13, 2020

Conversation

saser
Copy link
Owner

@saser saser commented Jan 13, 2020

This puzzle was the kind where I had to actually study the input a bit, instead of just following the instructions. After I did that, the problem became much easier.

For part 2, there are three kinds of nodes:

  1. The empty node, which acts like the "traveller" in this graph.
  2. Non-empty nodes, which the empty node can move to (by moving data from a non-empty node to the empty node, thereby creating a new empty node).
  3. Immovable nodes, which are not viable with any other node (and therefore never will become viable either).
    This makes the grid a kind of graph, and we do not have to actually care about the numbers in the nodes -- but it is based on the assumption that any non-empty node (except for the immovable nodes) will be viable together with the empty node.

For the graph search, this is a simple BFS Dijkstra's algorithm, where the state consists of a tuple of two points: the position of the empty node, and the position of the data that we want to move. Then the empty node moves around, and if the empty node moves to the position of the data, they essentially swap places, moving the data. This is how the data is eventually moved to the node at 0, 0.

@saser saser merged commit 7f9b8f0 into master Jan 13, 2020
@saser saser deleted the java/2016/22 branch January 13, 2020 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant