This came up in a real life problem I had, and I thought it might make an interesting challenge. The idea is simple, you have an array (sorted) containing n unique real numbers (call it @z). You also have two additional real values (call them $x, and $y). The challenge is to determine if $x and $y both either:
- Fall between the same two numbers in @z, or
- Are greater than all the numbers in @z, or
- Are less than all the numbers in @z
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.
Examples
@z = ( 1, 3, 27, 38 ); $x=4; $y=5; # Works $x=0; $y=-1; # Works $x=100; $y=100; # Works $x=10; $y=27; # Works $x=3; $y=27; #Fails
So you start out with code like this:
use strict; my $x = shift(); my $y = shift(); my @z = @_; print "YES!\n" if (...);
And the challenge is to replace '...' with as few characters (whitespace counts) as possible while satisfactorially solving the problem.
I've gotten it down to 32 chars. Who's going to beat me first?
updated: You need to use strict.
Back to
Meditations