SlideShare a Scribd company logo
Fix this code so that it will run with proper answers, please dont use chatgpt and please test your
code before submitting:
import sys
import heapq
import copy
class PriorityQueue():
def __init__(self):
self.thisQueue = []
def push(self, thisNode):
heapq.heappush(self.thisQueue, (thisNode.val, -thisNode.id, thisNode))
def pop(self):
return heapq.heappop(self.thisQueue)[2]
def isEmpty(self):
return len(self.thisQueue) == 0
def length(self):
return len(self.thisQueue)
class Set():
def __init__(self):
self.thisSet = set()
def add(self, entry):
if entry is not None:
self.thisSet.add(entry.__hash__())
def length(self):
return len(self.thisSet)
def isMember(self, query):
return query.__hash__() in self.thisSet
class Node():
def __init__(self, val, startstate, endstate, depth):
global nodeid
self.id = nodeid
nodeid += 1
self.val = val
self.state = startstate
self.endstate = endstate
self.depth = depth
def __str__(self):
return 'Node: id=%d val=%d' % (self.id, self.val)
def expand(current_node, closedlist, goal_state):
closedlist.add(current_node.state)
successors = []
up_child = current_node.state.up()
down_child = current_node.state.down()
right_child = current_node.state.right()
left_child = current_node.state.left()
children = [left_child, right_child, up_child, down_child]
for child in children:
if child is not None and not closedlist.isMember(child):
s = Node(0, child, None, current_node.depth + 1)
s.parent_node = current_node
if child == left_child:
s.action = "left"
elif child == right_child:
s.action = "right"
elif child == up_child:
s.action = "up"
elif child == down_child:
s.action = "down"
successors.append(s)
return successors
def h0(currenttiles, stiles):
misplaced = 0
for i in range(len(stiles)):
for j in range(len(currenttiles)):
if stiles[i][j] != currenttiles[i][j]:
misplaced += 1
return misplaced
def manhattan(currenttiles, stiles):
total = 0
for i in range(len(stiles)):
for j in range(len(currenttiles)):
if stiles[i][j] != currenttiles[i][j]:
y = stiles[i][j]
a = i
b = j
for k in range(len(stiles)):
for l in range(len(stiles)):
if currenttiles[k][l] == y:
d = k
e = l
count = (abs(d - a) + abs(e - b))
total += count
return total
class State():
def __init__(self):
self.xpos = 0
self.ypos = 0
self.tiles = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
def left(self):
if self.ypos == 0:
return None
s = self.copy()
s.tiles[s.xpos][s.ypos] = s.tiles[s.xpos][s.ypos - 1]
s.ypos -= 1
s.tiles[s.xpos][s.ypos] = 0
return s
def right(self):
if self.ypos == 2:
return None
s = self.copy()
s.tiles[s.xpos][s.ypos] = s.tiles[s.xpos][s.ypos + 1]
s.ypos += 1
s.tiles[s.xpos][s.ypos] = 0
return s
def up(self):
if self.xpos == 0:
return None
s = self.copy()
s.tiles[s.xpos][s.ypos] = s.tiles[s.xpos - 1][s.ypos]
s.xpos -= 1
s.tiles[s.xpos][s.ypos] = 0
return s
def down(self):
if self.xpos == 2:
return None
s = self.copy()
s.tiles[s.xpos][s.ypos] = s.tiles[s.xpos + 1][s.ypos]
s.xpos += 1
s.tiles[s.xpos][s.ypos] = 0
return s
def __hash__(self):
return (tuple(self.tiles[0]), tuple(self.tiles[1]), tuple(self.tiles[2]))
def __str__(self):
return '%d %d %dn%d %d %dn%d %d %dn' % (
self.tiles[0][0], self.tiles[0][1], self.tiles[0][2],
self.tiles[1][0], self.tiles[1][1], self.tiles[1][2],
self.tiles[2][0], self.tiles[2][1], self.tiles[2][2])
def copy(self):
s = State()
s.xpos = self.xpos
s.ypos = self.ypos
s.tiles = [row[:] for row in self.tiles]
return s
def astar(initial_state, goal_state, closedlist, heuristic_type):
initial_node = Node(0, initial_state, goal_state, 0)
print(initial_node.val)
frontier = PriorityQueue()
frontier.push(initial_node)
V = 0
N = 0
d = 0
while not frontier.isEmpty():
if frontier.length() > N:
N = frontier.length()
current_node = frontier.pop()
V += 1
if current_node.state == goal_state:
d = current_node.depth # Found the solution
return current_node, V, N, d
expanded = expand(current_node, closedlist, goal_state)
for node in expanded:
if heuristic_type == 0:
f_val = h0(node.state.tiles, goal_state.tiles) + node.depth
elif heuristic_type == 1:
f_val = manhattan(node.state.tiles, goal_state.tiles) + node.depth
node.val=f_val
frontier.push(node)
return None, V, N, d
def main():
global nodeid
nodeid = 0
inputs = []
for line in sys.stdin:
inputs += line.split()
array = [
[int(inputs[0]), int(inputs[1]), int(inputs[2])],
[int(inputs[3]), int(inputs[4]), int(inputs[5])],
[int(inputs[6]), int(inputs[7]), int(inputs[8])]
]
goal_state = State()
goal_state.tiles = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
s = State()
current = State()
current.tiles = array
s.tiles = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
print(array)
printMan = manhattan(array, goal_state.tiles)
print("Initial State:")
print(s)
print("Goal State:")
print(goal_state)
print("Manhattan Distance:", printMan)
for heuristic_type in range(2):
closedlist = Set()
nodeid = 0
d, N, V,_ = astar(current, goal_state, closedlist, heuristic_type)
print("nHeuristic", heuristic_type)
print("Nodes Visited/Expanded (V):", V)
print("Maximum Nodes Stored in Memory (N):", N)
print("Depth of Optimal
Solution
(d):", d)
if __name__ == "__main__":
main()
Current output results in a ton of unprecedented values for V, d, and N like 39,423

More Related Content

Similar to Fix this code so that it will run with proper answers, please dont u.pdf

Djangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicDjangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New Relic
New Relic
 
밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI
NAVER Engineering
 
ScalaBlitz
ScalaBlitzScalaBlitz
Implemeting queue in python.pptx
Implemeting queue in python.pptxImplemeting queue in python.pptx
Implemeting queue in python.pptx
KennyDon5
 
goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
  goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf  goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
ANJALIENTERPRISES1
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
Fwdays
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
Jordan Baker
 
Beyond Scala Lens
Beyond Scala LensBeyond Scala Lens
Beyond Scala Lens
Julien Truffaut
 
This assignment is about creating and using heaps. Implement a heap .docx
 This assignment is about creating and using heaps.  Implement a heap .docx This assignment is about creating and using heaps.  Implement a heap .docx
This assignment is about creating and using heaps. Implement a heap .docx
Komlin1
 
Python magicmethods
Python magicmethodsPython magicmethods
Python magicmethods
dreampuf
 
Monadologie
MonadologieMonadologie
Monadologie
league
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
kesav24
 
Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
Emertxe Information Technologies Pvt Ltd
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
Christian Baranowski
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
Adam Lowry
 
Unit test
Unit testUnit test
Unit test
David Xie
 
python within 50 page .ppt
python within 50 page .pptpython within 50 page .ppt
python within 50 page .ppt
sushil155005
 
Object Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonObject Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in Python
Tendayi Mawushe
 
Py Die R E A D M E
Py Die  R E A D M EPy Die  R E A D M E
Py Die R E A D M E
cfministries
 
Python Unit Test
Python Unit TestPython Unit Test
Python Unit Test
David Xie
 

Similar to Fix this code so that it will run with proper answers, please dont u.pdf (20)

Djangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicDjangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New Relic
 
밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI
 
ScalaBlitz
ScalaBlitzScalaBlitz
ScalaBlitz
 
Implemeting queue in python.pptx
Implemeting queue in python.pptxImplemeting queue in python.pptx
Implemeting queue in python.pptx
 
goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
  goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf  goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
 
Beyond Scala Lens
Beyond Scala LensBeyond Scala Lens
Beyond Scala Lens
 
This assignment is about creating and using heaps. Implement a heap .docx
 This assignment is about creating and using heaps.  Implement a heap .docx This assignment is about creating and using heaps.  Implement a heap .docx
This assignment is about creating and using heaps. Implement a heap .docx
 
Python magicmethods
Python magicmethodsPython magicmethods
Python magicmethods
 
Monadologie
MonadologieMonadologie
Monadologie
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
 
Unit test
Unit testUnit test
Unit test
 
python within 50 page .ppt
python within 50 page .pptpython within 50 page .ppt
python within 50 page .ppt
 
Object Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonObject Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in Python
 
Py Die R E A D M E
Py Die  R E A D M EPy Die  R E A D M E
Py Die R E A D M E
 
Python Unit Test
Python Unit TestPython Unit Test
Python Unit Test
 

More from txkev

Critical Thinking 10-7 Dynamic Mobile AccessThere are so many o.pdf
Critical Thinking 10-7 Dynamic Mobile AccessThere are so many o.pdfCritical Thinking 10-7 Dynamic Mobile AccessThere are so many o.pdf
Critical Thinking 10-7 Dynamic Mobile AccessThere are so many o.pdf
txkev
 
Crisis Response Instructions In Module 4, you learned that e.pdf
Crisis Response Instructions     In Module 4, you learned that e.pdfCrisis Response Instructions     In Module 4, you learned that e.pdf
Crisis Response Instructions In Module 4, you learned that e.pdf
txkev
 
Create a Schedule D and schedule 1 for this information, and the cor.pdf
Create a Schedule D and schedule 1 for this information, and the cor.pdfCreate a Schedule D and schedule 1 for this information, and the cor.pdf
Create a Schedule D and schedule 1 for this information, and the cor.pdf
txkev
 
Five areas that financial ratios concentrate on area) liquidity.pdf
Five areas that financial ratios concentrate on area) liquidity.pdfFive areas that financial ratios concentrate on area) liquidity.pdf
Five areas that financial ratios concentrate on area) liquidity.pdf
txkev
 
