Created
February 22, 2012 13:31
-
-
Save xquery/1885182 to your computer and use it in GitHub Desktop.
xquery impl of fizzbuzz - can you do faster or more elegant ?
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
| for $n in (1 to 100) | |
| let $fizz := if ($n mod 3) then () else "fizz" | |
| let $buzz := if ($n mod 5) then () else "buzz" | |
| return | |
| if ($fizz or $buzz) then concat($fizz,$buzz) else $n |
for $x in (1 to 100)
let $y := number($x mod 3 = 0) +2 * number($x mod 5 = 0)
return if($y =0) then $x else ('Fizz','Buzz','Fizz/Buzz')[$y]
Author
Dimitre Novatchev 2 interesting solutions have been added to the wiki page
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
faster but ugly...