In that case, maybe we could just get rid of the helper function and just write:
g (t:u:v:w:[]) = t*u*v*w
g (t:u:v:w:ws) = max (t*u*v*w) (g (u:v:w:ws))
By the way, what make you think that mutual recursion would use more
stack space than single recursion?
Oscar
On Tue, Aug 30, 2011 at 7:19 PM,
Very interesting. But for my taste I would do a cosmetic change. I
tend to find it more readable when function calls are written
vertically when they have with a great number of parameters or a lot
of parens like here.
listof4tuples xs = zip4
xs
(tail xs)
You also don't need mutual recursion for this explicit recursion since
I imagine it would use up more stack space.
-- Doing the one dimensional case.
f011 :: [Int] -> Int
f011 (t:u:v:xs) = f011helper t u v xs
f011helper :: Int -> Int -> Int -> [Int] -> Int
f011helper t u v (w:ws)
| ws == []
You might like this zipping & folding version.
Explicit recursion has the disadvantage that one has to read the
entire function in order to figure out what's going on; whereas using
the higher order functions makes things much easier to grasp.
listof4tuples xs = (zip4 xs (tail xs) (tail (tail xs)
On Monday 29 August 2011, 00:56:52, KC wrote:
> I just noticed that the 20x20 grid has some "00" entries; thus, time
> could be saved by not touching any of the grid entries 3 cells away.
> Same for the "01" entries.
>
> The challenge, of course, is in finding these entries in the first
> place. :
I just noticed that the 20x20 grid has some "00" entries; thus, time
could be saved by not touching any of the grid entries 3 cells away.
Same for the "01" entries.
The challenge, of course, is in finding these entries in the first place. :)
On Sun, Aug 28, 2011 at 1:58 PM, KC wrote:
> Try some
Try something like the following:
-- Project Euler 11
-- In the 20×20 grid below, four numbers along a diagonal line have
been marked in red.
--
-- The product of these numbers is 26 × 63 × 78 × 14 = 1788696.
-- What is the greatest product of four adjacent numbers in any
direction (up, down,
Think of the simplest version of the problem that isn't totally trivial.
e.g. A one dimensional list of numbers.
What would you do?
Note: you only want to touch each element once.
The 2 dimensional case could be handled by putting into lists: rows,
columns, major diagonals, and minor diagonals.
On Saturday 27 August 2011, 17:31:41, Oscar Picasso wrote:
> As a side note, my domain name is not oscarpicasso.com. It was already
> taken by someone else so I decided to use opicasso.com
Oh, yeah, it was that I allowed, misremembered the domain name.
Daniel,
Thank you very much for your comments, there are very useful, indeed.
As a side note, my domain name is not oscarpicasso.com. It was already
taken by someone else so I decided to use opicasso.com
Oscar
On Sat, Aug 27, 2011 at 11:05 AM, Daniel Fischer
wrote:
> On Saturday 27 August 2011,
On Saturday 27 August 2011, 16:03:46, Oscar Picasso wrote:
> Daniel,
>
> There are included as gists on the link provided. After your remark, I
> looked at the generated html code in my blog. The gists are actually
> displayed by running a javascript.
> Maybe your browser settings don't allow to d
Daniel,
There are included as gists on the link provided. After your remark, I
looked at the generated html code in my blog. The gists are actually
displayed by running a javascript.
Maybe your browser settings don't allow to display them.
If so, you can also look directly at the gists:
pb 01: ht
On Saturday 27 August 2011, 02:34:24, Oscar Picasso wrote:
> Hi,
>
> I order to improve my Haskell skills I started (again) to solve the
> project euler problems with this language.
> I am now at problem 11 and would really appreciate any comment about
> my code in order to make it more elegant or
Is Problem 11 the 4 consecutive #'s problem?
If so what must be true for 4 #'s to have a large product?
Hint: x * y * z * 2 is that going to be larger?
--
--
Regards,
KC
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/ma
Hi,
I order to improve my Haskell skills I started (again) to solve the
project euler problems with this language.
I am now at problem 11 and would really appreciate any comment about
my code in order to make it more elegant or efficient.
My solutions can be found here: http://fp.opicasso.com/tag
15 matches
Mail list logo