double Skiplist code below#include iostream#include vector.pdf
double Skiplist code below#include iostream#include vector.pdfdouble Skiplist code below#include iostream#include vector.pdf
double Skiplist code below#include iostream#include vector.pdf
txkev
 
Draw a class diagram for the following scenario The following are t.pdf
Draw a class diagram for the following scenario The following are t.pdfDraw a class diagram for the following scenario The following are t.pdf
Draw a class diagram for the following scenario The following are t.pdf
txkev
 
Discuss the structure of intelligent agents in artificial intelligen.pdf
Discuss the structure of intelligent agents in artificial intelligen.pdfDiscuss the structure of intelligent agents in artificial intelligen.pdf
Discuss the structure of intelligent agents in artificial intelligen.pdf
txkev
 
Consider the following game in which Sally can play T or B and John .pdf
Consider the following game in which Sally can play T or B and John .pdfConsider the following game in which Sally can play T or B and John .pdf
Consider the following game in which Sally can play T or B and John .pdf
txkev
 
Computer NetworksConsider the following scenario involving a.pdf
Computer NetworksConsider the following scenario involving a.pdfComputer NetworksConsider the following scenario involving a.pdf
Computer NetworksConsider the following scenario involving a.pdf
txkev
 
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdfCharacter.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
txkev
 
