in reply to Re^11: Challenge: Number of unique ways to reach target sum
in thread Challenge: Number of unique ways to reach target sum

fergal,
I had a copy/paste error which was the source of a whole lot of problems originally. I left j as type double and updated the printf() format as ".0f" but your way works too. I also had a missing hyphen from -fomit-frame-pointer which I corrected.

I have run this code on my machine and it finished in 53.5 minutes. I am not really shocked by this but I am impressed. The only optimizations the C code attempts to make is by limiting the number of the 17 trillion different sets it visits. Adding in a cache and some other neat doo-dads could probably blow this 53.5 minutes out of the water - but why bother. That is one of the beauties of Perl. The amount of time it would take to devise a C program to beat the Perl is more than time than it takes the Perl to run. Good Job.

Cheers - L~R

  • Comment on Re^12: Challenge: Number of unique ways to reach target sum

Replies are listed 'Best First'.
Re^13: Challenge: Number of unique ways to reach target sum
by fergal (Chaplain) on Feb 16, 2006 at 20:29 UTC

    Yeah, I thought about rewriting in C, maybe using glib to get nice hashes and strings. Memory usage would be way smaller and it would be way faster but it wouldn't be much fun to write :)

    I just got

    fergal@anacreon:~$ time ./lr 14479062751 real 76m17.183s user 75m32.075s sys 0m0.764s fergal@anacreon:~$ time perl make_ways.pl 14479062752 real 37m46.569s user 37m26.124s sys 0m1.416s

    That's without -march=... and -fomit-doodads.