224k views
3 votes
Consider the following (infinite) sequence of letters:

ABACABADABACABAEABACABADABACABAGABACABADABACABAEABACABADABACABAHABACABA…
We may construct it using the following steps:
0. Begin with an (infinite) sequence of A’s:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA…
1. Replace every 2nd letter with B:
ABABABABABABABABABABABABABABABABABABABA…
2. Replace every 4th letter with C:
ABACABACABACABACABACABACABACABACABACABA…
3. Replace every 8th letter with D:
ABACABADABACABADABACABADABACABADABACABA…
4. Replace every 16th letter with E:
ABACABADABACABAEABACABADABACABAEABACABA…
… and so on until Z.
The construction includes 25 replacement steps (for letters B to Z). At step k, we replace every (2k
)th
letter in the sequence with the (k + 1)st letter of the alphabet.
Your task is to write a program that inputs a positive integer n and prints the first n letters of that
sequence. For example, if the input integer is 8, it prints “ABACABAD”.
Input and output: Your program in java should input an integer n between 1 and 1,000, and print the first
n letters of the sequence. It should print the sequence on one line, with no spaces, punctuation
marks, or line breaks.

User TheGecko
by
7.7k points

1 Answer

3 votes
I’m answering this because I need free answers to pass dearly?
User Nbwoodward
by
7.7k points