CNA STB 14 July 2022, STB said � visitor arrival to Singapore are ex.pdf
CNA STB 14 July 2022, STB said � visitor arrival to Singapore are ex.pdfCNA STB 14 July 2022, STB said � visitor arrival to Singapore are ex.pdf
CNA STB 14 July 2022, STB said � visitor arrival to Singapore are ex.pdf
txkev
 
Directions# Caesar Cipher ImplementationYour task in this homew.pdf
Directions# Caesar Cipher ImplementationYour task in this homew.pdfDirections# Caesar Cipher ImplementationYour task in this homew.pdf
Directions# Caesar Cipher ImplementationYour task in this homew.pdf
txkev
 
Describe the leadership of Captain Michael Davidson and second mate .pdf
Describe the leadership of Captain Michael Davidson and second mate .pdfDescribe the leadership of Captain Michael Davidson and second mate .pdf
Describe the leadership of Captain Michael Davidson and second mate .pdf
txkev
 

More from txkev (13)

Critical Thinking 10-7 Dynamic Mobile AccessThere are so many o.pdf
Critical Thinking 10-7 Dynamic Mobile AccessThere are so many o.pdfCritical Thinking 10-7 Dynamic Mobile AccessThere are so many o.pdf
Critical Thinking 10-7 Dynamic Mobile AccessThere are so many o.pdf
 
Crisis Response Instructions In Module 4, you learned that e.pdf
Crisis Response Instructions     In Module 4, you learned that e.pdfCrisis Response Instructions     In Module 4, you learned that e.pdf
Crisis Response Instructions In Module 4, you learned that e.pdf
 
Create a Schedule D and schedule 1 for this information, and the cor.pdf
Create a Schedule D and schedule 1 for this information, and the cor.pdfCreate a Schedule D and schedule 1 for this information, and the cor.pdf
Create a Schedule D and schedule 1 for this information, and the cor.pdf
 
Five areas that financial ratios concentrate on area) liquidity.pdf
Five areas that financial ratios concentrate on area) liquidity.pdfFive areas that financial ratios concentrate on area) liquidity.pdf
Five areas that financial ratios concentrate on area) liquidity.pdf
 
double Skiplist code below#include iostream#include vector.pdf
double Skiplist code below#include iostream#include vector.pdfdouble Skiplist code below#include iostream#include vector.pdf
double Skiplist code below#include iostream#include vector.pdf
 
Draw a class diagram for the following scenario The following are t.pdf
Draw a class diagram for the following scenario The following are t.pdfDraw a class diagram for the following scenario The following are t.pdf
Draw a class diagram for the following scenario The following are t.pdf
 
Discuss the structure of intelligent agents in artificial intelligen.pdf
Discuss the structure of intelligent agents in artificial intelligen.pdfDiscuss the structure of intelligent agents in artificial intelligen.pdf
Discuss the structure of intelligent agents in artificial intelligen.pdf
 
Consider the following game in which Sally can play T or B and John .pdf
Consider the following game in which Sally can play T or B and John .pdfConsider the following game in which Sally can play T or B and John .pdf
Consider the following game in which Sally can play T or B and John .pdf
 
Computer NetworksConsider the following scenario involving a.pdf
Computer NetworksConsider the following scenario involving a.pdfComputer NetworksConsider the following scenario involving a.pdf
Computer NetworksConsider the following scenario involving a.pdf
 
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdfCharacter.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
 
CNA STB 14 July 2022, STB said � visitor arrival to Singapore are ex.pdf
CNA STB 14 July 2022, STB said � visitor arrival to Singapore are ex.pdfCNA STB 14 July 2022, STB said � visitor arrival to Singapore are ex.pdf
CNA STB 14 July 2022, STB said � visitor arrival to Singapore are ex.pdf
 
Directions# Caesar Cipher ImplementationYour task in this homew.pdf
Directions# Caesar Cipher ImplementationYour task in this homew.pdfDirections# Caesar Cipher ImplementationYour task in this homew.pdf
Directions# Caesar Cipher ImplementationYour task in this homew.pdf
 
Describe the leadership of Captain Michael Davidson and second mate .pdf
Describe the leadership of Captain Michael Davidson and second mate .pdfDescribe the leadership of Captain Michael Davidson and second mate .pdf
Describe the leadership of Captain Michael Davidson and second mate .pdf
 

Recently uploaded

Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 

Recently uploaded (20)

Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 

Fix this code so that it will run with proper answers, please dont u.pdf

  • 1. Fix this code so that it will run with proper answers, please dont use chatgpt and please test your code before submitting: import sys import heapq import copy class PriorityQueue(): def __init__(self): self.thisQueue = [] def push(self, thisNode): heapq.heappush(self.thisQueue, (thisNode.val, -thisNode.id, thisNode)) def pop(self): return heapq.heappop(self.thisQueue)[2] def isEmpty(self): return len(self.thisQueue) == 0 def length(self): return len(self.thisQueue) class Set(): def __init__(self): self.thisSet = set() def add(self, entry): if entry is not None: self.thisSet.add(entry.__hash__()) def length(self): return len(self.thisSet) def isMember(self, query): return query.__hash__() in self.thisSet class Node(): def __init__(self, val, startstate, endstate, depth): global nodeid self.id = nodeid nodeid += 1 self.val = val self.state = startstate self.endstate = endstate self.depth = depth
  • 2. def __str__(self): return 'Node: id=%d val=%d' % (self.id, self.val) def expand(current_node, closedlist, goal_state): closedlist.add(current_node.state) successors = [] up_child = current_node.state.up() down_child = current_node.state.down() right_child = current_node.state.right() left_child = current_node.state.left() children = [left_child, right_child, up_child, down_child] for child in children: if child is not None and not closedlist.isMember(child): s = Node(0, child, None, current_node.depth + 1) s.parent_node = current_node if child == left_child: s.action = "left" elif child == right_child: s.action = "right" elif child == up_child: s.action = "up" elif child == down_child: s.action = "down" successors.append(s) return successors def h0(currenttiles, stiles): misplaced = 0 for i in range(len(stiles)): for j in range(len(currenttiles)): if stiles[i][j] != currenttiles[i][j]: misplaced += 1 return misplaced def manhattan(currenttiles, stiles): total = 0 for i in range(len(stiles)): for j in range(len(currenttiles)): if stiles[i][j] != currenttiles[i][j]:
  • 3. y = stiles[i][j] a = i b = j for k in range(len(stiles)): for l in range(len(stiles)): if currenttiles[k][l] == y: d = k e = l count = (abs(d - a) + abs(e - b)) total += count return total class State(): def __init__(self): self.xpos = 0 self.ypos = 0 self.tiles = [[0, 1, 2], [3, 4, 5], [6, 7, 8]] def left(self): if self.ypos == 0: return None s = self.copy() s.tiles[s.xpos][s.ypos] = s.tiles[s.xpos][s.ypos - 1] s.ypos -= 1 s.tiles[s.xpos][s.ypos] = 0 return s def right(self): if self.ypos == 2: return None s = self.copy() s.tiles[s.xpos][s.ypos] = s.tiles[s.xpos][s.ypos + 1] s.ypos += 1 s.tiles[s.xpos][s.ypos] = 0 return s def up(self): if self.xpos == 0: return None s = self.copy()
  • 4. s.tiles[s.xpos][s.ypos] = s.tiles[s.xpos - 1][s.ypos] s.xpos -= 1 s.tiles[s.xpos][s.ypos] = 0 return s def down(self): if self.xpos == 2: return None s = self.copy() s.tiles[s.xpos][s.ypos] = s.tiles[s.xpos + 1][s.ypos] s.xpos += 1 s.tiles[s.xpos][s.ypos] = 0 return s def __hash__(self): return (tuple(self.tiles[0]), tuple(self.tiles[1]), tuple(self.tiles[2])) def __str__(self): return '%d %d %dn%d %d %dn%d %d %dn' % ( self.tiles[0][0], self.tiles[0][1], self.tiles[0][2], self.tiles[1][0], self.tiles[1][1], self.tiles[1][2], self.tiles[2][0], self.tiles[2][1], self.tiles[2][2]) def copy(self): s = State() s.xpos = self.xpos s.ypos = self.ypos s.tiles = [row[:] for row in self.tiles] return s def astar(initial_state, goal_state, closedlist, heuristic_type): initial_node = Node(0, initial_state, goal_state, 0) print(initial_node.val) frontier = PriorityQueue() frontier.push(initial_node) V = 0 N = 0 d = 0 while not frontier.isEmpty(): if frontier.length() > N: N = frontier.length()
  • 5. current_node = frontier.pop() V += 1 if current_node.state == goal_state: d = current_node.depth # Found the solution return current_node, V, N, d expanded = expand(current_node, closedlist, goal_state) for node in expanded: if heuristic_type == 0: f_val = h0(node.state.tiles, goal_state.tiles) + node.depth elif heuristic_type == 1: f_val = manhattan(node.state.tiles, goal_state.tiles) + node.depth node.val=f_val frontier.push(node) return None, V, N, d def main(): global nodeid nodeid = 0 inputs = [] for line in sys.stdin: inputs += line.split() array = [ [int(inputs[0]), int(inputs[1]), int(inputs[2])], [int(inputs[3]), int(inputs[4]), int(inputs[5])], [int(inputs[6]), int(inputs[7]), int(inputs[8])] ] goal_state = State() goal_state.tiles = [[0, 1, 2], [3, 4, 5], [6, 7, 8]] s = State() current = State() current.tiles = array s.tiles = [[0, 1, 2], [3, 4, 5], [6, 7, 8]] print(array) printMan = manhattan(array, goal_state.tiles) print("Initial State:")
  • 6. print(s) print("Goal State:") print(goal_state) print("Manhattan Distance:", printMan) for heuristic_type in range(2): closedlist = Set() nodeid = 0 d, N, V,_ = astar(current, goal_state, closedlist, heuristic_type) print("nHeuristic", heuristic_type) print("Nodes Visited/Expanded (V):", V) print("Maximum Nodes Stored in Memory (N):", N) print("Depth of Optimal Solution (d):", d) if __name__ == "__main__": main() Current output results in a ton of unprecedented values for V, d, and N like 39,423