Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by Aristotle (Chancellor)
on Dec 27, 2002 at 23:26 UTC ( [id://222645]=note: print w/replies, xml ) Need Help??


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

30
use strict; use Test::More q(no_plan); my @z = qw(1 3 27 38); my $x = shift(); my $y = shift(); my @test = ( [qw( 4 5) => 1], [qw( 0 -1) => 1], [qw(100 100) => 1], [qw( 10 27) => 1], [qw( 3 27) => 0], [qw( 0 100) => 0], ); sub bool { not not shift } for(@test) { my ($x, $y, $works) = @$_; is( # 1 2 3 #23456789012345678901234567890 ((grep$x<=$_,@z)==grep$y<=$_,@z), bool($works), "x=$x y=$y" ); } __END__ ok 1 - x=4 y=5 ok 2 - x=0 y=-1 ok 3 - x=100 y=100 ok 4 - x=10 y=27 ok 5 - x=3 y=27 ok 6 - x=0 y=100 1..6

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Golf Challenge - does $x and $y fit into the same slot on @z?
by ehdonhon (Curate) on Dec 27, 2002 at 23:41 UTC

    Wow. You came up with the exact same thing as I did, except for two little syntax differences. This is what I had. If I had knon that I didn't need the curly's on the grep, and if you reversed the order in your evaluations, they would be the same.

    use strict; my $x = 4; my $y = 38; my @z = ( 1, 3, 38, 83 ); print "Yes\n" if ((grep{$_<$x}@z)==(grep{$_<$y}@z));

Log In?
Username:
Password:

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

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

    No recent polls found