Anonymous user
Maximum triangle path sum: Difference between revisions
→{{header|Perl 6}}: more explanation
(→{{header|Perl 6}}: add FP version) |
(→{{header|Perl 6}}: more explanation) |
||
Line 69:
{{out}}
<pre>1320</pre>
Here's a more FPish version with the same output. We define our own operator and the use it in the reduction metaoperator form, <tt>[op]</tt>, which turns any infix into a list operator. (We could presumably have avoided the <tt>reverse</tt> by defining our op as equivalent to a right-associative operator instead, but the reversal works too, and seems more natural in this case.)
<lang perl6>sub infix:<op>(@a,@b) { (@a Zmax @a.rotate) Z+ @b }
|