Search the whole station

# 数学应用编程代写 Math 124代写 数学编程代写 数学作业代写

490

## Project 1 – The Trapped Knight

### Description

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.

### Part 1 – Initialize the board数学应用编程代写

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 numbersfunction initialize_board(n)end`

Out[1]:

initialize_board (generic function with 1 method)

### Part 2 – Simulate the walk数学应用编程代写

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 25Sequence = [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 walkfunction simulate_walk(board)end`

Out[2]:

simulate_walk (generic function with 1 method)

### Part 3 – Generate the full sequence and plot the path数学应用编程代写

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 [ ]:

The prev: The next:

### Related recommendations

• #### 离散数学与图论代写 图论代写 离散数学代写 数学作业代写

296

Discrete Mathematics and Graph Theory 离散数学与图论代写 Practice Class 4 1. Give recursive definitions of the following sequences. (a) The sequence of powers of 2: 20 = 1, and for n ≥ 1, _ ...

View details
• #### 数学统计作业代写 数学作业代写 统计作业代写 数学代写

489

Homework 3 数学统计作业代写 Instructions: Solve the problems in the spaces provided and save as a single PDF. Then upload the PDF to Canvas Assignments by the due date. Instructions: Solve t...

View details
• #### 计算数论作业代写 Mth 440/540代写 数学作业代写 数学代写

362

Mth 440/540 Homework 计算数论作业代写 (1) Part I a.) Use Mathematica to determine the 100th prime, the 1000th prime, and the 10,000th prime. b.) Use Mathematica to determine the prime (1) ...

View details
• #### 半群理论代写 MT5863代写 半群理论定义和基本属性代写

312

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
1