Run-length encoding: Difference between revisions
Content deleted Content added
→Linq: Better but slightly but longer linq! |
m →Linq: code typo |
||
Line 698: | Line 698: | ||
a=>a.o.Append(a.t).Select(p => (key: p.Length, chr: p[0]))) |
a=>a.o.Append(a.t).Select(p => (key: p.Length, chr: p[0]))) |
||
.Select(p=> $"{p.key}{p.chr}") |
.Select(p=> $"{p.key}{p.chr}") |
||
. |
.StringConcat(); |
||
public static string Decode(string input) => input |
public static string Decode(string input) => input |
||
.Aggregate((t: "", o: Empty<string>()), (a, c) => !char.IsDigit(c) ? ("", a.o.Append(a.t+c)) : (a.t + c,a.o)).o |
.Aggregate((t: "", o: Empty<string>()), (a, c) => !char.IsDigit(c) ? ("", a.o.Append(a.t+c)) : (a.t + c,a.o)).o |
||
.Select(p => new string(p.Last(), int.Parse(string.Concat(p.SkipLast(1))))) |
.Select(p => new string(p.Last(), int.Parse(string.Concat(p.SkipLast(1))))) |
||
. |
.StringConcat(); |
||
private static string StringConcat(this IEnumerable<string> seq) => string.Concat(seq); |
|||
public static void Main(string[] args) |
public static void Main(string[] args) |
||
{ |
{ |