Search

FizzBuzz

Here's a quick XQuery solution to the FizzBuzz problem posed in David Patterson's blog.

I've taken the liberty of splitting the hyphenated string into two attributes.

let $config :=<fizzbuzz><range min="1" max="100"/><test>   <mod value="3" test="0">Fizz</mod>   <mod value="5" test="0">Buzz</mod></test></fizzbuzz>for $i in ($config/range/@min to $config/range/@max)let $s :=  for $mod in $config/test/mod      return         if ($i mod $mod/@value = $mod/@test)         then string($mod)         else ()returnif (exists($s))then string-join($s,' ')else $i