Skip to content

Instantly share code, notes, and snippets.

@IgnacioCastro0713
Last active January 12, 2022 19:47
Show Gist options
  • Save IgnacioCastro0713/8cb73cffbb922fe29f3e38ef7e330406 to your computer and use it in GitHub Desktop.
Save IgnacioCastro0713/8cb73cffbb922fe29f3e38ef7e330406 to your computer and use it in GitHub Desktop.
var serials = new[]
{
"00001", "00002", "00003", "00004", "00005",
"00006", "00007", "00008", "00009", "00010",
"00011", "00012", "00013", "00014", "00015",
};
const int rows = 5;
var columns = (int)Math.Ceiling((double)serials.Length / rows);
var result = string.Empty;
var packageSerials = serials
.Select((value, index) => new { value, index = index / rows })
.GroupBy(x => x.index)
.Select(g => g.Select(x => x.value).ToArray()).ToList();
for (var index = 0; index <= rows; index++)
{
result += packageSerials
.Select(array => array.Length > index ? array[index] : string.Empty)
.Aggregate(string.Empty, (accumulator, currentSerial) =>
{
if (string.IsNullOrEmpty(currentSerial)) return accumulator + currentSerial;
var row = index + 1;
var column = packageSerials.FindIndex(array => array[index] == currentSerial) + 1;
return $"{accumulator}R{row}C{column}={currentSerial};";
});
}
Console.WriteLine(result);
Console.ReadLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment