id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

digit_matrix


In this puzzle you are asked to construct a matrix of digits (1 to 9) such that the product of each row and of each column matches the input given in the function call digit_matrix(rowproducts, colproducts). For example, digit_matrix([2, 12], [3, 8]) asks for a 2x2 matrix where the first row has the product 2 and the second row has product 12; the first column has product 3 and the second column has product 8. The matrix [[1, 2], [3, 4]] is a solution. If there are multiple solutions, just pick one; if there are no solutions, return None.


digit_matrix([2, 12], [3, 8]) → [[1, 2], [3, 4]]
digit_matrix([162, 200, 147, 140], [140, 150, 441, 72]) → [[1, 2, 9, 9], [5, 5, 1, 8], [7, 3, 7, 1], [4, 5, 7, 1]]
digit_matrix([10, 20, 30, 40, 50], [50, 40, 30, 20, 10]) → [[1, 1, 1, 2, 5], [1, 1, 2, 5, 2], [2, 5, 3, 1, 1], [5, 4, 1, 2, 1], [5, 2, 5, 1, 1]]

...Save, Compile, Run (ctrl-enter)

def digit_matrix(rowproducts, colproducts):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 680 Post-solution available

Copyright Nick Parlante 2017 - privacy