Created
February 3, 2019 08:28
-
-
Save takuma-saito/0f765924774d9373456dadb11d7dfd79 to your computer and use it in GitHub Desktop.
q-puzzle.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 9 パズルビームサーチの擬似コード | |
queue.push({s: {7, 8, 0, 1, 2, 3, 4, 5, 6}, r: 2}) | |
while (not queue.empty()) | |
pqueue = PriorityQueue.new | |
while (q = queue.pop()) | |
[[-1, 0], [0, 1], [1, 0], [0, -1]].each do |d| | |
newState = state(q, d) | |
pqueue.push(newState) | |
pqueue.pop() if pqueue.size > K | |
end | |
end | |
while (q = pqueue.pop()) | |
queue.push(q) # 逆順にしておく | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment