Вы находитесь на странице: 1из 4

Ateneo de Manila University

ITM14F&G LT3
Instructions:
1. This is a hands-on group test. You are only allowed to talk to your groupmates.
2. Open notes. No internet.
3. This test is composed of 7 problems. You must save your programs in separate excel
files. Hence, you will be submitting 7 files at the end of test.
4. Save your excel files as
[ProblemName]_ [IDNumberofMember1] _ [IDNumberofMember5].xlsm
Sample: MakeAPalindrome_090416_090417_090418_090419_090420.xlsm
I. MakeAPalindrome (20pts)
Assuming the given string is composed of lowercase letters of a-z only, a palindromic string,
or a palindrome reads the same both ways. For example, abcba is a palindrome, while abc
is not a palindrome.
Characters can be added at the end of the string to make it a palindrome. For example, ab is
not a palindrome, but you can add a to from aba, which is a palindrome.
Given a string, create a function to find its palindrome conversion using the minimum
number of inserted characters.
Sample Input
ab
aa
abbey
dddaale

Output
aba
aa
abbeyebba
dddaalelaaddd

II. HappyG (20pts)


We'll say that a lowercase g in a string is "happy" if there is another 'g' immediately to its left or
right.
Assume that the input string is composed of lowercase letters from a-z only.
Create a function that returns TRUE if all the g's in the given string are happy, and FALSE
otherwise.
Sample Input
xxggxx
xxgxx
xxggyygxx

Output
TRUE
FALSE
FALSE

III. CircularPrime (30pts)


The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and
719, are themselves prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
Create a sub to count how many circular primes are there below one million.

IV. Periodic Strings (30pts)


A character string is said to have period k if it can be formed by concatenating one or more
repetitions of another string of length k.
For example, the string "abcabcabcabc" has period 3, since it is formed by 4 repetitions of the
string "abc". It also has periods 6 (two repetitions of "abcabc") and 12 (one repetition of
"abcabcabcabc").
Create a function that determines the smallest period for a given string. If the given
string cannot be formed through a repetition of a substring output N/A.
Assume that the input string is composed of lowercase letters from a-z only.
Sample Input

Output

hohoho

abcde

N/A

abcabcabcabc

V. Anagram (30pts)
Write a sub procedure generate all possible words from a given set of letters. Generate
the output in COLUMN A of your worksheet
Example: Given the word "abc", your program should - by exploring all different combination of
the three letters - output the words "abc", "acb", "bac", "bca", "cab" and "cba".
Assume that the input string is composed of uppercase and lowercase letters from a-z only.

VI. SelfNumbers (30pts)


In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called selfnumbers. For any positive integer n, define d (n) to be n plus the sum of the digits of n.
(The d stands for digitadition, a term coined by Kaprekar.) For example, d (75) = 75 + 7 + 5 =
87.
Given any positive integer n as a starting point, you can construct the infinite increasing
sequence of integers n, d(n), d(d(n)),d(d(d(n))), ....
For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51,
the next is 51 + 5 + 1 = 57, and so you generate the sequence 33, 39, 51, 57, 69, 84, 96, 111,
114, 120, 123, 129, 141...
The number n is called a generator of d (n). In the sequence above, 33 is a generator of 39, 39
is a generator of 51, 51 is a generator of 57, and so on. Some numbers have more than one
generator: for example, 101 has two generators, 91 and 100.
A number with no generators is a self-number. There are thirteen self-numbers less than 100:
1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97.
Create a sub procedure that lists all self-numbers less than 200.

VII. NumberChains (40pts)


Given a number, we can form a number chain by
1. arranging its digits in descending order
2. arranging its digits in ascending order
3. subtracting the number obtained in (2) from the number obtained (1) to form a new
number
4. and repeat these steps unless the new number has already appeared in the chain
Note that 0 is a permitted digit. The number of distinct numbers in the chain is the length of the
chain. You are to write a program that reads numbers and outputs the number chain and the
length of that chain for each number read.
Assume that the input is (data type: LONG).
Write a sub procedure that outputs the number chain for a number.
Sample Input

Output

123456789

123456789
864197532
864197532

1234

1234
3087
3582
6174
6174

444

444
0
0

Additional Explanation:
Original number was 123456789
987654321 - 123456789 = 864197532
987654321 - 123456789 = 864197532
Original number was 1234
4321 - 1234 = 3087
8730 - 378 = 8352
8532 - 2358 = 6174
7641 - 1467 = 6174
Original number was 444
444 - 444 = 0
0-0=0

Вам также может понравиться