# Lab 7 COMP9021 solution

\$19.99

Original Work
Category:

## Description

5/5 - (1 vote)

1 Obtaining a sum from a subsequence of digits
Writeaprogramthatpromptstheuserfortwonumbers,sayavailable_digitsanddesired_sum, and outputs the number of ways of selecting digits from available_digits that sum up to desired_sum. For instance, if available_digits is 12234 and sum is 5 then there are 4 solutions:
• one solution is obtained by selecting 1 and both occurrences of 2 (1+2+2=5); • one solution is obtained by selecting 1 and 4 (1+4=5); • one solution is obtained by selecting the ﬁrst occurrence of 2 and 3 (2+3=5); • one solution is obtained by selecting the second occurrence of 2 and 3 (2+3=5).
Here is a possible interaction:
\$ python question_1.py Input a number that we will use as available digits: 12234 Input a number that represents the desired sum: 5 There are 4 solutions. \$ python question_1.py Input a number that we will use as available digits: 11111 Input a number that represents the desired sum: 5 There is a unique solution \$ python question_1.py Input a number that we will use as available digits: 11111 Input a number that represents the desired sum: 6 There is no solution. \$ python question_1.py Input a number that we will use as available digits: 1234321 Input a number that represents the desired sum: 5 There are 10 solutions.
1
2 R Merging two strings into a third one
Say that two strings s1 and s2 can be merged into a third string s3 if s3 is obtained from s1 by inserting arbitrarily in s1 the characters in s2, respecting their order. For instance, the two strings ab and cd can be merged into abcd, or cabd, or cdab, or acbd, or acdb, …, but not into adbc nor into cbda. Write a program that prompts the user for 3 strings and displays the output as follows: • If no string can be obtained from the other two by merging, then the program outputs that there is no solution. • Otherwise, the program outputs which of the strings can be obtained from the other two by merging.
Here is a possible interaction: