$35
COSC 326
Repeated digits
When we write numbers down some (e.g., 11) have repeated digits, and others (e.g., 12)
don’t. Of course if we change the base in which we’re writing numbers then that can
affect whether or not a number has repeated digits. For instance, the decimal number
11:
Base Number Repeat
2 10112 Yes
3 2023 Yes
4 234 No
. . . . . . . . .
9 129 No
10 1110 Yes
Task
• In base b is there a largest number without repeated digits? If so, what is it?
• Write a program which carries out the following two tasks:
A. Given a base b and an integer n finds the longest block of integers all having
repeated digits in base b that are less than n. The output should be the first
integer of the block (in normal decimal representation) and the length of the
block (if there is more than one block of the same length, the first one should
be given.)
B. Given two bases, b and c, finds the smallest integer n which has repeated
digits in both bases.
Input will be in a series of lines from stdin. A properly formatted line will
consist of the letter A or B, followed by whitespace, followed by two numbers
separated by whitespace. Output should be to stdout. If a line is properly formatted just the answer for that type of question should be given in a single line.
If a line is improperly formatted then output should be the text “Bad line: ”
followed by the improperly formatted line exactly as read.
Submit an answer (and justification) for the first part and your program for the second
part.
Relates to Objectives
1.2, 1.4, 2.2, 2.7, 3.1, 3.5.
COSC 326 2022 Summer School Étude 1
(Individual)