Answered step by step
Verified Expert Solution
Link Copied!

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_1=
Red->Green->Yellow->Red->Blue->Green->None
building_2=
Red->Green->Yellow->Red->Blue->Green->None
Similar
building_1=
Red->Green->Yellow->Red->Yellow->Green->None
building_2=
Red->Green->Yellow->Red->Blue->Green->None
Not Similar
building_1=
Red->Green->Yellow->Red->Blue->Green->None
building_2=
Red->Green->Yellow->Red->Blue->Green->Blue->None
Not Similar You must Run this cell for your driver code to execute successfully #Run this cell
class Node:
def __init__(self,elem,next = None):
self.elem,self.next = elem,next
def createList(arr):
head = Node(arr[0])
tail = head
for i in range(1,len(arr)):
newNode = Node(arr[i])
tail.next = newNode
tail = newNode
return head
def printLinkedList(head):
temp = head
while temp != None:
if temp.next != None:
print(temp.elem, end ='-->')
else:
print(temp.elem)
temp = temp.next
print() Driver code:
def length(head):
temp, count = head, 0
while temp != None:
count +=1
temp = temp.next
return count
def check_similar(building_1, building_2):
#TO DO
print('==============Test Case 1=============')
building_1= createList(np.array(['Red', 'Green', 'Yellow', 'Red', 'Blue', 'Green']))
building_2= createList(np.array(['Red', 'Green', 'Yellow', 'Red', 'Blue', 'Green']))
print('Building 1: ', end ='')
printLinkedList(building_1)
print('Building 2: ', end ='')
printLinkedList(building_2)
returned_value = check_similar(building_1, building_2)
print(returned_value) #This should print 'Similar'
unittest.output_test(returned_value, 'Similar')
print()
print('==============Test Case 2=============')
building_1= createList(np.array(['Red', 'Green', 'Yellow', 'Red', 'Yellow', 'Green']))
building_2= createList(np.array(['Red', 'Green', 'Yellow', 'Red', 'Blue', 'Green']))
print('Building 1: ', end ='')
printLinkedList(building_1)
print('Building 2: ', end ='')
printLinkedList(building_2)
returned_value = check_similar(building_1, building_2)
print(returned_value) #This should print 'Not Similar'
unittest.output_test(returned_value, 'Not Similar')
print()
print('==============Test Case 3=============')
building_1= createList(np.array(['Red', 'Green', 'Yellow', 'Red', 'Blue', 'Green']))
building_2= createList(np.array(['Red', 'Green', 'Yellow', 'Red', 'Blue', 'Green', 'Blue']))
print('Building 1: ', end ='')
printLinkedList(building_1)
print('Building 2: ', end ='')
printLinkedList(building_2)
returned_value = check_similar(building_1, building_2)
print(returned_value) #This should print 'Not Similar'
unittest.output_test(returned_value, 'Not Similar')
print()
print('==============Test Case 4=============')
building_1= createList(np.array(['Red', 'Green', 'Yellow', 'Red', 'Blue', 'Green', 'Blue']))
building_2= createList(np.array(['Red', 'Green', 'Yellow', 'Red', 'Blue', 'Green']))
print('Building 1: ', end ='')
printLinkedList(building_1)
print('Building 2: ', end ='')
printLinkedList(building_2)
returned_value = check_similar(building_1, building_2)
print(returned_value) #This should print 'Not Similar'
unittest.output_test(returned_value, 'Not Similar')
print()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Rules In Database Systems Third International Workshop Rids 97 Sk Vde Sweden June 26 28 1997 Proceedings Lncs 1312

Authors: Andreas Geppert ,Mikael Berndtsson

1997th Edition

3540635165, 978-3540635161

More Books

Students also viewed these Databases questions

Question

Q .1. Different ways of testing the present adulterants ?

Answered: 1 week ago

Question

Q.1. Health issues caused by adulteration data ?

Answered: 1 week ago

Question

1. Traditional and modern methods of preserving food Articles ?

Answered: 1 week ago

Question

What is sociology and its nature ?

Answered: 1 week ago

Question

e. What are notable achievements of the group?

Answered: 1 week ago