sub binary (0|1 $n) { $n }
sub binary ($n) {
my $k = int($n/2);
my $b = $n % 2;
my $E = binary($k);
return $E ~ $b;
}
That's fantasy syntax, unless it was allowed in the last two weeks where I didn't have internet access. It might work along these lines:
multi binary ($n where 0|1) { $n }
multi binary ($n) {
my $k = int($n/2);
my $b = $n % 2;
my $E = binary($k);
return $E ~ $b;
}
When you post Perl 6 code these days it's worth trying it in Rakudo first, which supports all the features needed for the subroutine above (I would try it myself, but I'm currently on a machine where I can't install any programs :-/).
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|