Thank you, Roger, for your insightful solution! Your new solution runs
in about 9 secs, compared to 36 secs.

2007/2/4, Roger Hui <[EMAIL PROTECTED]>:
Even if a program is going to be run just once or
a problem is already solved there is satisfaction
in doing it well for oneself.  The pursuit of Truth
and Beauty makes life worth living.  Better than
watching the Super Bowl, for instance.



Yes, indeed.

In the process I may find some paradigms of programming, as Robert Floyd did[0]:

<quote>
In my own experience of designing difficult algorithms, I find a
certain technique most helpfult in expanding my own capabilities.
After solving a challenging problem, I solve it again from scratch,
retracing only the insight of the earlier solution. I repeat this
until the solution is as clear and direct as I can hope for. Then I
look for a general rule for attacking similar problems, that would
have led me to approach the given problem in the most efficient way
the first time. Often, such a rule is of permanent value. ...... The
rules of Fortran can be learned within a few hours; the associated
paradigms take much longer, both to learn and to unlearn. --Robert W.
Floyd
</quote>

And as George Polya, from his excellent book How to Solve It, said:

<quote>
Even fairly good students, when they have obtained the solution of the
problem and written down neatly the argument, shut their books and
look for something else. Doing so, they miss an important and
instructive phase of the work. ... A good teacher should understand
and impress on his students the view that no problem whatever is
completely exhausted. --George Polya
</quote>

Dijkstra always said he seeks beauty, and we should do so[1]. Donald
Knuth explicitly said "a programmer who subconsciously views himself
as an artist will enjoy what he does and will do it better."[2]

[0] http://www.iisc.ernet.in/academy/resonance/May2005/pdf/May2005Classics.pdf
(Robert Floyd's Turing Award Lecture)
[1] http://www.amazon.com/exec/obidos/ISBN=0387972994/ (Beauty is Our Business)
[2] http://fresh.homeunix.net/~luke/misc/knuth-turingaward.pdf (Don
Knuth's Turing Award Lecture)




----- Original Message -----
From: Devon McCormick <[EMAIL PROTECTED]>
Date: Saturday, February 3, 2007 11:22 am
Subject: Re: [Jprogramming] Collatz Problem again

> June -
>
> how many times do you plan to solve the problem or do you plan to
> extend the search?
>
> I'm asking because I just wrote "collatz" myself for the
> projectEuler math
> challenge. My version, which I wrote in less than 5 minutes, took
> about1350 seconds to complete for the first million integers.
> Obviously,Roger's version is far faster.
>
> However, I may never run this code again.
>
> I looked at one of the discussion groups on the math challenge site
> and, typically, much of the talk was about shaving seconds off an
> implementation of code to solve one of the problems.
>
> I still fail to grasp the economics of spending hours of one's own,
> irreplaceable time to save seconds of processing time, especially
> for one-shot solutions and especially since I can do other things
> in the 1300 seconds I "waste" by not running faster code.
>
> Apologies to long-time readers of this forum for this re-iteration
> of my standard rant, number one on the list, but it continues to be
> relevant.
>
> Just to point out the benefits of coding quickly and
> inefficiently, in the
> few days since I got interested in this math challenge, I've
> gotten my
> ranking up to around 380 out of 2089, so I've passed about 1700
> people.
> Not to brag: I owe it to J and a little of it to advance peeks at
> some of the problems people have asked about on the forum.
>
> I probably should really be embarrassed that I'm gaining on people
> in a race where most of them are crawling, wearing boxes on their
> heads and dragging chains.
>
> So, I'm unwilling to spend more than a few minutes to improve on a
> solution, especially one that Roger wrote.  However, his essay on the
> solution is worthwhile, especially for the notion of caching
> results, as
> this has general applicability and may be a time-saver in the future.
>
> Good luck,
>
> Devon
>
> On 2/3/07, June Kim <[EMAIL PROTECTED]> wrote:
> >
> > Have a look at this problem:
> >
> > http://www.programming-
> challenges.com/pg.php?page=downloadproblem&probid=110101&format=html>
> > In short, you need to calculate the maximum cycle length in a
> given range.
> >
> > Roger wrote an essay which is related to this problem.
> > http://www.jsoftware.com/jwiki/Essays/Collatz_Conjecture
> >
> > Suppose we want to calculate the maximum cycle length of collatz
> > sequences for 1, ..., 1e6.
> >
> > It would be defined, using Roger's definition, as >./ cn 1e6
> >
> > It currently takes around 40 secs on the computer I'm using.
> Could you
> > improve its efficiency?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to