Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re^3: Odd Ball Challenge by kaif
in thread Odd Ball Challenge by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-23 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found