Run-length encoding: Difference between revisions

→‎Linq: Updated short linq solution to match
(→‎Linq: More idiomatic Linq and faster)
(→‎Linq: Updated short linq solution to match)
Line 733:
using System.Linq;
using static System.Console;
using MoreLinq; // best/most popular addon library for linq - NOT using built in runlengthencoding() method here
 
namespace RunLengthEncoding
{
static class Program
{
public static string Encode(string input) => input.Length ==0 ? "" : input.Skip(1)
.GroupAdjacentAggregate(i=>i,(key, vals) => (rptt:valsinput[0].CountToString(), chro: keyEmpty<string>());,
(a,c)=>a.t[0]==c ? (a.t+c,a.o) : (c.ToString(),a.o.Append(a.t)),
a=>a.o.Append(a.t).Select(p => (key: p.Length, chr: p[0])));
 
public static string Decode(IEnumerable<(int i , char c)> input) =>