# Sample Questions from the 2018 Contest

## Description

In this problem, you are given a list of x, y values that represent points in an x, y coordinate system. Process the list of x, y coordinates to determine which two are the closest. In each test case, there will be only one pair of points that are the "closest". The distance (d) between two points (x1, y1) and (x2, y2) is given by the following formula: Each point is composed of two numbers – an x coordinate and a y coordinate. The value 24, 12 is an example of a valid point. Consider the three points listed below.

24 12 25 54 33 13

The three points are (24, 12), (25, 54), and (33, 13). For output you will need to identify the two closest points and the distance between them. For the three points above the results are:

Closest 2 points are (24, 12) and (33, 13). The distance is 9.055385138137417

The closest points can be listed in any order: (24,12) and (33, 13) or (33, 13 and (24, 12). Input will be provided via a text file. Each test will have at least two points. There is no maximum number of points. The points in the tests will be separated with a space not a comma. Values for points will be positive integer numbers. Write your solution code to use only the closepoints.txt file. You can use a text editor to copy and paste data from the other test files (closepoints_1.txt and closepoints_2.txt) into closepoints.txt.

## Test Data

InputOutput
(closepoints.txt)
2 20 55 217 33 45 100 50 99 22 13 86 60 217 34 29 14 19 200 25 100 7Closest 2 points are (55, 217) and (60, 217). The distance is 5.0
(closepoints_1.txt)
21 20 33 45 100 5 99 22 13 86 34 29 14 19 200 25 100 19Closest 2 points are (99, 22) and (100, 19). The distance is 3.1622776601683795
(closepoints_2.txt)
45 100 50 99Closest 2 points are (45, 100) and (50, 99). The distance is 5.0990195135927845

1. You do not need to edit the input data.
2. You do not need to handle exceptions.
4. The judges will test your application with a different set of data that will have a different number of test cases.
5. Create your input file using a relative file address. That is, do not specify a drive or folders for the input file.

## Description

Create a numeric sequence based on multiplying the non-zero digits in a starting number. The sequence starts with a given value (x). Multiply all the non-zero digits of x together and add that value to x giving x’. Repeat the process with x’.  For example, assume x = 87. You would multiply 8 x 7 to get 56. Next, add 56 to 87 to get 143. Repeating the process for 143 gives you 155. Therefore, the first occurrences of the sequence are 87, 143, and 155. If the starting number is 1 then the first 20 numbers in the sequence are:

1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, 108, 116, 122, 126, 138, 162, 174, 202

Let’s call the sequence generated when starting with 1 the “original sequence”. An interesting property of this sequence is that, regardless of the starting number, the sequence will eventually “converge” with the original sequence. For example, starting with 55 the following sequence will be generated:

55, 80, 88, 152, 162

We can say 55 converged with the original sequence at 162. This required 4 iterations. In this problem you will be given a starting number for a new sequence. Determine the number at which the new sequence will converge with the original sequence and how many iterations this will require. The starting number will be greater than 1 and less than or equal to 500,000.

Any starting number in the input data file will converge with the original sequence before the original sequence reaches five million.

The input file (digitproductsequence.txt) will have one test case per line. For each test case, display the starting number, the number at which the sequence converges with the original sequence, and how many iterations were required.

## Test Data

Input FileInput DataOutput
digitproductsequence.txt 55 55 converged at 162 requiring 4 iteration(s)
569823569823 converged at 3110832 requiring 580 iteration(s)
6363 converged at 150056 requiring 322 iteration(s)
500000500000 converged at 1150056 requiring 199 iteration(s)

1. You do not need to edit the input data.
2. You do not need to handle exceptions.
4. The judges will test your application with a different set of test cases.
5. Create your input file using a relative file address. That is, do not specify a drive or folders for the input file.

## Description

Given a square matrix of size N by N, calculate the sums of its diagonals. There are two diagonals in each array as indicated by the figures below. In figure 1, the sum of the diagonal values is 1 + 5 + 12 or 18. In Figure 2, the sum of the diagonal values is 9 + 5+ 18 or 32. The sum of both diagonals is 18 + 32 or 50. An input text file will contain the data for the array. Each test file will contain the data for one array test case. The file contains a single integer, N. This represents the size of the square array. For example, a value of 4 indicates a 4 x 4 array. The next N2 entries in the file will be integers used to fill the array. These integers may be positive, negative, or zero. Determine and display the sum of the values in each diagonal.

Write your solution code to use only the sumofdiagonals.txt file. You can use a text editor to copy and paste data from the other test files (sumofdiagonals _1.txt and sumofdiagonals _2.txt) into sumofdiagonals.txt.

## Test Data

InputOutput
(sumofdiagonals.txt)
4 1 2 3 4 5 6 7 8 9 10 11 12 13 114 115 116Sum of diagonals is 168.
(sumofdiagonals_1.txt)
5 100 101 102 -37 100 2 -4 6 0 20 108 19 20 15 -15 -81 299 40 50 77 22 30 88 17 60Sum of diagonals is 667.
(sumofdiagonals_2.txt)
2 10 20 4 8Sum of diagonals is 42.

1. You do not need to edit the input data.
2. You do not need to handle exceptions.
4. The judges will test your application with a different set of test cases.
5. Create your input file using a relative file address. That is, do not specify a drive or folders for the input file.

## Description

Given a positive base 10 integer, greater than zero, determine how many one bits are in the binary equivalent. Then determine how many numbers between zero and the given number contain the same number of one bits. For example, the number 12 expressed as a binary number (1100) has 2 one bits. Between 0 and 12 there are 5 other numbers having 2 one bits when expressed as a binary number. These are: 3 (11), 5 (101), 6 (110), 9 (1001), 10 (1010)

In this problem you must read multiple test cases from a text file named onebits.txt. The file will contain one base 10 integer on each line. Each line represents a test case. There will be at least one test case in the file. Each base 10 integer number will be > 0 and less than the maximum value of an integer. For each base 10 integer, determine how many one bits there are in the binary equivalent. Also determine how many other numbers between zero and the number have this number of one bits.

Note: The last test number, 27465865, will likely cause your application to run a little longer than the other test numbers. However, if it runs longer than 5 seconds you likely have an error in your code.

## Test Data

Input (onebits.txt)Output

8

8 in binary has 1 1-bits. There are 3 other numbers with 1 1-bits between 0 and 8.
1212 in binary has 2 1-bits. There are 5 other numbers with 2 1-bits between 0 and 12.
1717 in binary has 2 1-bits. There are 6 other numbers with 2 1-bits between 0 and 17.
5555 in binary has 5 1-bits. There are 2 other numbers with 5 1-bits between 0 and 55.
33 in binary has 2 1-bits. There are 0 other numbers with 2 1-bits between 0 and 3.
10241024 in binary has 1 1-bits. There are 10 other numbers with 1 1-bits between 0 and 1024.
2746586527465865 in binary has 10 1-bits. There are 3010552 other numbers with 10 1-bits between 0 and 27465865.

1. You do not need to edit the input data.
2. You do not need to handle exceptions.
4. The judges will test your application with a different set of test cases.
5. Create your input file using a relative file address. That is, do not specify a drive or folders for the input file.

## Description

Central Florida Pest Control (CFPC) needs help identifying the best location to apply pesticide. CFPC scans an area where pests are suspected. The device generates a square array of 1’s and 0’s with 1’s indicating the presence of pests and 0 indicating no pests. A square array is one with the same number of rows as columns. CFPC wants to plant pesticide where the largest grouping of pests occur as this is likely the location of the “queen pest”. The largest grouping of pests will be identified by the largest square sub-array of all 1’s. Given the input from CFPC’s scanner, you will need to display the row and column of the upper left corner of the biggest square sub-array that contains all 1’s and the size of the sub-array. For example, consider the array on the left below. The largest square sub-array of all ones begins at location 2, 2 and has a size of 2. That is, there are two rows and two columns in the square sub-array. The square sub-array is highlighted on the right below. Each array will have only one largest square sub-array, or it will have no square sub-array of ones. Note it might have several square sub-arrays that are smaller than the largest one. The smallest square sub-array possible will have a size of two. The largest possible square sub-array will have the same size as the original array. You will read the data for the array from a text file. The text file will contain only valid integer values. The first integer will be the size of the square array. For example, 5 will indicate a 5 by 5 square array. The remainder of the file will contain a random series of ones and zeroes that will just fill the array. Write your solution code to use only the scan.txt file. You can use a text editor to copy and paste data from the other test files (scan _1.txt and scan _2.txt) into scan.txt.

## Test Data

InputOutput
(scan.txt)
4
0 0 1 1
0 1 0 1
1 1 1 1
1 0 1 1
The largest square sub-array begins at 2, 2 and size is 2.
(scan_1.txt)
3
1 0 1
0 1 0
1 1 1
There are no square sub-arrays.
(scan_2.txt)
8
0 0 1 0 1 1 0 1
0 0 1 0 1 1 1 1
0 0 1 0 1 1 1 1
0 0 1 0 1 1 1 1
1 1 1 0 1 1 1 1
1 1 1 0 1 1 0 1
1 1 1 0 1 1 0 1
1 1 1 0 1 1 0 1
The largest square sub-array begins at 1, 4 and size is 4.

1. You do not need to edit the input data.
2. You do not need to handle exceptions.
4. The judges will test your application with a different set of test cases.
5. Create your input file using a relative file address. That is, do not specify a drive or folders for the input file.

## Description

A group of schools has a specific number of lockers and a specific number of students. All lockers are closed on the first day of school. As students get to school they begin to play with the lockers. The first student opens every locker. The second student begins with the 2nd locker and closes every other locker. The third student starts with the third locker and changes every 3rd locker. That is, the third student opens the locker if it is closed and closes it if it is open. The 4th student starts with locker 4 and changes every 4th locker and so on. After all the students are done, display how many lockers are open.

The number of lockers will be an integer greater than 0. The number of students will be an integer greater than 0 and less than or equal the number of lockers. Input will be contained in a text file with 2 values in each row. Each line in the text file will have a different combination of number of lockers followed by a space followed by the number of students. Although there are three “records” in the test file below, there could be a variable number of rows ("records") in the text file.

## Test Data

Input (lockers.txt)Output
100 100100 Lockers: 100 Students; 10 Open lockers
10 510 Lockers; 5 Students; 6 Open lockers
1000 501000 Lockers; 50 Students; 499 Open lockers

1. You do not need to edit the input data.
2. You do not need to handle exceptions.
4. The judges will test your application with a different set of test cases.
5. Create your input file using a relative file address. That is, do not specify a drive or folders for the input file.

## Description

Leakey Tours gives water tours on a small lake. They have a variety of small boats. Each boat can hold exactly three people including the boat’s operator. Although every boat can hold three people, each individual boat has a maximum weight capacity that is different. This presents a problem when large tour groups are scheduled. In this case, Mr. Leakey can’t afford to take chances so sometimes he sends a boat out with only two people, so it is not overloaded. This means he must run more boats than he wants or the wait time for customer increases. He would like you to write a program that uses the weight capacity of a boat and all the weights of people in the tour group. With this information he wants the program to tell him the combinations of weights that will allow three people to go out in a boat, if there any.

For example, assume a boat has a capacity of 300 pounds and a group of people, including the operator, has weights of 125, 99, 87, 75, 118, 100, 66, and 113 pounds. There are two combinations of 3 passengers that would exactly fill the boat. These are 75, 100, 125 and 87, 100, 113. Notice each group of three totals exactly 300 pounds. The weights can be listed in any order but only once. That is, the combination of 75, 100, 125 can only appear once but that one display could be any ONE of the following: 75, 100, 125 or 75, 125, 100 or 125, 75, 100, etc.

The input will consist of a text file of positive integers greater than zero. The first integer in the file will be the weight capacity of the boat. That will be followed by the weights of the people in the tour group. There will be at least three weights but not more than 50 weights. The number of “answers” for any group could be zero, one, or more than one. Write your solution code to use only the weights.txt file. You can use a text editor to copy and paste data from the other test files (weights _1.txt and weights _2.txt) into weights.txt.

## Test Data

InputOutput
(weights.txt)
300 125 99 87 75 118 100 66 11375, 100, 125
87, 100, 113
(weights_1.txt)
400 100 50 32 50 18 125No combinations exist
(weights_2.txt)
100 13, 24 76 3 12 25 88 75 15 10 2 112, 13, 75
1, 24, 75
2, 10, 88
10, 15, 75

1. You do not need to edit the input data.
2. You do not need to handle exceptions.
4. The judges will test your application with a different set of test cases.

### Pair Isograms

A pair isogram is a word where every letter appears exactly twice. In this problem you must read a text file containing a list of words and determine which words are pair isograms. There will be at least one word in the file but no maximum number of words. Each word in the file will be separated by a single space. Each word will be at least 2 letters long and composed of all lowercase letters.

Examine each word and determine if it is a pair isogram. Display the word and whether it is a pair isogram or not.

## Test Data

Input (isograms.txt)Output
restaurateursrestaurateurs is NOT pair isogram
intestinesintestines is pair isogram
appearerappearer is pair isogram
bookkeeperbookkeeper is NOT pair isogram
arraigningarraigning is pair isogram
reproposesreproposes is pair isogram
installationsinstallations is NOT pair isogram
weeweeweewee is NOT pair isogram