
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 digits0through9once each, such that the first number divided by the second is equal to some integerN, whereNis between2and100(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-fa20-assignments # Go to assignments repository
$ git checkout master # Make sure we are on master
$ git pull --rebase # Pull any changes from GitHub
$ 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 GitHub
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 0.11
$ curl -F source=@challenge07/program.cpp https://dredd.h4x0r.space/code/cse-30872-fa20/challenge07
{"result": "Success", "score": 6, "time": 0.11480951309204102}
Once you have committed your work and pushed it to GitHub, remember to create a pull request and assign it to the appropriate teaching assistant from the Reading 04 TA List.