Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Building Blocks Your twin and you are under an experiment where the amount of thinking similarities you two have is being observed. As per the
Building Blocks
Your twin and you are under an experiment where the amount of thinking similarities you two have is being observed. As per the experiment, you are given the same number of building blocks of different colors and are told to make a building using those blocks in two different rooms.
After the buildings are finished, the observers check whether the two buildings are the same based on the block colors. Now, you are the tech guy of that team and you are instructed to write a program that will output Similar or Not Similar given the two buildings. For fun, you decided to represent those buildings as a linked list!
NB: Red means a red block
Blue means a blue block
Yellow means a yellow block
Green means a green block.
Sample Input
Sample Output
building
RedGreenYellowRedBlueGreenNone
building
RedGreenYellowRedBlueGreenNone
Similar
building
RedGreenYellowRedYellowGreenNone
building
RedGreenYellowRedBlueGreenNone
Not Similar
building
RedGreenYellowRedBlueGreenNone
building
RedGreenYellowRedBlueGreenBlueNone
Not Similar You must Run this cell for your driver code to execute successfully #Run this cell
class Node:
def initselfelem,next None:
self.elem,self.next elem,next
def createListarr:
head Nodearr
tail head
for i in rangelenarr:
newNode Nodearri
tail.next newNode
tail newNode
return head
def printLinkedListhead:
temp head
while temp None:
if temp.next None:
printtempelem, end
else:
printtempelem
temp temp.next
print Driver code:
def lengthhead:
temp, count head,
while temp None:
count
temp temp.next
return count
def checksimilarbuilding building:
#TO DO
printTest Case
building createListnparrayRed 'Green', 'Yellow', 'Red', 'Blue', 'Green'
building createListnparrayRed 'Green', 'Yellow', 'Red', 'Blue', 'Green'
printBuilding : end
printLinkedListbuilding
printBuilding : end
printLinkedListbuilding
returnedvalue checksimilarbuilding building
printreturnedvalue #This should print 'Similar'
unittest.outputtestreturnedvalue, 'Similar'
print
printTest Case
building createListnparrayRed 'Green', 'Yellow', 'Red', 'Yellow', 'Green'
building createListnparrayRed 'Green', 'Yellow', 'Red', 'Blue', 'Green'
printBuilding : end
printLinkedListbuilding
printBuilding : end
printLinkedListbuilding
returnedvalue checksimilarbuilding building
printreturnedvalue #This should print 'Not Similar'
unittest.outputtestreturnedvalue, 'Not Similar'
print
printTest Case
building createListnparrayRed 'Green', 'Yellow', 'Red', 'Blue', 'Green'
building createListnparrayRed 'Green', 'Yellow', 'Red', 'Blue', 'Green', 'Blue'
printBuilding : end
printLinkedListbuilding
printBuilding : end
printLinkedListbuilding
returnedvalue checksimilarbuilding building
printreturnedvalue #This should print 'Not Similar'
unittest.outputtestreturnedvalue, 'Not Similar'
print
printTest Case
building createListnparrayRed 'Green', 'Yellow', 'Red', 'Blue', 'Green', 'Blue'
building createListnparrayRed 'Green', 'Yellow', 'Red', 'Blue', 'Green'
printBuilding : end
printLinkedListbuilding
printBuilding : end
printLinkedListbuilding
returnedvalue checksimilarbuilding building
printreturnedvalue #This should print 'Not Similar'
unittest.outputtestreturnedvalue, 'Not Similar'
print
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started