Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Project Euler (a series of challenging mathematical/computer programming problems)

by Anonymous Monk
on Feb 11, 2006 at 21:36 UTC ( #529599=note: print w/ replies, xml ) Need Help??


in reply to Project Euler (a series of challenging mathematical/computer programming problems)

i'm pretty sure my answer for 112 is correct, but apparently it's not. anybody see anything wrong with this? it works fine for the two examples (.5->538, .9->21780).

my $max = .99; my $bouncy = 0; for (my $n=1; ; $n++) { my ($inc, $dec) = (0, 0); my @d = split //, $n; for (my $i=0; $i<@d-1; $i++) { if ($d[$i] < $d[$i+1]) { $inc++ } elsif ($d[$i] > $d[$i+1]) { $dec++ } } $bouncy++ if $inc and $dec; next if $max > $bouncy/$n; printf "n=%d: %%%f\n", $n, $bouncy/$n; last; }


Comment on Re: Project Euler (a series of challenging mathematical/computer programming problems)
Download Code
Re^2: Project Euler (a series of challenging mathematical/computer programming problems)
by hv (Parson) on Feb 11, 2006 at 23:59 UTC

    Even though I can't see it explicitly stated anywhere, I think the intention of the site is that you solve the problems on your own without asking for help.

    For what it's worth, while working through the problems I found that at least 75% of the time if my first attempt at an answer was wrong it was because I had misread the question rather than because I had a bug in my code.

    Hugo

Re^2: Project Euler (a series of challenging mathematical/computer programming problems)
by mpolo (Chaplain) on Feb 12, 2006 at 17:18 UTC

    Well, I don't think that directly helping would be "ethical", but for what it's worth I (and most of the successful coders from what I remember in the fora) did that one with a rather different approach. One helpful trick is to try the examples in the problem (just insert a print "helpful debugging stuff\n" if $n==number_with_known_property; and see if they get classified correctly by your program. Much more fun is number 113, which has a slick mathematical solution, or my methodical number-crunching solution...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://529599]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (14)
As of 2014-10-23 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls