Monday, March 19, 2007


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 :=
<range min="1" max="100"/>
<mod value="3" test="0">Fizz</mod>
<mod value="5" test="0">Buzz</mod>

for $i in ($config/range/@min to $config/range/@max)
let $s := for $mod in $config/test/mod
if ($i mod $mod/@value = $mod/@test)
then string($mod)
else ()
if (exists($s))
then string-join($s,' ')
else $i


M. David Peterson said...

Hi Chris,

re: [Not sure how to retain the indentation in this blog]

You *should* be able to use,


... code ...


which *should* take care of it (I add the emphasis on should, as I have no idea how blogspot handles additional inline markup)

re: your solution. This is great! Will add this to the Dev.AOL solution collection entry now.


chris wallace said...

Many thanks David - fixed.

M. David Peterson said...

Right on. Good to know that it works :)

For reference, I've added id's to each entries beginning paragraph. Your entry is @