Answered step by step
Verified Expert Solution
Link Copied!

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 2: SEND MORE MONEY! [60 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:
SEND+MORE=MONEY
Here, it is understood that each letter represents a unique digit (0 to 9) and no two letters share the same
digit.
For instance, consider the following mapping:
Using this mapping, SEND represents 9567, MORE represents 1085, and MONEY represents 10652. This is
correct because 9567+1085=10652.
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 2A: Does it work? [15 marks]
First, we will try to find if a given mapping is valid. There are 2 criteria that determines if a mapping is valid.
The first digit of a word cannot be 0
The addition result must be correct
Write a function check(puzzle, 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 2 elements. For a n-sized tuple, the first (n-1)
elements are words that are to be added together, and the n-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 (i.e., the mapping)
CS1010E Assignment 3
AY2022/2023, Special Term 2
Else, return False Part 2B: Unique Letters [10 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 unique_letters(puzzle) 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 2 elements. For a n-sized tuple, the first (n-1)
elements are words that are to be added together, and the n-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:('D','Y','S','N','R','E','M','O') Part 2C: Exploring the possibilities [25 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 assign(letters, numbers_left, 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 1:
This means that for the puzzle A+B=C, which I have decided that A=2, I still need to assign some
numbers to " B " and "C" to satisfy the puzzle, where they could either take up the values 5,6 or 8
In this case, the algorithm will determine correctly that B can be 6,C can be 8 and hence return {?''A'':2,
"B":6,"C": 8}
Example 2:
This means that for the puzzle A+B=C, which I have decided that A=1,1 still need to allocate "B" and
" C ", where they could either take up the values 2,4,6 or 8
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 2D: Putting it together [10 marks]
Nice! Now that we have all the functions required, we can solve the cryptic message we received.
Given the 3 functions defined earlier, write a function solve(puzzle) 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:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

Students also viewed these Databases questions