Display a linear combination: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: Added zkl) |
(→{{header|Perl 6}}: style) |
||
Line 27: | Line 27: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
<lang perl6>sub linear-combination(@coeff) { |
<lang perl6>sub linear-combination(@coeff) { |
||
(@coeff Z=> map { "e($_)" }, 1 .. *)\ |
|||
.grep(+*.key)\ |
|||
.map({ .key ~ '*' ~ .value })\ |
|||
.join('+')\ |
|||
map { .key ~ '*' ~ .value }, |
|||
⚫ | |||
grep +*.key, |
|||
⚫ | |||
(@coeff Z=> map { "e($_)" }, 1 .. *) |
|||
|| '0' |
|||
⚫ | |||
⚫ | |||
} |
} |
||
say linear-combination( |
say linear-combination($_) for |
||
[1, 2, 3], |
[1, 2, 3], |
||
[0, 1, 2, 3], |
[0, 1, 2, 3], |
||
Line 48: | Line 46: | ||
[-1, -1, -1], |
[-1, -1, -1], |
||
[-1, -2, 0, -3], |
[-1, -2, 0, -3], |
||
[ |
[-1 ] |
||
;</lang> |
;</lang> |
||
{{out}} |
{{out}} |