Menu

Follow Previous Set Questions Solution Previous Set Given Question Answer Basing Answers Q43822416

This is a follow-up of a previous set of questions.The solution to the previous set has been given below. Thisquestion has to be answer basing on the answers from the previousset. Please solve them in python language for me. Thankyou.

Please note: The whole thing is just one questionand the rest of the base code has been noted with the next questionat
https://www.chegg.com/homework-help/questions-and-answers/question-follows-https-wwwcheggcom-homework-help-questions-answers-follow-previous-set-que-q43828154?trackid=F8BYKJiv

***The code at the end is not the solution. Thoseare the base codes basing on which the codes for the followingquestions are to be answered.***

**Please take your time***

Part A: Helper functions (10 marks) This task involves writing some new helper functions, that are useful to use with brute f

+ L L ---|---|---|--- ---|--- --- | T | LRT LRT --- ---|--- ---|--- --- | BIT | T | LR ---|--- |---|---|--- | T | B | BITI TI

# Part A: Representation and display (15 marks) # Part A - Task 1 - Initial setup (5 marks) def readBoard (fileName): M = 0 N

# Part A - Task 2 - Display (10 marks) def printBoard (positivesColumn, negativesColumn, positivesRow, negativesRow, orientat

print() print(--- , end=) # print line below row check orientation for colCounter in range (N): if (orientations (rowCo

#Part B: Helper functions (25 marks) #Part B - Task 1 - Safe placing (10 marks) def canPlace Pole (row, col, pole, workingBoa

#Part B - Task 3 - Pole Count (5 marks) def poleCount (rowOrCol, index, pole, workingBoard): M= len (workingBoard) N= len (wo

# Part C: Board Generation Functions (30 marks) # Part C - Task 1: Orientations generation (10 marks) def orientations Genera

# Part C - Task 2: Filling board with magnets (10 marks) def fillWithMagnets (orientations): M= len (orientations) N= len (or

# Part C - Task 3: Generating random new board (10 marks) def randomNewBoard (M,N): # 1. Generate the orientations board of s

# Part A: Representation and display (15 marks)

# Part A – Task 1 – Initial setup (5 marks)
def readBoard(fileName):
M = 0
N = 0
positivesColumn = []
negativesColumn = []
positivesRow = []
negativesRow = []
orientations = []
workingBoard = []

file = open(fileName)
fileContent = []

for line in file:
fileContent.append(line.strip())

M = int(fileContent[0]) # line 1 in file
N = int(fileContent[1]) # line 2 in file

positivesColumn = convertStringListToIntList(
fileContent[2].split()) # line 3 in file
negativesColumn = convertStringListToIntList(
fileContent[3].split()) # line 4 in file
positivesRow = convertStringListToIntList(
fileContent[4].split()) # line 5 in file
negativesRow = convertStringListToIntList(
fileContent[5].split()) # line 6 in file

# next M lines after line 6
for counter in range(M):
orientations.append(list(str(fileContent[counter+6])))

# remaining M lines in file
for counter in range(M):
workingBoard.append(list(str(fileContent[counter+M+6])))
file.close()
return (positivesColumn, negativesColumn, positivesRow,negativesRow, orientations, workingBoard)

def convertStringListToIntList(lst):
for item in range(len(lst)):
lst[item] = int(lst[item])
return lst

# Part A – Task 2 – Display (10 marks)
def printBoard(positivesColumn, negativesColumn, positivesRow,negativesRow, orientations, workingBoard):
M = len(orientations)
N = len(orientations[0])

# print the positivesColumn -> the top positive
print(” + |”,end=””)
for rowCounter in range(N):
if positivesColumn[rowCounter]>=0:
print(” ” + str(positivesColumn[rowCounter])+ ” “,end=””)
elif positivesColumn[rowCounter]==-1:
# -1 to empty square
print(” “, end=””)
print(“|”,end=””)
print(“”)

# print the following line
print(“— “*(N+2))

# print the workingBoard one row at a time
for rowCounter in range(M):

#print the positivesRow first
if positivesRow[rowCounter]>=0:
print(” ” + str(positivesRow[rowCounter]) + ” “, end=””)
elif positivesRow[rowCounter]==-1:
print(” “, end=””)
print(“|”,end=””)

