| This web page uses stylesheets, so it may look a little
funny in older browsers. The complete set of problems and solutions can be downloaded as a self extracting zip file by clicking the icon below. Copies of Turbo Pascal and QBasic are available online. Also available is the Judges Packet, which lists the inputs and outputs judges used to check programs.
Background Prime number - any number n whose only factors are 1 and n. Example: 2,3,5,7,11... Perfect number - number that equals the sum of all its factors excluding its self. Example: 6 = 1+2+3 Armstrong number - a number that equals the sum of the cubes of its digits. Example: 13+53+33=153 Program Print the sum of all prime, armstrong, and perfect numbers within a range of numbers. If a number falls into more than one category, count it only once. Solutions: Pascal Source | Executable Background Not much. Program Write a program that inputs a sentence and reverses the order of the letters while maintaining the original spacing. Example:
Solutions: QBasic Source | Executable 12 Days of Christmas 10 points Background The hit song, 12 Days of Christmas, describes how 12 types of gifts are distributed over 12 days. On each day n, the gifts from all the previous days are given as well as n copies of a new type of gift, shown in the chart below. For example on the second day the gift list includes 2 Turtle Doves and 1 Partridge. The accumulated gifts on that day are 2 Turtle Doves and 2 Partridges. 1st Day: 1 Partridge in a Pear Tree Program Part A: Write a program that will list the accumulated gifts on any day n. Part B: Find out which gift you have the most of after 12 Days. Solutions: Pascal Source | ExecutableQuadratic Formula Problem 10 points Background Many computer programs in competitions such as this one aim to solve strange and obscure problems or to produce mysterious numerical answers which are of little or no use to anyone. Boldly carrying on this noble tradition is this little 10 pointer! Program
Using inputted numbers A, B, and C, write a program that sums all of the the real roots of this equation for all the different rearrangements of A, B, and C. (ABC,CBA,BCA, etc...) Example: For an A, B, C of 1, 2, and 3 respectively, the sum value should be -1.5. Solutions: Pascal Source | ExecutableBackground Resistors are components used in electronics to limit the flow of current. All resistors have a resistance value that is measured in ohms. Resistors are printed with 4 or 5 color bands that indicate their value. The colors have values as listed in the chart below:
In a 4 band resistor, the first two color bands represent the first two digits of the resistance value. In a five band resistor, the first three bands correspond to the first three digits of the resistance value. The second to last band specifies the multiplier value which is multiplied by the number made from the digits to equal the resistance value of the resistor. The last band indicates the tolerance of the resistor. Five-band resistors have three significant figures and a tolerance of either 1 or 2 percent. Four-band resistors have only two figures and have tolerance values of 5 or 10 percent. Some examples can be found below: Brown, Red, Orange, Gold = 12x103 ±5% = 12,000 ohms ±5% Violet, Green, Blue, Brown, Brown = 756x101 ±2% = 7560 ohms ±2% Brown, Red, Yellow, Silver, Black = 124x10-2 ±1% = 1.24 ohms ±1% Program Part A: Write a program to convert resistor color codes into resistance and tolerance values. (15 points) Solutions: Pascal Source | ExecutablePart B: Write a program to convert the resistance and tolerance values into color codes. (20 points) Solutions: Pascal Source | ExecutableBackground It takes 365 days, 5 hours, 48 minutes, and 46 seconds for the earth to make one revolution around the sun. Since our calendars require us to round off to the nearest day, we account for the extra time through a complex system of leap years, in which an extra day is added to the end of February. A leap year occurs on most years that are divisible by 4. A leap year does not occur on years divisible by 100 unless they are divisible by 400. Years divisible by 400 are leap years unless they are divisible by 4000. Years divisible by 4000 are never leap years. Program Part A: Write a program to that will print the number of days in any year greater than 0. (10 points) Solutions: Pascal Source | ExecutablePart B: Assuming that the calendar is precisely accurate at the beginning of year 1, write a program that will calculate the discrepancy (down to the nearest second) between the solar years and the calendar years at the of beginning of any year (greater than 0) given to the program. Also state whether our calendar is ahead of or behind the solar calendar. For example: in the beginning of the year 2, our calendar would be 5 hours, 48 minutes, and 46 seconds ahead of the solar calendar. (20 points) Solutions: Pascal Source | ExecutableBackground There are a few popular algorithms for date calculations which incorporate the 4, 100, and 400 leap year rules (as described in the calendar problem). Most, however, ignore the 4,000 year rule. Your goal is to follow all of these rules in the programs listed below. Program Part A: Write a date subtraction program that will find the number of days between two dates. (Ex: 3/28/1999 - 3/27/1999 = 1 day). (30 points) Solutions: Pascal Source | ExecutablePart B: Write a program that will input a month and a year and output the name of the weekday that the 1st of that month falls on. (5 points) Solutions: Pascal Source | ExecutableMatrix Multiplication 20 points Background A matrix is a set of numbers arranged in rows and columns so as to form a rectangular array. The numbers are called the elements, or entries, of the matrix. Matrices have wide applications in engineering, physics, economics, and statistics as well as in various branches of mathematics. Historically, it was not the matrix but a certain number associated with a square array of numbers called the determinant (see next problem) that was first recognized. Only gradually did the idea of the matrix as an algebraic entity emerge. This problem involves matrix multiplication which is a process that can only be done on certain types of matrices under certain conditions. The multiplication of a matrix A by a matrix B to yield a matrix C is defined only when the number of columns of the first matrix A equals the number of rows of the second matrix B. To determine the element cij, which is in the ith row and jth column of the product, the first element in the ith row of A is multiplied by the first element in the jth column of B, the second element in the row by the second element in the column, and so on until the last element in the row is multiplied by the last element of the column; the sum of all these products gives the element cij. In symbols, cij = ai1b1j + ai2b2j + ... + aimbmj for the case where A has m columns and B has m rows. Here is a numerical example:
Program Write a program that will input and multiply two matrices up with up to 10 rows and columns) (20 points) Solutions: Pascal Source | ExecutableDeterminant of an NxN Matrix 30 points Background Every square matrix has a number associated with it called a determinant. For a 2x2 matrix, the determinant is defined as:
Larger determinants ordinarily are evaluated by a stepwise process, expanding them into sums of terms, each the product of a coefficient and a smaller determinant. Any row or column of the matrix is selected, each of its elements arc is multiplied by the factor (-1)r + c and by the smaller determinant Mrc formed by deleting the rth row and cth column from the original array. Each of these products is expanded in the same way until the small determinants can be evaluated by inspection. At each stage, the process is facilitated by choosing the row or column containing the most zeros. For example, the determinant of the matrix:
Program Write a program to calculate the determinant of any NxN matrix up to 8x8. Solutions: C Source | ExecutableSpanish Syllable Hunt 45 points Background Unlike English, the Spanish language has a consistent set of rules to determine how words are divided up into syllables and which syllables are stressed. Most syllables begin with a consonant and end with a vowel, for example: di | ne | ro ho | la But exceptions to this rule can arise when a word begins with a vowel or when there are two consonants together: mo | ver | se a | sis | tir In the Spanish language, letter combinations ch ll and rr are considered to be like single letters. Consequently, they are never separated between two syllables: mu | cha |cho ca | ba | lle | ro Syllables can be divided between vowel combinations depending on whether they are strong or weak vowels. Strong vowels are a, e, o, á, é, í, ó, and ú. Weak vowels are u and i. Syllables are always divided between two strong vowels: de | se | o ha | bí | a But it is not necessary to divide a syllable between a strong vowel and a weak vowel or two weak vowels. a | bier | to a | bue | lo con | se | guir Stress is assigned to syllables on the basis of these divisions. Any syllable that includes an accented vowel will be the stressed syllable regardless of its positioning in the word. pe | LÍ | cu | la es | TÚ | pi | da Otherwise, if a word ends in a vowel or a vowel followed by an n or s, then the second to last syllable is stressed: a | la | ME | da COM | pras In all other situations the last syllable is stressed. te | le | vi | SOR ac | TRIZ Program Part A: Write a program that divides Spanish words up into their syllables. To get credit, the user must be able to insert vowels with accent marks. One way to implement this is to type an apostrophe before a vowel and have that be replaced by the accented vowel during processing. (Dont be intimidated by the amount of rules listed here. With a little bit of planning, the program cleanly breaks down into 6 or 7 IF..THEN statements.) (35 points) Part B: Indicate which syllable in the word receives gets stressed. (10 points) Solutions: Pascal Source | ExecutableFraction to Decimals 30 points Program Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator, that prints out the decimal representation. If the decimal representation has a repeating sequence of digits, it should be indicated by enclosing it in brackets. Example 1/3 = .33333333...is denoted as .(3), and 41/333 = .123123123...is denoted as .(123). Typical conversions are: 1/3 = .(3) 22/5 = 4.4 1/7 = .(142857) 3/8 = .375 45/56 = .803(571428) Solutions: Pascal Source | ExecutableBackground A square arrangement of numbers is a 5 x 5 Latin Square because each whole number from 1 to 5 appears once and only once in each row and column. 1 2 3 4 5 Program Write a program that will generate a random Latin square using an inputted value of N. Your program should work for any N from 2 to 9. Solutions: QBASIC Source | ExecutableProgram Write a program that reads in a roman numeral and converts the number to normal decimal. The roman characters are : M = 1000, D = 500, C = 100, L = 50, X = 10, V = 5, I = 1 Test your program with the following values : V (5), IV (4), VIII (8), MM (2000), MCM (1900), MCMXCIV (1994). Example Enter a roman numeral : VIII VIII is 8. Solutions: QBASIC Source | ExecutableDescription The factorial of an integer n, written n!, is the product of all the integers from 1 to n inclusive. The factorial quickly becomes very large; 13! is too large to store as an integer on most computers, and 35! is too large for a floating-point variable. Your task is to find the rightmost non-zero digit of n!. For example, 5! = 1 * 2 * 3 * 4 * 5 = 120, so the rightmost non-zero digit of 5! is 2. Also, 7! = 1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040, so the rightmost non-zero digit of 7! is 4. Input An integer n, between 1 and 100 inclusive. Output The rightmost non-zero digit of n!. Example 1 Input 3 Output 6 Solutions: Pascal Source | ExecutableDescription Consider the string AAAABCCCCCDDDD consisting of alphabetic characters only. This string is of length 14. Since the string consists of alphabetic characters only, duplicate characters can be removed and replaced with a duplication factor n. With this technique the string can be compressed and represented by 4AB5C4D. The compressed string is of length 7. Write a program which takes a string in compressed form and recreates the original uncompressed string. Input The string will be of the format nA... where n, the duplication factor, is an integer between 2 and 99 and A is an uppercase alphabetic character. A string may contain single characters not prefixed with a duplication factor. If this were not the case, for instance, the string AABCDE would be compressed to 2A1B1C1D1E. To avoid this, single characters will not be prefixed with a duplication factor. The string AABCDE would be compressed to 2ABCDE. The maximum length of an input string is 80 characters. Output The uncompressed string, 40 characters per line (it may be necessary to break an uncompressed string over multiple lines). Example 1 Input 3A4B7D Output AAABBBBDDDDDDD Solutions: Pascal Source | Executable |