Programming chrestomathy: wealthiest customer

FeepingCreature feepingcreature at gmail.com
Tue Mar 9 07:03:46 UTC 2021


On Tuesday, 9 March 2021 at 05:06:03 UTC, mipri wrote:
> But D is very competitive here:
>
>   int maximumWealth(const int[][] accounts) {
>       import std.algorithm : map, sum, maxElement;
>       return accounts.map!sum.maxElement;
>   }
>
> Or, aping the APL:
>
>   int maximumWealth(const int[][] accounts) {
>       import std.algorithm : fold, map;
>       return accounts.map!(fold!"a+b").fold!"a.max(b)";
>   }
>

Golf!

import std;

alias maximumWealth = pipe!(map!sum, maxElement);

unittest { assert([[2, 10], [11]].maximumWealth == 12); }


More information about the Digitalmars-d mailing list