Fibonacci序列 - PHP最短代码(Fibonacci Sequence - PHP shortest code possible)
我花了一些时间尝试将Fibonacci序列执行到500个数字并以尽可能短的代码输出到屏幕。 这对我来说是一次学习练习。
我把它从21行压缩到12行,这是我能编写的最短代码,这使得这个工作..任何人都可以告诉我如何使代码更短?
我已经在google上查找了PHP循环,而while循环似乎效果最好。 PHP中是否还有其他数学技巧可以用来压缩这个?
通常当我问一个问题时,我喜欢展示我对这个问题所做的研究,但由于我不知道任何关键字要查找更好的数学或循环,我不知道该搜索什么...
码:
$counter = 0; $first = 1; $second = 1; echo $first."<br/>"; echo $second."<br/>"; while ($counter < 500) { $next = $first + $second; echo $next."<br/>"; $counter++; $second=$first; $first=$next; }
I have spent some time trying to execute the Fibonacci sequence to 500 numbers and output to screen in the shortest amount of code possible. This was a learning exercise for me.
I have condensed it from 21 lines down to 12, this is the shortest code I can write that makes this work.. Can anyone show me how I could have made the code even shorter?
I have looked on google for PHP loops, and the while loop seemed to work best. Are there any other math tricks in PHP I can use to condense this even more?
Normally when I ask a question, I like to show what research I have done into the problem, but since I don't know any keywords to look up for better math or loops, I am not sure what to search..
Code:
$counter = 0; $first = 1; $second = 1; echo $first."<br/>"; echo $second."<br/>"; while ($counter < 500) { $next = $first + $second; echo $next."<br/>"; $counter++; $second=$first; $first=$next; }
原文:
最满意答案
我们发现了这个问题。 使用单字符参数定义URI参数存在问题。 作为解决方法,请使用不同的参数定义您的资源。 例如:/ client / calculate / add / {xx} / {yy}
此外,您必须将资源的“Produces”属性设置为“application / xml”,因为默认值为“application / json”,并且不受后端支持。
请参考下面的截图并定义您的API资源,并重新发布API。
We found the issue. There is a problem with defining URI params with single-character parameters. As a workaround, please define your resource with different parameters. Ex: /client/calculate/add/{xx}/{yy}
Also, you have to set the "Produces" attribute for the resource as "application/xml" since the default value is "application/json" and is not supported by your backend.
Please refer the screenshot below and define your API resource, and republish the API.
相关问答
更多-
WSO2 AM培训文档问题(WSO2 AM Training Doc Issue)[2022-04-06]
网址中的版本应为v0.10 http://localhost:9763/client-registration/v0.10/register Version in the URL should be v0.10 http://localhost:9763/client-registration/v0.10/register -
如果您想将WSO2 IS配置为关键管理器,则可以在WSO2文档中找到所有详细步骤https://docs.wso2.com/display/CLUSTER44x/Configuring+the+Identity+Server+5.2.0+as+a+键+管理+与+ API +管理+ 2.0.0 If you want to configure WSO2 IS as an keymanager all the detailed steps can be found in WSO2 doc https://doc ...
-
WSO2IS可以用作身份提供者。 在这种情况下,是的,它将负责验证用户(有很多方法可以做到这一点,您可以选择适合您需求的方法)。 它可以使用任何SSO协议,如SAML,OpenID Connect等等。 是的,这是我认为最常见的方法。 通常每个组织都有自己的用户信息存储区。 它可能是LDAP或RDBMS等。您可以将WSO2IS设置为接收认证请求,并让WSO2IS从该现有存储中认证用户。 WSO2IS can be used as a identity provider. In that case, yes ...
-
WSO2 API管理器 - 无法使用Sails发布基于Node的API(WSO2 API manager - Unable to publish API built on Node using Sails)[2023-08-24]
404表示资源不是资金。 你能看到你的请求URL是对的吗? Eg: http://localhost:8280/test/1.0 404 indicates that resource not fund. Can you cheek your request URL is right? Eg: http://localhost:8280/test/1.0 -
在云中部署WSO2 API?(Deploying WSO2 APIs in cloud?)[2024-01-22]
WSO2在云中具有API管理解决方案。 这是WSO2 API Cloud,它是WSO2 API Manager即服务。 您可以访问http://wso2.com/cloud/api-cloud/ ,注册并开始使用API Cloud。 您可以在https://docs.wso2.com/display/APICloud/WSO2+API+Cloud+Documentation找到API云的文档和教程。 WSO2 has a API Management solution in the cloud. Thats ... -
如果您只是想用OAuth2保护您的REST API,请使用WSO2 API Manager。 您可以按照快速入门指南开始。 有关添加API和启用OAuth2保护的详细信息,请参阅快速入门指南。 If you simply want to protect your REST API with OAuth2 use the WSO2 API Manager. You can follow the quick start guide to get started. Details related to addin ...
-
虽然你的突触配置不存在,但我会回答你的问题。 你可以这两种方式。 一种是使用Header Mediator。 你可以提供这个 Doc。 示例代码如下,
第二种方法是使用属性中介,您可以设置Header值并将范围设置为transport。 因此将添加Header属性。 您只需要将原始请求内容分配给属性,以便稍后使用。 有很多方法可以做到这一点,下面的例子是使用rich mediator ... -
云中有以下选项可用。 你仍然可以做IP白名单。 您可以请求将IP列入云支持频道白名单。 您可以使用API云和后端进行相互ssl 正如您所提到的,您可以发送一个自定义标题,其中包含一个来自API Cloud的秘密值,并从您的后端检查它 您也可以让API云将基本身份验证发送到您的后端 https://docs.wso2.com/display/APICloud/Secure+your+Backend+Services You have the following options available in the ...
-
WSo2 API Manager(WSo2 API Manager)[2022-07-11]
是的,WSO2 Identity Server功能安装在API Manager中。 如果您有一个单独运行的WSO2 Identity Server节点,它也可以充当密钥管理器 。 Yes, WSO2 Identity Server features are installed within API Manager. And if you have a WSO2 Identity Server node running separately, it can also act as the key manage ... -
WSO2 API云问题(WSO2 API Cloud Issue)[2022-10-10]
我们发现了这个问题。 使用单字符参数定义URI参数存在问题。 作为解决方法,请使用不同的参数定义您的资源。 例如:/ client / calculate / add / {xx} / {yy} 此外,您必须将资源的“Produces”属性设置为“application / xml”,因为默认值为“application / json”,并且不受后端支持。 请参考下面的截图并定义您的API资源,并重新发布API。 We found the issue. There is a problem with def ...