Last active
December 31, 2015 14:08
-
-
Save CliffordAnderson/7997843 to your computer and use it in GitHub Desktop.
Fibonacci sequence in XQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| xquery version "3.0"; | |
| (: Fibonacci Sequence :) | |
| declare function local:fibo-numbers($num1 as xs:integer, $num2 as xs:integer, $limit as xs:integer) as xs:integer* { | |
| if ($limit > 0) then ($num1, local:fibo-numbers($num2, $num1 + $num2, $limit -1)) | |
| else $num1 | |
| }; | |
| declare function local:fibo-sequence($limit as xs:integer) as xs:integer* { | |
| local:fibo-numbers(0, 1, $limit) | |
| }; | |
| local:fibo-sequence(15) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See this XQuery Wikibook for more information about the Fibonacci algorithm in XQuery as well as how to time the difference between implementations.