Balanced ternary: Difference between revisions
m
→{{header|Perl 6}}: various fixes
m (→{{header|ALGOL 68}}: add addition and miltiplication) |
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: various fixes) |
||
Line 2,902:
</pre>
=={{header|Perl 6}}==
{{
<lang perl6>class BT {
has @.coeff;
Line 2,910:
multi method new (Str $s) {
self.bless(
}
multi method new (Int $i where $i >= 0) {
self.bless(
}
multi method new (Int $i where $i < 0) {
Line 2,940:
multi infix:<+> (BT $x, BT $y) {
my ($b,$a) = sort +*.coeff, $x, $y;
BT.new: coeff => carry ($a.coeff Z+ |$b.coeff, |(0 xx
}
Line 2,951:
my @safe;
for @x -> $xd {
@z = @z Z+ |(@y X* $xd), |(0 xx
@safe.push: @z.shift;
}
|