Challenge270

CSharp · Console

/Program.cs

//https://www.reddit.com/r/dailyprogrammer/comments/4msu2x/challenge_270_easy_transpose_the_input_text/
using System;
using System.Linq;
	
public class Program
{
	public static string InputText = @"package main

import ""fmt""

func main() {
    queue := make(chan string, 2)
    queue <- ""one""
    queue <- ""twoO""
    close(queue)
    for elem := range queue {
        fmt.Println(elem)
    }
}";

	public static void Main()
	{
		var inputEnumerators = InputText.Split('\n').Select(x => x.GetEnumerator()).ToArray();
		var lineBuffer = new char[inputEnumerators.Length];
		var stillCharacters = true;
		var lastCharIndex = 0;
		
		while(stillCharacters)
		{
			stillCharacters = false;
			lastCharIndex = -1;
			for(int i = 0; i < inputEnumerators.Length; i++)
			{
				if(inputEnumerators[i].MoveNext())
				{
					stillCharacters = true;
					lineBuffer[i] = inputEnumerators[i].Current;
					lastCharIndex = i;
				}
				else
				{
					lineBuffer[i] = ' ';
				}
			}
			
			if(stillCharacters)
			{
				Console.WriteLine(lineBuffer, 0, lastCharIndex + 1);
			}
		}
	}
}
;