0% found this document useful (0 votes)
27 views4 pages

Final Test Dev: 1. Dynamic Table

The document describes two functions: 1. A dynamic table function that takes an array of numbers and maximum column count as parameters and returns a formatted table with numbers from the array placed into the columns up to the maximum allowed per row. 2. A castle builder function that takes an array of land heights and returns the number of castles that can be built, where a castle can be built on a hill (block taller than neighbors) or valley (block shorter than neighbors).

Uploaded by

Rayhan Agoalex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views4 pages

Final Test Dev: 1. Dynamic Table

The document describes two functions: 1. A dynamic table function that takes an array of numbers and maximum column count as parameters and returns a formatted table with numbers from the array placed into the columns up to the maximum allowed per row. 2. A castle builder function that takes an array of land heights and returns the number of castles that can be built, where a castle can be built on a hill (block taller than neighbors) or valley (block shorter than neighbors).

Uploaded by

Rayhan Agoalex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

FINAL TEST DEV

1. Dynamic Table
Please create a function that will create a dynamic table that contains numbers. It has 2 parameters,
parameter 1 is an array of numbers as the content of the table, and parameter 2 is a number as the maximum
number of column per row.

Details:

F(X, y)

X = [n], when n is an Integer >=


0 y = m, when m is an Integer
>= 1

Additional rules:

a. Maximum length that a column can contains is the longest length of a number in the array.

b. You will put a star ( * ) for any number in a column that not as long as the maximum length of the
column.

c. The numbers will be placed in the table sequentially same as the way you put it in the array, start
from top left of the first row, go to the max column, then going down. So last number should be at
the bottom (most right) of the last row.

d. You must have separator ( | ) between columns.

e. Use plus sign ( + ) as the corner of a column.

f. Use equal sign ( = ) as the line of the column.

Sample input:

X = [12, 444, 54643, 3155, 667543, 8637, 0, 369, 7516, 335]


y=4

Sample output (based on sample input):


|****12|***444|*54643|**3155|

|667543|**8637|*****0|***369|

** 7 516 | ***335
2. Castle Builder
Please create a function that will count how many castle that you can build. It has 1 parameter which is an
array of numbers as the land height per 1 block length.

Details:

F(X)

X = [n], when n is an Integer (-2,147,483,648 to 2,147,483,647)

Additional rules:

a. You only can build a castle on a hill or a valley.

b. Hill contains block(s) with the height is taller than the neighbors blocks.

c. Valley contains block(s) with the height is shorter than the neighbors blocks.

d. Incomplete hill or valley at the first and the last block, still can be used to build a castle (considered as
hill or valley)

e. Your function just need to count, no need to draw.

Sample input:

X = [3, -1, -5, -5, 2, 4, 7, 5, 1, 1, 1, 4]

Illustration based on the input (C is the castle position):


Sample output (based on sample input):

You might also like