Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part 2 : SEND MORE MONEY! [ 6 0 marks ] You recelved the following cryptic message ( which you have identified that it is
Part : SEND MORE MONEY! marks
You recelved the following cryptic message which you have identified that it is not a scam from your secret
agent partner, requesting you to send over some amount indicated by the following sum:
SENDMOREMONEY
Here, it is understood that each letter represents a unique digit to and no two letters share the same
digit.
For instance, consider the following mapping:
Using this mapping, SEND represents MORE represents and MONEY represents This is
correct because
In this task, your final goal is to determine what digit each letter represents, and hence the amount of
MONEY that your partner is requesting. To help you out with this problem, it will be split into various parts,
and you will get to consolidate these into a functional algorithm at the end. Part A: Does it work? marks
First, we will try to find if a given mapping is valid. There are criteria that determines if a mapping is valid.
The first digit of a word cannot be
The addition result must be correct
Write a function checkpuzzle mapping that takes in the puzzle as a tuple and the mapping as a dictionary
and returns the dictionary if it is a valid mapping, and False otherwise
Input:
puzzle of type tuple Contains a tuple of at least elements. For a sized tuple, the first
elements are words that are to be added together, and the th element is the result that it should
add up to
mapping of type dictionary Contains a dictionary where the key is the alphabet, and the value is
the corresponding integer.
Output:
If it is valid, return the dictionary ie the mapping
CSE Assignment
AY Special Term
Else, return False Part B: Unique Letters marks
Now, let us try to tackle the puzzle. We will first need to find out what are the alphabets that are present
within the puzzle.
Write a function uniqueletterspuzzle that takes in the puzzle as a tuple and returns a tuple of letters
present within the puzzle. The output should not contain any duplicated alphabets.
Input:
puzzle of type tuple Contains a tuple of at least elements. For a sized tuple, the first
elements are words that are to be added together, and the th element is the result that it should
add up to
Output:
A tuple of the unique elements within the puzzle. The ordering of the output does not matter
Examples:DYSNREMO Part C: Exploring the possibilities marks
Let us try to find a possible mapping for the puzzle. This may seem hard, but we will try to guide you
through the thought process so don't worry!
Given a sequence of alphabets within the puzzle and a sequence of numbers which we could match the
alphabets to write a function assignletters numbersleft, mapping, puzzle that will determine a
possible mapping that satisfies the puzzle, if it exists.
To better illustrate what each parameter is below are a few examples explained:
Example :
This means that for the puzzle which I have decided that I still need to assign some
numbers to B and C to satisfy the puzzle, where they could either take up the values or
In this case, the algorithm will determine correctly that B can be can be and hence return
B:C:
Example :
This means that for the puzzle which I have decided that still need to allocate B and
C where they could either take up the values or
In this case, there is no possible way of doing it and hence the algorithm will return False
Input:
letters tuple of characters the letters that have yet to be allocated a mapping
numbers left tuple of integers the numbers that can be mapped to the lettersPart D: Putting it together marks
Nice! Now that we have all the functions required, we can solve the cryptic message we received.
Given the functions defined earlier, write a function solvepuzzle that returns the corresponding
mapping. If the puzzle is not solvable, return False
Input:
puzzle tuple the addition puzzle as described in earlier parts
Output:
If the puzzle is solvable, return the final mapping
If it is not solvable, return False
Examples:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started