[Haskell-beginners] Haskell triangular loop (correct use of (++))

Silent Leaf silent.leaf0 at gmail.com
Mon Apr 11 02:45:01 UTC 2016


Ah, from that I gather I probably won't think about anything you wouldn't,
then ^^

But I'll try because it's fun anyway!
If dropping incessantly from the start of the list at each iteration is the
problem (is that it? or did I not understand correctly?), could we not
manage the problem with memoization, using a recursive function of the like:
f 1 = drop 1 xs
f n = drop 1 (f (n-1))
I can't be sure at all, so I'll ask: would haskell remember the result of
each f 1, f 2, f 3, instead of recalculating them all the time? it would
allow for only one "drop" operation per iteration, and i guess it's the
best we can get with the general path I tried... but it seems obvious from
you both messages, there must be better ones no matter what, efficiently
speaking. :P

it could be naive, but one way to manage mere lists of integral numbers,
would be to transform them into one big number, and instead of dropping, we
do integral divisions/recuperation of remainders. i bet *if* that's more
efficient, there's a library to do that already.

one only has to to write the number that serves as list as a juxtaposition
of n-sized clusters of digits, n being the biggest power of ten reached by
the biggest number of the list. smaller numbers, tha have not enough digits
could be written with zeroes to fill in the rest: "0010" for example, and
of course so as to not lose trailing zeroes of the number at the leftest,
one has to start (from the right) with the smaller numbers:
123...010...002001.
But who knows if it's really more efficient? I'd have a tendency to say,
arithmetic is just numbers, the computer can do it way quicker and with
much less memory, but maybe not.

Just an idea off the top of my head. I bet no matter the technique we use,
handling one big number could end up being faster than a big list, and with
the right set of functions, it could be just as easy, but i could be
totally wrong.
And if too big numbers are problematic, we can still attempt intermediary
solutions, like lists of clustered numbers ^^
Sorry for the stupid ideas, hopefully soon my wild imagination will be
better handled by what i'll learn when i get a little less newbie. :P
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160411/0d62a72f/attachment.html>


More information about the Beginners mailing list