根据给定的 TestUnit 编写函数
我需要编写一个函数来满足这个输入 ->输出列表:
0 -> 0
1 -> 1
3 -> 2
4 -> 3
5 -> 5
7 -> 13
9 -> 34
f(x) = ??
I need to write a function to satisfy this input -> output list:
0 -> 0
1 -> 1
3 -> 2
4 -> 3
5 -> 5
7 -> 13
9 -> 34
f(x) = ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,这非常简单......如果您不担心过度拟合,那么您可以这样做:
如果您想要一个好的解决方案,您可能需要对问题进行更多限制。您还可以考虑绘制该函数的图形,以查看是否存在任何明显的模式,或者可能显示所涉及的位。了解输入和输出是整数值还是实值(函数应该是连续的还是离散的?)也很有用。如果没有这些信息,就很难提供帮助。
编辑
显示缺失的数字有帮助:
0 -> 0
1-> 1
2-> 1
3-> 2
4-> 3
5-> 5
6-> 8
7-> 13
8-> 21
9-> 34
(斐波那契数列:f(x) = f(x-1)+f(x-2),其中 f(0)=0 且 f(1)=1)。
PS
对于此功能,动态编程或记忆化特别有用。
Well, that is incredibly easy... if you aren't concerned about over-fitting, then you can do:
You probably need more constraints on the problem if you want a good solution. You also might consider graphing the function to see if there is any obvious pattern, or maybe show the bits involved. It would also be useful to know if the inputs and outputs are integer-valued or real-valued (is the function supposed to be continuous or discrete?). Without this information, it's a little bit hard to help.
Edit
Showing the missing numbers helps:
0 -> 0
1 -> 1
2 -> 1
3 -> 2
4 -> 3
5 -> 5
6 -> 8
7 -> 13
8 -> 21
9 -> 34
(It's the Fibonnaci numbers: f(x) = f(x-1)+f(x-2), where f(0)=0 and f(1)=1).
PS
This is a function for which dynamic programming or memoization is particularly useful.
由 Eureqa 解决
round(exp(0.4807*input - 0.799938))
Solved by Eureqa
round(exp(0.4807*input - 0.799938))
我不知道这是否是家庭作业,但这是一个非常著名的序列。一个(相当大的)提示是 f(n) 取决于 f(n-1) 和 f(n-2)。如果您不关心只是被告知答案,请单击此处。实现该序列是相当简单的递归完成,但如果您遇到问题,请编辑您的帖子并指定您陷入困境的部分
I don't know if this is homework or not, but this is an extremely well-known sequence. A (rather large) hint is that f(n) is dependent on f(n-1) and f(n-2). If you're not concerned with just being told the answer, click here. Implementing the sequence is pretty trivially done recursively, but edit your post if you're having trouble with it and specify which part you're stuck on