指数增长一线功能在一个测试中失败,而其他测试却没有失败?

发布于 2025-01-25 02:56:34 字数 558 浏览 1 评论 0原文

有人可以为我调试吗?我一直盯着它并测试了几个小时,但似乎无法正常工作。我开始怀疑编码挑战Web应用程序是否错了,我是对的!

任务是:

找到人口p0超过最大总体p的世代数量,鉴于人口增加了>>>>%%>%加上AUG每一代

如下:

nbYear = (p0, percent, aug, p) => {
  return Array(999).fill().filter((_,i)=>Array(i+1).fill().map((_,j)=>j==0?p0:0).reduce((y,_)=>Math.round(y*percent/100+y+aug))<=p).length;
}

我编写的代码通过100个测试,但在一个测试中失败(他们没有透露失败的输入参数)。它说的只是该函数给出了输出:51应该是50

Can anyone debug this for me? I've been staring at it and testing things for hours but can't seem to get it working. I'm starting to wonder whether the coding challenge web app is wrong and I'm right!

The task is this:

Find the number of generations it would take for a population p0 to surpass a max population p given that the population increases by percent% plus aug every generation

My one-liner is as follows:

nbYear = (p0, percent, aug, p) => {
  return Array(999).fill().filter((_,i)=>Array(i+1).fill().map((_,j)=>j==0?p0:0).reduce((y,_)=>Math.round(y*percent/100+y+aug))<=p).length;
}

The code I've written passes on 100 tests but fails on one in particular (they don't disclose the input paramters on which it failed). All it says is that the function gave the output: 51 when it should have been 50

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

峩卟喜欢 2025-02-01 02:56:35

我得出的结论是,失败的一个测试一定是以超过999的价值来进行的。

I've concluded that the one test for which it failed must have been for a value over 999.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文