Batman is an atypical "superhero". Unlike Spider-man, Batman has no special powers (unless you count being filthy rich a superpower). That said, he is, for better or worse, greatly respected for being a crime-fighter by his many fans. Despite his dour demeanor, Batman at times displays moments of humor and periodically manifests his modest intellect.
In this programming challenge, Batman is locked in a battle of wits with the Riddler. Once again, the green supervillain has a mind-bending, brain-teasing challenge for the masked avenger:
Find all the pairs of
5
-digit numbers that use the digits0
through9
once each, such that the first number divided by the second is equal to some integerN
, whereN
is between2
and100
(inclusive).
That is, given the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
and a number N
,
find all permutations of these digits such that:
abcde / fghij = N
where each letter represents a different digit. The first digit of one of
the numerals is allowed to be 0
.
Because Batman lacks any significant superpower (besides money), he begs that you help him defeat the Riddler by using your programming superpowers.
Each line of input consists of a valid integer N
. An input of 0
terminates the program (no output should be displayed for it).
61 62 0
The program should display ALL pairs of numerals that match the description above. The numerators should be sorted by increasing numerator and denominator and displayed in the following format:
XXXXX / XXXXX = N XXXXX / XXXXX = N ...
If there are no pairs of numerals satisfying the atypical division condition, then the program should display: "There are no solutions for N".
Separate the output for two different values of N
by a blank line.
There are no solutions for 61. 79546 / 01283 = 62 94736 / 01528 = 62
This is based on the Division problem on the UVa Online Judge.
To submit your work, follow the same procedure you used for Reading 00:
$ cd path/to/cse-30872-fa18-assignments # Go to assignments repository $ git checkout master # Make sure we are on master $ git pull --rebase # Pull any changes from GitLab $ git checkout -b challenge07 # Create and checkout challenge07 branch $ $EDITOR challenge07/program.cpp # Edit your code $ git add challenge07/program.cpp # Stage your changes $ git commit -m "challenge07: done" # Commit your changes $ git push -u origin challenge07 # Send changes to GitLab
To check your code, you can use the .scripts/submit.py
script or curl:
$ .scripts/submit.py Submitting challenge07 assignment ... Submitting challenge07 code ... Result Success Score 6.00 Time 3.97 $ curl -F source=@challenge07/program.cpp https://dredd.h4x0r.space/code/cse-30872-fa18/challenge07 {"score": 6, "result": "Success"}
Once you have commited your work and pushed it to GitLab, member to create a merge request. Refer to the Reading 04 TA List to determine your corresponding TA for the merge request.