Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 ( #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? | Other CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2022-07-01 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (98 votes). Check out past polls.

    Notices?