Jump to content

Set right-adjacent bits: Difference between revisions

m
(Realize in F#)
m (→‎{{header|Raku}}: simplify)
Line 398:
 
=={{header|Raku}}==
{{incomplete|Raku|Missing the examples asked for}}
A left-to-right ordered collection of bits is more commonly referred to as an Integer in Raku.
 
<lang perl6>sub rab (Int $n is copy, Int $b = 1) {
formy 1..$n.msbm ->= $i {n;
$m +|= next unless ($n +&> (1$_) +<for ^$i)b;
$nm
$n +|= exp($i - $_, 2) for 1 .. $b
}
$n
}
 
sub lab (Int $n is copy, Int $b = 1) {
formy $n.msbm … 0 ->= $i {n;
next unless $nm +&|= (1$n +< $i_) for ^$b;
$nm
$n +|= exp($i + $_, 2) for 1 .. $b
}
$n
}
 
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.