Anonymous user
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;
namespace RunLengthEncoding
{
static class Program
{
public static string Encode(string input) => input.Length ==0 ? "" : input.Skip(1)
.
(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) =>
|