半群理论代写 MT5863代写 半群理论定义和基本属性代写
479MT5863 Semigroup theory: Problem sheet 1 Definition and basic properties 半群理论代写 Let S be a semigroup, and let e, z, u ∈ S. Then: (i) e is a left identity if ex = x for all x ∈ S; (ii)...
View detailsSearch the whole station
数学应用编程代写 Description In this project, you will write a computer code to generate a particular sequence of numbers described in the following YouTube video:
In this project, you will write a computer code to generate a particular sequence of numbers described in the following YouTube video: The Trapped Knight (https://www.youtube.com/watch?v=RGQe8waGJ4w)
Begin by watching the video and make sure you understand exactly how the sequence is generated. Then continue to implement the code in the 3 parts described below.
We will store the chess board in a 2d-array of integers. The size of the board is -by- , for a given integer . This means the board extends from the center square by steps in all directions.
The first step is to initialize the board by filling it with the integers described in the video. Finish the implementation of the function definition in the cell below such that it returns this “spiral pattern” for any given input parameter .
An example is given below: for the following input
board = initialize_board(3)
the correct output is
7×7 Matrix{Int64}:
37 36 35 34 33 32 31
38 17 16 15 14 13 30
39 18 5 4 3 12 29
40 19 6 1 2 11 28
41 20 7 8 9 10 27
42 21 22 23 24 25 26
43 44 45 46 47 48 49
Test your function for various values of to make sure it is correct before you continue.
Hints:
Note that since Julia uses 1-based indexing, the center square of the array board is given by element
board[n+1,n+1] .
After the center has been placed, there are exactly “circles” of numbers of increasing radius. This is naturally implemented using a for-loop.
In each “circle”, there are 4 segments going up, left, down, and right. These are also naturally implemented using a sequence of 4 for-loops.
In [1]:
# Initializes the board on a [-n:n]x[-n:n] domain with spiral numbers
#
# Example: initialize_board(2) returns
# 17 16 15 14 13
# 18 5 4 3 12
# 19 6 1 2 11
# 20 7 8 9 10
# 21 22 23 24 25
#
# Inputs:
# n = integer size of board to allocate
# Outputs:
# board = 2n+1 x 2n+1 integer array filled with spiral numbers
function initialize_board(n)
end
Out[1]:
initialize_board (generic function with 1 method)
Next we will write the function to simulate the walk and produce the sequence. This function will take an initialized board as input, and produce a list of numbers as well as the corresponding x- and y-coordinates.
For example, the following input:
board = initialize_board(2)
display(board)
seq, xs, ys = simulate_walk(board);
println("Sequence = ", seq)
println("x-coordinates = ", xs)
println("y-coordinates = ", ys)
should produce the following correct output:
5×5 Matrix{Int64}:
17 16 15 14 13
18 5 4 3 12
19 6 1 2 11
20 7 8 9 10
21 22 23 24 25
Sequence = [1, 10, 3, 6, 9, 4, 7, 2, 5, 8, 11, 14]
x-coordinates = [0, 2, 1, -1, 1, 0, -1, 1, -1, 0, 2, 1]
y-coordinates = [0, 1, -1, 0, 1, -1, 1, 0, -1, 1, 0, -2]
Again test your code, first using small values of as shown above, which makes it easier to look at the results and find errors.
Hints:
It is convenient to create another 2d-array of booleans, indicating if a square has been visited or not.
Make sure you never allow the knight to jump outside the board. That is, the only valid positions are steps from the center square in either direction
In [2]:
# Simulates the trapped knight walk on a pre-initialized board and returns information about knight
#
# Inputs:
# board = 2n+1 x 2n+1 integer array filled with spiral numbers
# Outputs:
# sequence = integer array containing the sequence of spiral numbers the knight jumped to during wa
# x_path = integer array containing the x coordinates of each step of knight walk
# y_path = integer array containing the y coordinates of each step of knight walk
function simulate_walk(board)
end
Out[2]:
simulate_walk (generic function with 1 method)
Finally, use your code to generate the full sequence ( is sufficient), output the last number, and plot the path by straight lines between all the visited x,y-coordinates.
In [ ]:
In [ ]:
更多代写:CS作业代写网站 托福代考多少钱 英国Budgeting代考 怎么写summary 怎么写conclusion 计算机论文写作技巧
合作平台:essay代写 论文代写 写手招聘 英国留学生代写
MT5863 Semigroup theory: Problem sheet 1 Definition and basic properties 半群理论代写 Let S be a semigroup, and let e, z, u ∈ S. Then: (i) e is a left identity if ex = x for all x ∈ S; (ii)...
View details数学作业代写了解一下,可以快速完成数学作业 数学作业代写,我们每个人生活的方方面面都因为网络时代的来临而有所改变。就比如日常购物方面,从前的我们购买东西还需要到街上去,用一张一张的现金购买东西,...
View details4. Probability on finite sample spaces. 数学概率作业代写 1. Are the following events A, B ⊂ Ωroulette independent? Find P(A|B) and P(B|A) in each case. a) A = Red, B = Even, 1. Are the fol...
View detailsMACM 201 - D100 AND D200 ASSIGNMENT #8 离散数学作业代写 Instructions Answer all questions on paper or a tablet using your own handwriting. Put your name, student ID number and page number at th...
View details