解决未知指数

时间:2019-06-14 21:02:25

标签: javascript

我正在尝试创建一个函数,该函数创建一个指数级增长的数字列表,其中数字的总和等于某个最大值。

例如:

/*
* What do I have to raise N by in order for the sum to be 40
*/

(1**x + 2**x + 3**x + 4**x + 5**x) === 40;

/*
* Wolframalpha tells me: x = 1.76445
* But how can I solve with JS.
*/ 
function listOfNumbers(n, maxSum) {
  // implementation
}

var result = listOfNumbers(5, 40);
/*
 * result === [1, 3.397..., 6.947..., 11.542...,  17.111...]
 * 
*/

result.reduce((acc, n) => acc += n) === 40

1 个答案:

答案 0 :(得分:0)

尝试https://en.wikipedia.org/wiki/Bisection_method

$ /home/qa/start_vms.sh 
VBoxManage: error: Machine 'QAT-116-sonarsql-test-virtualbox' is not currently running
Waiting for VM "QAT-116-sonarsql-test-virtualbox" to power on...
VM "QAT-116-sonarsql-test-virtualbox" has been successfully started.
VBoxManage: error: Machine 'QAT-116-oracle12' is not currently running
Waiting for VM "QAT-116-oracle12" to power on...
VM "QAT-116-oracle12" has been successfully started.
VBoxManage: error: Machine 'QAT-116-finder-tests_oori' is not currently running
Waiting for VM "QAT-116-finder-tests_oori" to power on...
VM "QAT-116-finder-tests_oori" has been successfully started.
$ vboxmanage list runningvms
"QAT-116-sonarsql-test-virtualbox" {a0d929e0-8556-4d22-ab99-5deff7d25462}
"QAT-116-oracle12" {b5d58758-8925-4780-9037-604b6f9a4185}
"QAT-116-finder-tests_oori" {4c1d84f9-fd3e-4398-a46e-ec592411c66c}
$