<div dir="ltr">Is it successively appending? My intention was to prepend. If it's appending, Is that because the ++ operator always evaluates its left argument first, then its right one?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 6, 2015 at 2:42 PM, David Feuer <span dir="ltr"><<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><p dir="ltr"><br>
On Feb 6, 2015 3:41 PM, "Jeffrey Brown" <<a href="mailto:jeffbrown.the@gmail.com" target="_blank">jeffbrown.the@gmail.com</a>> wrote:<br>
><br>
> Here's a solution:<br>
> lastDigit x = mod x 10<br>
> remainingDigits x = (x - lastDigit x) `div` 10<br>
> listDigits x<br>
>   | x < 10 = [x]<br>
>   | otherwise = (listDigits $ remainingDigits x) ++ [lastDigit x]<br>
><br>
> Here's a faster one:<br>
> listDigits2 x<br>
>   | x < 10 = [x]<br>
>   | otherwise = (listDigits $ remainingDigits) ++ [lastDigit]<br>
>   where lastDigit = mod x 10<br>
>         remainingDigits = (x - lastDigit) `div` 10</p>
</span><p dir="ltr">These give somewhat peculiar results when the argument is negative. That can be rectified, of course. Unfortunately, all of these proposed solutions have a serious performance problem: successively appending single elements to build a list of length n is O(n^2). There's an easy fix, which I'll let you come up with.</p><span class="HOEnZb"><font color="#888888">
<p dir="ltr">David</p>
</font></span></blockquote></div><br></div>