Re: Contribution to perl 6 - week 9 Hash.pick

2010-07-15 Thread yary
> or, if you want to use bit ops and integer math, "$l +> 1 + $r +> 1 + > ($l mod 2 + $r mod 2) +> 1" Just because I find a perverse pleasure in this- $mid = $r+>1+$l+>1+($r+&$l+&1) -y

Re: Contribution to perl 6 - week 9 Hash.pick

2010-07-15 Thread yary
"mid" is too specific. A "mean" function may be good as part of a statistics package. Doesn't seem like a good addition to the core. How about resorting to algebra and using the commutation my $middle = floor($l / 2 + $r / 2); or, if you want to use bit ops and integer math, "$l +> 1 + $r +> 1 +

Re: Contribution to perl 6 - week 9 Hash.pick

2010-07-15 Thread Moritz Lenz
Todd Olson wrote: > At 12:35 +0200 2010-07-15, Moritz Lenz wrote: >>>If it ever were the case that $r + $l could produce an overflow >> >>Then we really have other problems. Remember that $r and $l are >>array indexes. If your machine has enough memory to hold an array >>and a hash of the same si

Re: Contribution to perl 6 - week 9 Hash.pick

2010-07-15 Thread Todd Olson
Hi At 20:11 +0200 2010-07-14, Moritz Lenz wrote: I'll also fix some minor nits, like simplifying my $middle = $l + floor( ($r-$l)/2); to my $middle = floor ($r + $l) / 2 Since we often need to compute (correctly and efficiently) the middle point of two numberish things, perhaps a better appr

Re: Contribution to perl 6 - week 9 Hash.pick

2010-07-15 Thread Todd Olson
At 12:35 +0200 2010-07-15, Moritz Lenz wrote: If it ever were the case that $r + $l could produce an overflow Then we really have other problems. Remember that $r and $l are array indexes. If your machine has enough memory to hold an array and a hash of the same size in memory, but can't stor

Re: Contribution to perl 6 - week 9 Hash.pick

2010-07-15 Thread Moritz Lenz
Am 15.07.2010 12:24, schrieb Todd Olson: Hi At 20:11 +0200 2010-07-14, Moritz Lenz wrote: I'll also fix some minor nits, like simplifying my $middle = $l + floor( ($r-$l)/2); to my $middle = floor ($r + $l) / 2 ??? !!! Thinking more about it, my $middle = ($r + $l) div 2 is even better

Re: Contribution to perl 6 - week 9 Hash.pick

2010-07-15 Thread Todd Olson
Hi At 20:11 +0200 2010-07-14, Moritz Lenz wrote: I'll also fix some minor nits, like simplifying my $middle = $l + floor( ($r-$l)/2); to my $middle = floor ($r + $l) / 2 ??? If it ever were the case that $r + $l could produce an overflow then the second statement would fail, while the first

Contribution to perl 6 - week 9 Hash.pick

2010-07-14 Thread Radu Stoica
Hi,   Please see below the code. It does not check for integer values yet and the algorithm is based on the suggestion made in moritz's post. diff --git a/src/core/Hash.pm b/src/core/Hash.pmindex 0365dfc..b2fa0ae 100644--- a/src/core/Hash.pm+++ b/src/core/Hash.pm@@ -96,6 +96,69 @@ role Hash is E

Re: Contribution to perl 6 - week 9 Hash.pick

2010-07-14 Thread Moritz Lenz
Hi, thank you very much for your contribution. I'm now in the middle of testing and applying it, and if all goes right, I'll push it tonight (ie in the course of a few hours). According to my tests it does exactly what it should, I only found one minor bug: {a => 1, b => 0}.pick(*) would produc