[Haskell-beginners] Bug in solution for problem 19
Nicolás Hertzulis
nicohertzulis at gmail.com
Thu Nov 19 08:57:37 UTC 2015
The penultimate solution for problem 19 of Ninety-Nine Haskell Problems
<https://wiki.haskell.org/H-99:_Ninety-Nine_Haskell_Problems> is giving the
result for the opposite of the given N.
e.g. rotate "abcdefgh" (-3) gives the result for rotate "abcdefgh" 3
Here's the problem https://wiki.haskell.org/99_questions/11_to_20 and the
solution https://wiki.haskell.org/99_questions/Solutions/19
I think it could be solved like this:
rotate xs n
| n <= 0 = (reverse . take (negate n) . reverse $ xs) ++ (reverse .
drop (negate n) . reverse $ xs)
| n > 0 = (drop n xs) ++ (take n xs)
I know it's not great, just keeping the spirit of the original solution
Is this the right list for reporting this kind of bugs?
Nicolás
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151119/4c06b2be/attachment.html>
More information about the Beginners
mailing list