Gray code: Difference between revisions
m
→{{header|Raku}}: Undo bizarre single space indent that somebody found necessary to do
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: Undo bizarre single space indent that somebody found necessary to do) |
||
Line 4,489:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>sub gray_encode ( Int $n --> Int ) {
return $n +^ ( $n +> 1 );
my $mask = 1 +< (32-2);
$n +^= $mask +> 1 if $n +& $mask while $mask +>= 1;
return $n;
my $g = gray_encode($n);
my $d = gray_decode($g);
printf "%2d: %5b => %5b => %5b: %2d\n", $n, $n, $g, $d, $d;
die if $d != $n;
}</syntaxhighlight>▼
▲</syntaxhighlight>
{{out}}
|