Question: Imagine a future generation communicating via an emoji - based language. They can also do some basic math with the same language. Consider the following

Imagine a future generation communicating via an emoji-based language. They can also
do some basic math with the same language. Consider the following example:
Our goal is to interpret this particular mysterious addition operation given in above figure. More specifically, given the two emojicexpressions
as summands and their addition result as another emojic-expression above, we would like to assign a different digit to
each emoji in the emojic-expressions (in the two summands and the summation result), without leading zeros (i.e., the first digit of
each number, the couple and family emojis in the above example, cannot be zero), such that the summation in our decimal system
is correct. An example solution is as follows:
4
1 import itertools
2 function EnumerateOrderedDigits(int n):
3 return list(itertools.permutations(range(10),n))
4 function SolveMyEmojiPuzzle():
5 Emojis =[couple,family,heart,smiley,dog,cat]
6 OrderedDigits = EnumerateOrderedDigits(6)
7 OrderedDigits =[od for od in OrderedDigits if od[0]!=0 and od[1]!=0]
8 List_of_EmojiDigitAssignments =[dict(zip(Emojis,od)) for od in OrderedDigits]
9 Solutions =[]
10 for assignment in List_of_EmojiDigitAssignments:
11 if assignment correctly solves the puzzle:
12 Add (summand,summation result) to Solutions
13 # E.g., we should have (765,1530) in Solutions
14 return Solutions
(a) Implement the algorithm provided as in the pseudocode above. Note that emoji has all lowercase letters. Your function should
return list of all the solutions stored as tuple of strings in the format (3-digit-number,3-digit-number, corresponding-sum).
Sample function call and expected inputs/outputs are provided below.
1 emoji_solutions = SolveMyEmojiPuzzle() # emoji_solutions is a list of tuples of strings
2 # emoji_solutions =[(734,734,1468),(765,765,1530),...] code in python

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!