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

Re: Golf Challenge - does $x and $y fit into the same slot on @z?

by sauoq (Abbot)
on Dec 28, 2002 at 01:39 UTC ( [id://222665]=note: print w/replies, xml ) Need Help??


in reply to Golf Challenge - does $x and $y fit into the same slot on @z?

I hate to spoil the party here but all of the solutions thus far fail on one or more boundary condition.

I suggest adding two test cases:

$x = 1; $y = 2; @z = (0, 1);
and
$x = 0; $y = -1; @z = (0, 1);

It is possible that the specification was poorly written but, as it is stated, there is no mention of cases where $x and/or $y are equal to a number in the array. It stands to reason that the safe assumption is that such condition should be considered a failure condition. At the very least, it should be handled consistently. All of the current solutions handle it differently depending on which end of the array the equality occurs at.

Take, for example, the first test I proposed above: $x = 1; $y = 2; @z = (0, 1);. In that case, it obviously not true that $x and $y are between the same numbers in @z. It is also not true that they are both less than all the numbers in @z. Finally, since $x is equal to the last element in @z, it is not true that they are both greater than all elements in @z.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^2: Golf Challenge - does $x and $y fit into the same slot on @z?
by Aristotle (Chancellor) on Dec 28, 2002 at 01:43 UTC
    I hate to spoil the party here but all of the solutions thus far fail on one or more boundary condition.
    Liar! Admit it, you thoroughly enjoyed that one. Don't you try to hide that smug look on your face from me. ;-)

    Makeshifts last the longest.

Re: Re: Golf Challenge - does $x and $y fit into the same slot on @z?
by BrowserUk (Patriarch) on Dec 28, 2002 at 01:54 UTC

    Erm. Isn't that covered by the bit that says:

    #When determining "betweeness", treat any cases where $x or $y equals a value in @z as if $x or $y was actually less than that value.
    ?

    By my (probably flawed) reading of that, your first case would be a fail because the $x would be judged less than the second element of @z

    And the second case would be a pass as both $x and $y would be judges as being lower than the first valeue of @z


    Examine what is said, not who speaks.

      Erm. Isn't that covered by the bit that says

      Hrm. It's a debatable point, I suppose.

      It explicitly states that that should be the strategy when determining "betweeness" whereas the example test cases I gave were those dealing with "greater than" or "less than" all the numbers in the array. I'm wavering more toward the poorly stated specification option now, though.

      -sauoq
      "My two cents aren't worth a dime.";
      

        Understood. I took it to be a "fenceposts" problem

        • -infinity < ($x & $y) <= $z[0]
        • $zn < ($x & $y) <= $zn+1
        • $z-1 < ($x & $y) <= +infinity

        but now you have pointed out an alternative reading, I can see the ambiguity.

        20:20 vision in hindsight :^)


        Examine what is said, not who speaks.

        I'm wavering more toward the poorly stated specification option now, though.

        You're probably right, although BrowserUk did have the correct interpretation.

        It was my first golf challenge ever. If I ever get the courage to post another one, I will be sure to be more clear. Although, I have the feeling that no matter How clear I make it, there will always be somebody that will find a loophole.

      Yes, you are correct.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-16 22:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found