Python Coding代写 | COMS 4701 Artificial Intelligence Homework – Coding


Read Carefully:

• You must name your file Any submission that does not follow this naming will not be graded
and will receive a zero.

• Do not import any libraries other than NumPy.

• A skeleton of each function has been provided to you. You are expected to ONLY write code in the functions
and blocks specified. In any case, DO NOT modify the function signatures, or any code that is not specified
to be modifiable for any reason. Also, though you may modify the main function to test other cases, do not
turn in an assignment with a modified main function. This will be run by our autograder, so any unexpected
modifications that make it malfunction will receive a zero. Test cases have been provided in the main function
in the skeleton code.

• Only Python 3.x versions will be graded.

• To receive points, make sure your code runs. We recommend using Spyder, Pycharm or Google Colab. They
all allow you to download .py files. Be aware that if you write your code in some platforms like Codio and
copy and paste it in a text file, there may be spurious characters in your code, and your code will not compile.
Always ensure that your .py compiles. Code that does not run will not receive any points.

• Submission Instructions: Please submit the file on Gradescope under the assignment
Homework1 Programming.

Write a Python function to return a string of first k factorials (starting from 1!), separated by commas, in reverse
order. Use a single for loop to achieve this. You may use a helper function.
For example, for k = 8, the output would be the following string: “40320,5040,720,120,24,6,2,1”

Write a single Python function that takes two lists (x and y) as inputs for each of the following:

a. Return the resulting list after the following operations: (i) sort y by descending order, and (ii) delete the last
element of this sorted list.

b. Return the reverse list of x.

c. Return the list of unique elements that you get by concatenating x and y, in ascending order.

d. Return a single list consisting of x and y as its two elements.

Write a single Python function that takes three sets, x, y, and z, as inputs for each of the following:

a. Return the union set of all three sets.

b. Return the intersection set of all three sets.

c. Return a set of elements that belong to only a single set out of the three sets.

a. Consider the following 5×5 mini-chess board. Assuming that the top left corner is (0, 0) and any cell in the board
is represented with (i, j) where i is the row and j is column, create a 2D NumPy array where black knights are
represented with integer 1, white pawn is represented with 2, and empty spaces are represented with 0. Return
this array in the associated function.

b. Now suppose you are controlling the white pawn. Write a Python function that takes in any such board configu-
ration x (i.e. a NumPy array) as the only argument and returns a list of indices of the black knights that currently
threaten the white pawn (e.g. [(0, 1), (0, 3), …]). This should work for all cases (i.e. any 5×5 board with
black knights as 1s and a single white pawn as 2). You do not have to worry about the order of tuples in the list.
To see how a knight moves in chess, check