-
AlgebraMathematicsAlgorithmsLogic
Code def multiply(a, b): a,b = list(map(digits, [a,b])) res = [0 for _ in range(len(a+b)-1)] for i,n in enumerate(a): for j,m in enumerate(b): res[i+j] += n*m return res def digits(n): return list(map(int, str(n)))
Test Cases Test.assert_equals(multiply(123, 456), [4, 13, 28, 27, 18]); Test.assert_equals(multiply(42, 424), [16, 16, 20, 8]);
Output:
-
Code - def multiply(a, b):
#your codepass- a,b = list(map(digits, [a,b]))
- res = [0 for _ in range(len(a+b)-1)]
- for i,n in enumerate(a):
- for j,m in enumerate(b):
- res[i+j] += n*m
- return res
- def digits(n):
- return list(map(int, str(n)))
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}