留学生作业代写 . Complete catalan_recur function, which recursively calculates the N-th

. Complete catalan_recur function, which recursively calculates the N-th Catalan number
(Links to an external site.)
from a given positive integer input n. Catalan number sequence occurs in various
counting problems

Copyright By PowCoder代写 加微信 powcoder

(Links to an external site.)
. The sequence can be recursively defined by the following equation.
And this is the high-level description of the recursive Catalan. def catalan_recur(n):
if n <= 1: return 1; foriinrange(n): #i=0~(n-1) res += catalan_recur(i) * catalan_recur(n-i-1) return res; >> a0: the argument for the given positive integer input, n
3A. Complete load_pts_file function that reads multiple pairs of numbers from a file and finds the distance between every two numbers on a number line:
Few steps as the guidance
1) Open/Read the .dat file into a pre-allocated given space, data_buffer. 2) The format is fixed in every single line of the file, parse the content
and interpret each as an integer number.
3) Finding distances from the every-two-number, iteratively store the
distance to an integer array
(note: the base address is given in $a1).
4) Return the number of distances calculated. For example,
lab3_pts.dat Integer Array for Return Value Distances
The above example shows that load_pts_file function
– opens/reads lab3_pts.dat file (into data_buffer),
– parses and interprets ‘1’ as the integer numbers, 1, and ‘2’ as 2
– finds the distance of 1 and 2 to be 1 and updates the distance array
– repeats the above two until the end of file, then returns 4 distances calculated. NOTE: you can safely assume
I. the file will strictly follow such
11 12 -3 4 11 -12
[-1, -1, -1, -1, -1] [After]
[1, 1, 7, 23, -1]

format in every single line.
II. there will be at least one line in the file.
III. The file won’t exceed 300 bytes, i.e. you don’t need to worry about out of memory in the given space, data_buffer.
IV. The default values in data_buffer were all 0.
Arguments and Given parameters:
>> $a0: the address of the string that represents the input file name, “lab3_pts.dat”.
>> $a1: the base address of an integer array that will be used to store distances >> data_buffer: the buffer that you use to hold data for file read/write (MAXIMUM: 300 bytes)
3B. Complete save_dist_list function that saves N distances’ values into a file For example,
Integer Array for Number of Distances to lab3_dist.dat Distances Save
Note: the NEWLINE character (at the end of every line) is not visible.
The above example shows that save_dist_list function takes 4 distances from the distance array, converts integers into ASCII characters, as a result of “1 1 7 2 3 ” in the data_buffer, then makes syscall to write 9 characters from this string into lab3_dist.dat file. Thought before starting to code: How to convert 23 into ‘2’, ‘3’? other examples, 123 -> ‘1’, ‘2’, ‘3’?
NOTE: you can safely assume
I. The distances to save are guaranteed positive/valid, e.g. N=4, the first four numbers in the array must be positive.
Arguments and Given parameters:
>> $a0: the address of the string that represents the output file name, “lab3_dist.dat”.
>> $a1: the base address of an integer array that stores distances
>> $a2: the number of distances to save from an integer array
>> data_buffer: the buffer that you use to hold data for file read/write (MAXIMUM: 300 bytes)
Side Note:
If you have finished part3A, you may un-comment the code block (line 233-234 in lab3_test.asm) to forward part3A result to be part3B input. Therefore, by orchestrating with part3A, part3B can save found distances, originally from a
[1, 1, 7, 23, -1]

points file, lab3_pts.dat, into a distance file, lab3_dist.dat.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com