Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Odd Ball Challenge

by kaif (Friar)
on Jun 23, 2005 at 23:10 UTC ( [id://469558]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Odd Ball Challenge
in thread Odd Ball Challenge

I've thought about this particular problem before, and I wrote the kind of program you would like to see, in C++. It was challenging, and somewhat time-consuming, which is probably why no one has responded yet like that; I was going to simply translate my program to Perl, but I think I dropped it in the bit bucket.

I eventually generalized the problem and solved it mathematically, noticing that 12 == (3**3 - 1)/2 - 1. Thus, to me, this is an old case of the following: given the task "write a program to sum the numbers from 1 to $x" after learning about loops, does one write print $x*($x+1)/2 or

for $i ( 1 .. $x ) { $sum += $i; } print $sum;

So, I went the easier route and golfed in a relatively general way; my comparisons "2 9 11 12 <=> 3 5 6 8", etc., are not hard-coded (I could write a much shorter program otherwise) and the computation of the result is clever. I hope that this is okay. I understand your challenge, but I still think that the less-than-240-characters above is an accomplishment. Thank you for the clarification, though.

Replies are listed 'Best First'.
Re^4: Odd Ball Challenge
by Limbic~Region (Chancellor) on Jun 24, 2005 at 11:49 UTC
    kaif,
    I certainly didn't mean to imply I wasn't impressed - I am. I understand this isn't an easy problem and most monks will find it too much work to devote with no tangible reward. I just like to share the problems I think up because some monks do enjoy them immensly.

    Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-18 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found