#print the workingBoard Row
for colCounter in range(N):
#if E print blank square
if (workingBoard[rowCounter][colCounter]==’E’):
print(” “, end=””)
else:
print (” ” + workingBoard[rowCounter][colCounter] + ” “,end=””)
#Check orientations board if current magnet is horizontal orvertical
#if horizontal
if (orientations[rowCounter][colCounter]==’L’):
print(” “,end=””)
else:
#if vertical
print(“|”,end=””)

#print the negatives row
if negativesRow[rowCounter]>=0:
print(” ” + str(negativesRow[rowCounter]) + ” “, end=””)
elif negativesRow[rowCounter]==-1:
print(” “, end=””)
  

print(“”)
print(“— “,end=””)
# print line below row check orientation
for colCounter in range(N):
if (orientations[rowCounter][colCounter]!=’T’):
print(“— “,end=””)
else:
#if vertical
print(” “,end=””)
print(“— “,end=””)
print(“”)
  
# print the negativeColumn at the bottom
print(” |”, end=””)
for rowCounter in range(len(negativesColumn)):
if negativesColumn[rowCounter] >= 0:
print(” ” + str(negativesColumn[rowCounter]) + ” “, end=””)
else:
print(” “, end=””)
print(“|”,end=””)
print(” – “)
print(“”)
return

Part A: Helper functions (10 marks) This task involves writing some new helper functions, that are useful to use with brute force and backtracking algorithms. Task 1: Converting a set into a board (5 Marks) Write a function setToBoard(set, orientations) that takes a given set list and converts it into a board based on existing orientations. This function will return the resulting board as the output. set is a list of values that can only be 0, 1, or 2. The length of set is equivalent to the number of blocks that will be converted. • • Orepresents: O For an LR block: A positive pole (‘+’) in the left (L’) square and therefore negative pole (-) in the right (‘R’) square. o For a TB block: A positive pole (‘+’) in the top (‘T’) square and therefore negative pole (-4) in the bottom (‘B’) square. 1 represents: o For an LR block: A negative pole (-) in the left (L’) square and therefore positive pole (‘+’) in the right (‘R’) square. o For a TB block: A negative pole (-) in the top (‘T’) square and therefore positive pole (‘+’) in the bottom (‘B’) square. 2 represents: O Blank block (‘X’) squares for both squares of any block orientation. • Important Notes: The function will start from the top left square find the required number of blocks that it will need to change based on the length of set. • The len (set) <= (M*N)//2, where (M*N)//2 stands for the number of slots in the entire board. • If the len(set) is less than (M*N)//2 then the board should turn the remaining slots to empty block( ‘E’) Example of this function’s use is as follows: positivesColumn = (-1, -1, -1, -1, -1] negativesColumn = (-1, -1, -1, -1, -1] positiveshow = (-1, -1, -1, -1, -1, -1] negativesRow = (-1, -1, -1, -1, -1, -1] orientations = [[‘T’, ‘L’, ‘R’, ‘L’, ‘R’), [‘B’, ‘T’, ‘T’, ‘L’, ‘R’], [‘T’, ‘B’, ‘B’, ‘T’, ‘T’], [‘B’, ‘L’, ‘R’, ‘B’, ‘B’], [‘L’, ‘R’, ‘L’, ‘R’, ‘T’], [‘L’, ‘R’, ‘I’, ‘R’, ‘B’] ] printBoard (positives Column, negativesColumn, positives Row, negatives Row, orientations, orientations) set=[0,1,1,0) workingBoard= setToBoard (set, orientations) print(“###########################################”) printBoard (positives Column, negatives Column, positives Row, negatives Row, orientations, workingBoard) set = [0,2,0,2,1,0,2] workingBoard= setToBoard (set, orientations) print(“###########################################”) printBoard (positivesColumn, negatives Column, positives Row, negatives Row, orientations, workingBoard) + L L —|—|—|— —|— — | T | LRT LRT — —|— —|— — | BIT | T | LR —|— |—|—|— | T | B | BITI TI —| |—|—| |— | B | LRB | BI —|—|—|—|—|—|— | LRT LRT —|—|—|—|— |— | LRT LR | BI —|—|—|—|—|— — L | – ############################# + 1 L L L L | —|—|—|— — — — | + – + | – + —| |—|—|—|—— | – | + L —|—| |—|—— —| |—|—| |— -|—|—|—|— — |—|—|—|—| |— –L—|——|—— ########################## + L L L L —|—|—|— —|— — | + | X X + – —| |—|— — — — | – | x | – | + – —L—| |—|—— | X | X + 1 1 — —|— |— | XL L L | —|——|——|—— |—|—|—|—| |— |—|—|—|—|—|— Example 1 – setToBoard function example # Part A: Representation and display (15 marks) # Part A – Task 1 – Initial setup (5 marks) def readBoard (fileName): M = 0 N = 0 positivesColumn = [] negativesColumn = [] positivesRow = [] negativesRow = [] orientations = [] workingBoard = [] file = open(fileName) fileContent = [] for line in file: fileContent.append(line.strip()) M = int(fileContent [0]) N = int(fileContent [1]) # line l in file # line 2 in file positivesColumn = convertStringListToIntList fileContent [2].split() # line 3 in file negativesColumn = convertStringListToIntList fileContent [3].split() # line 4 in file positives Row = convertStringListToIntList fileContent [4].split() # line 5 in file negativesRow = convertStringListToIntList fileContent [5].split()) # line 6 in file # next M lines after line 6 for counter in range (M) : orientations.append (list (str (fileContent [counter+6]))) # remaining M lines in file for counter in range (M): workingBoard.append (list (str(fileContent [counter+M+6]))) file.close() return (positivesColumn, negativesColumn, positives Row, negativesRow, orientations, workingBoard) def convertStringListToIntList (1st): for item in range (len (1st)): ist[item] = int(1st[item]) return ist # Part A – Task 2 – Display (10 marks) def printBoard (positivesColumn, negativesColumn, positivesRow, negativesRow, orientations, workingBoard): M = len (orientations) N = len (orientations[0]) # print the positivesColumn -> the top positive print(” + 1″, end=””) for rowCounter in range (N): if positivesColumn[rowCounter] >=0: print(” ” + str (positivesColumn[rowCounter]) + ” “, end=””) elif positivesColumn [rowCounter)==-1: # -1 to empty square print(” “, end=””) print(“/”, end=””) print(“”) # print the following line print(“— “* (N+2)) # print the workingBoard one row at a time for rowCounter in range (M): #print the positivesRow first if positivesRow [rowCounter] >=0: print(” ” + str (positivesRow [rowCounter]) + ” “, end=””) elif positives Row [rowCounter)==-1: print(” “, end=””) print(“/”, end=””) #print the workingBoard Row for colCounter in range (N): #if E print blank square if (workingBoard[rowCounter] [colCounter]==’E’): print(” “, end=””) else: print (” ” + workingBoard (rowCounter] [colCounter] + ” “, end=””) #Check orientations board if current magnet is horizontal or vertical #if horizontal if (orientations[rowCounter] [colCounter]==’L’): print(” “, end=””) else: #if vertical print(“/”, end=””) #print the negatives row if negativesRow [rowCounter] >=0: print(” ” + str (negativesRow [rowCounter]) + ” “, end=””) elif negativesRow [rowCounter)==-1: print(” “, end=””) print(“”) print(“— “, end=””) # print line below row check orientation for colCounter in range (N): if (orientations (rowCounter] [colCounter] !=’T’): print(“— “, end=””) else: #if vertical print(” “, end=””) print(“— “, end=””) print(“”) # print the negativeColumn at the bottom print(” l”, end=””) for rowCounter in range (len (negativesColumn)) : if negativesColumn [rowCounter] >= 0: print(” ” + str(negativesColumn [rowCounter]) + ” “, end=””) else: print(” “, end=””) print(“l”, end=””) print(” – “) print(“”) return #Part B: Helper functions (25 marks) #Part B – Task 1 – Safe placing (10 marks) def canPlace Pole (row, col, pole, workingBoard) : M= len (workingBoard) N= len (workingBoard[0]) if (row>M-1 or col>N-1): return false # check surrounding squares (diagonals are not checked ) if ((row > 0 and workingBoard[row – 1] [col] == pole) or (row < M – 1 and workingBoard[row + 1][col] == pole) or (col > 0 and workingBoard[row][col – 1] == pole) or (col < N – l and workingBoard[row][col + 1] == pole)): return false return True #Part B – Task 2 – Block orientation (5 marks) def getBlockOrientation (row, col, orientations): M= len (orientations) N= len (orientations[0]) if (row>M-1 or col>N-1): return None #if TB (Top Bottom/Vertical) orientation #if Top return Bottom coordinates if (orientations [row][col] == ‘T’): return “TB”, row+1, col #else if Bottom return Top coordinates elif (orientations [row][col] == ‘B’): return “TB”, row-1, col #else if Left return Right coordinates elif (orientations [row][col] == ‘L’): return “LR”, row, col+l #else if Right return Left coordinates elif (orientations [row][col] == ‘R’): return “LR”, row, col-1 else: return None #Part B – Task 3 – Pole Count (5 marks) def poleCount (rowOrCol, index, pole, workingBoard): M= len (workingBoard) N= len (workingBoard[0]) or (index > N-1 and rowOrCol == ‘C’)): if ((index >M-1 and rowOrCol == ‘r’) return None poleCounter=0 if str(rowOrCol).lower() ==’r’: for iterator in range (N): if workingBoard[index][iterator]== pole: poleCounter+=l elif str(rowOrCol).lower() == ‘c’: for iterator in range (M) : if workingBoard[iterator] [index]== pole: poleCounter+=1 return poleCounter #Part B – Task 4 – Random Magnetic Pole Distribution (5 marks) def randomPoleFlip (alist, percentage, flipValue): listLength = len (alist) noofflips = math.floor(listLength*percentage) #Keep repeating until desired number of flips is fulfilled while aList.count (flipValue) < noofflips: random Index= random.randint(0, listLength-1) if aList[random Index] !=flipValue: aList[random Index] = flipValue # Part C: Board Generation Functions (30 marks) # Part C – Task 1: Orientations generation (10 marks) def orientations Generator (M, N): # Generating a new M by N board with all orientations set as vertical blocks # Note: be mindful of copy orientations=[[”]*N] *M for row in range (0,M-1, 2): orientations [row]=[‘T’]*N orientations (row+1]=[‘B’]*N # Repeat the process at least 1000 times for repeat in range (1000): # Picking random block randomRow = random.randint (0,M-1) randomCol = random.randint (0, N-1) otherEndRow = getBlockOrientation (randomRow, randomCol, orientations) [1] otherEndCol = getBlockOrientation (randomRow, randomCol, orientations) [2] # If it is a LR block, check the block that is immediately above it. # If it is also an LR block and it is perfectly aligned with the picked # block then change both blocks to become TB blocks. # If it is not possible to do this with the top block, then try with the bottom block. if randomRow>0 and orientations (randomRow] [randomCol] == orientations (randomRow-1] [randomCol] and getBlockOrientation (randomRow, randomCol, orientations)[0] == ‘LR’: #Change bottom block to ‘B’s orientations [randomRow] [randomCol]=’B’ #other end orientations (otherEndRow] (otherEndCol]=’B’ #Change top block to ‘T’s orientations (randomRow-1] [randomCol]=’T’ orientations (otherEndRow-1] (otherEndCol]=’T’ elif randomCol>0 and orientations[randomRow] [randomCol] == orientations[randomRow] [randomCol-1] and getBlockOrientation (randomRow, randomCol, orientations)[0] == ‘TB’: #Change right block to ‘R’s orientations [randomRow] [randomCol]=’R’ #other end orientations (otherEndRow] (otherEndCol]=’R’ #Change left block to ‘L’s orientations (randomRow] [randomCol-1)=’L’ orientations (otherEndRow] (otherEndCol-1]=’L’. return orientations We were unable to transcribe this image# Part C – Task 3: Generating random new board (10 marks) def randomNewBoard (M,N): # 1. Generate the orientations board of size M x N randomly. (1 mark) # Note: Use orientations Generator function for this. orientations = orientations Generator (M, N) # 2. Fill the board with magnet blocks. (1 mark) # Note: use fillWithMagnets function for this. workingBoard = fillWithMagnets (orientations) # 3. Randomly replace 30% of the blocks with blank blocks (‘X’ blocks) (3 marks) # Cover the board from top to bottom and the decision to swap with a # blank block is based on a random chance for each block and repeated # until 30% of board is replaced. Other end of a checked block will be ignored. blockCount = M * N / 2 requiredReplacements = math.ceil(0.3 * blockCount) replacement Chance=0.2 replacement Count=0 while (replacement Count <requiredReplacements): for rowCounter in range (M): for colCounter in range (N): rand = random.random() #blockOrientation = getBlockOrientation (rowCounter, colCounter, orientations) [O] # unused otherEndRow = getBlockOrientation (rowCounter, colCounter, orientations) [1] otherEndCol = getBlockOrientation (rowCounter, colCounter, orientations) [2] if (otherEndRow > rowCounter or otherEndCol > colCounter): if (rand<=replacementChance and replacement Count <requiredReplacements): workingBoard[rowCounter] [colCounter]=’X’ working Board (otherEndRow] [otherEndcol]=’X’ replacement Count+=l # 4. Generate the resulting positivesColumn, negativesColumn, positivesRow, and negativesRow lists. (3 marks) # Note: use poleCount function for this. positivesColumn=[] negativesColumn=[] positivesRow=[] negativesRow=[] for counter in range (N): positivesColumn.append( poleCount(‘c’, counter,’+’, workingBoard)) negativesColumn.append( poleCount(‘c’, counter,’-‘,workingBoard)) for counter in range (M): positivesRow.append( poleCount(‘r’, counter, ‘+’, workingBoard)) negativesRow.append( poleCount(‘r’, counter,’-‘, workingBoard)) # 5. Replace 50% of the numbers in each of positivesColumn, negativesColumn, positivesRow, and # negativesRow lists with -1. (2 marks) # Note: use random PoleFlip function for this. randomPoleFlip (positives Column, 0.5,-1) randomPoleFlip (negativesColumn, 0.5,-1) randomPoleFlip (positivesRow, 0.5,-1) randomPoleFlip (negativesRow, 0.5,-1) return (positivesColumn, negativesColumn, positivesRow, negativesRow, workingBoard, orientations) Show transcribed image text Part A: Helper functions (10 marks) This task involves writing some new helper functions, that are useful to use with brute force and backtracking algorithms. Task 1: Converting a set into a board (5 Marks) Write a function setToBoard(set, orientations) that takes a given set list and converts it into a board based on existing orientations. This function will return the resulting board as the output. set is a list of values that can only be 0, 1, or 2. The length of set is equivalent to the number of blocks that will be converted. • • Orepresents: O For an LR block: A positive pole (‘+’) in the left (L’) square and therefore negative pole (-) in the right (‘R’) square. o For a TB block: A positive pole (‘+’) in the top (‘T’) square and therefore negative pole (-4) in the bottom (‘B’) square. 1 represents: o For an LR block: A negative pole (-) in the left (L’) square and therefore positive pole (‘+’) in the right (‘R’) square. o For a TB block: A negative pole (-) in the top (‘T’) square and therefore positive pole (‘+’) in the bottom (‘B’) square. 2 represents: O Blank block (‘X’) squares for both squares of any block orientation. • Important Notes: The function will start from the top left square find the required number of blocks that it will need to change based on the length of set. • The len (set) the top positive print(” + 1″, end=””) for rowCounter in range (N): if positivesColumn[rowCounter] >=0: print(” ” + str (positivesColumn[rowCounter]) + ” “, end=””) elif positivesColumn [rowCounter)==-1: # -1 to empty square print(” “, end=””) print(“/”, end=””) print(“”) # print the following line print(“— “* (N+2)) # print the workingBoard one row at a time for rowCounter in range (M): #print the positivesRow first if positivesRow [rowCounter] >=0: print(” ” + str (positivesRow [rowCounter]) + ” “, end=””) elif positives Row [rowCounter)==-1: print(” “, end=””) print(“/”, end=””) #print the workingBoard Row for colCounter in range (N): #if E print blank square if (workingBoard[rowCounter] [colCounter]==’E’): print(” “, end=””) else: print (” ” + workingBoard (rowCounter] [colCounter] + ” “, end=””) #Check orientations board if current magnet is horizontal or vertical #if horizontal if (orientations[rowCounter] [colCounter]==’L’): print(” “, end=””) else: #if vertical print(“/”, end=””) #print the negatives row if negativesRow [rowCounter] >=0: print(” ” + str (negativesRow [rowCounter]) + ” “, end=””) elif negativesRow [rowCounter)==-1: print(” “, end=””)
print(“”) print(“— “, end=””) # print line below row check orientation for colCounter in range (N): if (orientations (rowCounter] [colCounter] !=’T’): print(“— “, end=””) else: #if vertical print(” “, end=””) print(“— “, end=””) print(“”) # print the negativeColumn at the bottom print(” l”, end=””) for rowCounter in range (len (negativesColumn)) : if negativesColumn [rowCounter] >= 0: print(” ” + str(negativesColumn [rowCounter]) + ” “, end=””) else: print(” “, end=””) print(“l”, end=””) print(” – “) print(“”) return
#Part B: Helper functions (25 marks) #Part B – Task 1 – Safe placing (10 marks) def canPlace Pole (row, col, pole, workingBoard) : M= len (workingBoard) N= len (workingBoard[0]) if (row>M-1 or col>N-1): return false # check surrounding squares (diagonals are not checked ) if ((row > 0 and workingBoard[row – 1] [col] == pole) or (row 0 and workingBoard[row][col – 1] == pole) or (col M-1 or col>N-1): return None #if TB (Top Bottom/Vertical) orientation #if Top return Bottom coordinates if (orientations [row][col] == ‘T’): return “TB”, row+1, col #else if Bottom return Top coordinates elif (orientations [row][col] == ‘B’): return “TB”, row-1, col #else if Left return Right coordinates elif (orientations [row][col] == ‘L’): return “LR”, row, col+l #else if Right return Left coordinates elif (orientations [row][col] == ‘R’): return “LR”, row, col-1 else: return None
#Part B – Task 3 – Pole Count (5 marks) def poleCount (rowOrCol, index, pole, workingBoard): M= len (workingBoard) N= len (workingBoard[0]) or (index > N-1 and rowOrCol == ‘C’)): if ((index >M-1 and rowOrCol == ‘r’) return None poleCounter=0 if str(rowOrCol).lower() ==’r’: for iterator in range (N): if workingBoard[index][iterator]== pole: poleCounter+=l elif str(rowOrCol).lower() == ‘c’: for iterator in range (M) : if workingBoard[iterator] [index]== pole: poleCounter+=1 return poleCounter #Part B – Task 4 – Random Magnetic Pole Distribution (5 marks) def randomPoleFlip (alist, percentage, flipValue): listLength = len (alist) noofflips = math.floor(listLength*percentage) #Keep repeating until desired number of flips is fulfilled while aList.count (flipValue) 0 and orientations (randomRow] [randomCol] == orientations (randomRow-1] [randomCol] and getBlockOrientation (randomRow, randomCol, orientations)[0] == ‘LR’: #Change bottom block to ‘B’s orientations [randomRow] [randomCol]=’B’ #other end orientations (otherEndRow] (otherEndCol]=’B’ #Change top block to ‘T’s orientations (randomRow-1] [randomCol]=’T’ orientations (otherEndRow-1] (otherEndCol]=’T’ elif randomCol>0 and orientations[randomRow] [randomCol] == orientations[randomRow] [randomCol-1] and getBlockOrientation (randomRow, randomCol, orientations)[0] == ‘TB’: #Change right block to ‘R’s orientations [randomRow] [randomCol]=’R’ #other end orientations (otherEndRow] (otherEndCol]=’R’ #Change left block to ‘L’s orientations (randomRow] [randomCol-1)=’L’ orientations (otherEndRow] (otherEndCol-1]=’L’. return orientations

# Part C – Task 3: Generating random new board (10 marks) def randomNewBoard (M,N): # 1. Generate the orientations board of size M x N randomly. (1 mark) # Note: Use orientations Generator function for this. orientations = orientations Generator (M, N) # 2. Fill the board with magnet blocks. (1 mark) # Note: use fillWithMagnets function for this. workingBoard = fillWithMagnets (orientations) # 3. Randomly replace 30% of the blocks with blank blocks (‘X’ blocks) (3 marks) # Cover the board from top to bottom and the decision to swap with a # blank block is based on a random chance for each block and repeated # until 30% of board is replaced. Other end of a checked block will be ignored. blockCount = M * N / 2 requiredReplacements = math.ceil(0.3 * blockCount) replacement Chance=0.2 replacement Count=0 while (replacement Count rowCounter or otherEndCol > colCounter): if (rand

Expert Answer


Answer to This is a follow-up of a previous set of questions. The solution to the previous set has been given below. This question…

OR