I want to solve a problem but I don’t know how to proceed.
In fact, I want to create the following function:
<?php
function xSumY(int $x, int $y)
{
$set = [];
//find $set {$a + $b + $c + ... ($x times)} which sum equal $y
}
//Examples
$set1 = xSumY(55, 1);
$set2 = xSumY(1, 20);
$set3 = xSumY(3, 10); //returns for example {1, 3, 6}
NOTE: If possible avoid repetition of given value
Thanks in advance for your help.
2
Answers
After several hours I got something like this:
I want to know if it's good or I'm missing something or if there is a way I can dot it better. Also, I wanted to know if this operation will not excessively consume the memory.
I don’t understand the need for all that code you used in your answer. I made this in five minutes:
and it seems to do the job.