You need to sign in or sign up before continuing.×
6 kyu
Sum and Product of Three Numbers
133CheeSenTan
Description:
Problem
Given positive integers a
and b
, we want to write a function that calculates the number of possible sets (x, y, z)
of positive integers `x ≤ y ≤ z such that:
x + y + z = a
x * y * z = b
Note that each set (x, y, z)
is unique up to permutation. (E.g. if x = y
, then (x, y, z)
and (y, x, z)
count as one and the same solution)
Examples
If a = 19
and b = 144
, then the solutions are (2, 8, 9)
and (3, 4, 12)
, because:
2 + 8 + 9 = 3 + 4 + 12 = 19
2 * 8 * 9 = 3 * 4 * 12 = 144
If a = 39
and b = 1200
, then the solutions are (4, 15, 20)
, (5, 10, 24)
and (6, 8, 25)
, because:
4 + 15 + 20 = 5 + 10 + 24 = 6 + 8 + 25 = 39
4 * 15 * 20 = 5 * 10 * 24 = 6 * 8 * 25 = 1200
Therefore, we want a function that:
number_of_sets(19, 144) = 2 #(2, 8, 9) and (3, 4, 12)
number_of_sets(39, 1200) = 3 #(4, 15, 20), (5, 10, 24) and (6, 8, 25)
Fundamentals
Similar Kata:
Stats:
Created | Jan 27, 2021 |
Published | Jan 27, 2021 |
Warriors Trained | 434 |
Total Skips | 44 |
Total Code Submissions | 360 |
Total Times Completed | 133 |
Python Completions | 133 |
Total Stars | 9 |
% of votes with a positive feedback rating | 85% of 48 |
Total "Very Satisfied" Votes | 37 |
Total "Somewhat Satisfied" Votes | 8 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 29 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |