Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Create the following functions
- makeBoard
- Accepts two parameters, integers mm and nn, and creates an mm x nn numpy array of zeros
- Returns the created array
- makeMove
- Accepts two parameters, a 2D array (such as created by makeBoard), and an integer xx
- Checks if the value at position xx in the array is 0.
- If it is, changes it to 1 and returns True
- If it isn't, does not change it and returns False
- Position xx in the array is given by reading the array top-down and left-to right. A simple 2x3 array is seen below with each value representing its position
- You may assume without checking that the value of xx provided is valid, that is it is within the array.
- Hint: Arrays have a property you can use to determine their shape.
- Hint: This function may (and indeed should) contain if statements, but no loops.
Sample array with positions:
[[0 1 2]
[ 3 4 5]]
For testing purposes, you may copy the function provided here into your code
def playGame(mm,nn): board = makeBoard(mm,nn) play = True while play: pos = np.random.randint(0,mm*nn) print(f"Move to position {pos}") play = makeMove(board,pos) print(board) print('Game Over') |
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.Similar questions
- Prompt: In Python language, write a function that applies the logistic sigmoid function to all elements of a NumPy array. Code: import numpy as np import math import matplotlib.pyplot as plt import pandas as pd def sigmoid(inputArray): modifiedArray = np.zeros(len(inputArray)) #YOUR CODE HERE: return(modifiedArray) def test(): inputs = np.arange(-100, 100, 0.5) outputs = sigmoid(inputs) plt.figure(1) plt.plot(inputs) plt.title('Input') plt.xlabel('Index') plt.ylabel('Value') plt.show() plt.figure(2) plt.plot(outputs,'Black') plt.title('Output') plt.xlabel('Index') plt.ylabel('Value') plt.show() test()arrow_forward# dates and times with lubridateinstall.packages("nycflights13") library(tidyverse)library(lubridate)library(nycflights13) Qustion: Create a function called date_quarter that accepts any vector of dates as its input and then returns the corresponding quarter for each date Examples: “2019-01-01” should return “Q1” “2011-05-23” should return “Q2” “1978-09-30” should return “Q3” Etc. Use the flight's data set from the nycflights13 package to test your function by creating a new column called quarter using mutate()arrow_forwardComplete this code using Python m1 = [] #Matrix 1m2 = [] #Matrix 2#Write a function that will return the addition of Matrix A and B.#Create a new matrix C that will hold the addtion result of Matrix A and B (A+B).#Return the resultant matrix Cdef addMatrix(A,B):#Write your code here#Write a function that will return the subtraction of Matrix B from A.#Create a new matrix C that will hold the substraction result of Matrix B from A (A-B).#Return the resultant matrix Cdef subsMatrix(A,B):#Write your code here#Write a function that will return the multiplication of Matrix A and B.#Create a new matrix C that will hold the multiplication result of Matrix A and B (A*B).#Keep in mind,in order to perform matrix multiplication, the number of columns in Matrix A must be equal to the number of columns in Matrix B. #Return the resultant matrix Cdef multipyMatrix(A,B):#Write your code here#Write a function that will transform matrix A to the transpose of matrix A.#The transpose of a matrix means…arrow_forward
- Please answer in matlab code.arrow_forwardQ/Complete the following code in Python language (biometrics) for voice recognition and apply the code, mentioning the approved source if it exists import osimport numpy as npfrom pyAudioAnalysis import audioBasicIO, audioFeatureExtraction, audioTrainTestfrom pydub import AudioSegment# Function to capture and save voice samplesdef capture_voice_samples(num_samples, speaker_name):os.makedirs("speakers", exist_ok=True)os.makedirs(f"speakers/{speaker_name}", exist_ok=True)for i in range(num_samples):input(f"Press Enter and start speaking for sample {i + 1}...")# Recording audio using pyAudioAnalysisaudio = audioBasicIO.record_audio(4, 44100)filepath = f"speakers/{speaker_name}/sample_{i + 1}.wav"audioBasicIO.write_audio_file(filepath, audio, 44100)print(f"Sample {i + 1} saved for {speaker_name}")# Function to extract features from voice samplesdef extract_features():speakers = [d for d in os.listdir("speakers") if os.path.isdir(os.path.join("speakers", d))]all_features = []all_labels =…arrow_forwardWrite the following function #input: a numerical vector x #output:the normalized vector, i.e. the vector rescaled into [0,1] # the formula to normalize is (x-min(x))/ (max(x)-min(x)) # you can NOT use the functions min and max # you can use %%, nrow, ncol, and length # you can write multiple functionsarrow_forward
- Create a function using Java: Number of Rows = 3-6 Number of Columns = 3-6 Function Name: winInDiagonalBSParameters: board: 2D integer array, piece: integerReturn: booleanAssume board is valid 2D int array, piece is X==1/O==2.Look at all backward slash \ diagonal in the board. If any backward slash \ diagonal has atleast 3 consecutive entries with a given type of piece (X/O) (3 in a row XXX, OOO), then return true,otherwise false.arrow_forwardUSE PYTHON THANK YOUarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY