Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Odd Ball Challenge

by Limbic~Region (Chancellor)
on Jun 23, 2005 at 22:09 UTC ( [id://469545]=note: print w/replies, xml ) Need Help??


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

kaif,
I think you misunderstood the challenge and wrote a solution to the riddle instead. You are supposed to start out not knowing how to solve the riddle and write code that tells you how. The bonus was to have the code smart enough to understand whatever it outputted and generate a solution (such as the one you provided).

Let me try and be clearer this time since it was likely my fault. You start out knowing only the rules of riddle. You right code that starts searching for combinations of groupings and weighings that keeps track of what knowledge it has gained along the way. Eventually it has enough information to say:

  • Split the 12 balls up into X groups of Y balls
  • First, balance group A against group B
  • If they balance do ....
  • If A is heavier do ....
  • etc, etc, etc

I am not real particular in how that information is conveyed but it would be really cool if once the code reaches its conclusion it is smart enough to understand its own output and also generate code to execute the steps.

Cheers - L~R

Replies are listed 'Best First'.
Re^3: Odd Ball Challenge
by kaif (Friar) on Jun 23, 2005 at 23:10 UTC

    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.

      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://469545]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-19 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found