Skip to content

Instantly share code, notes, and snippets.

@aschuhardt
Created February 23, 2018 16:50
Show Gist options
  • Save aschuhardt/52f195dfe251638816355cbeaa93950c to your computer and use it in GitHub Desktop.
Save aschuhardt/52f195dfe251638816355cbeaa93950c to your computer and use it in GitHub Desktop.
Creates wavy text using Reddit's markup.
using System;
using System.Linq;
using System.Text;
namespace WavyText
{
class Program
{
private enum Direction
{
Up,
Down
}
private const int MAX_HEIGHT = 3;
private const char CARAT = '^';
static void Main(string[] args)
{
var input = args.Length > 0 ? args[0] : Console.ReadLine();
var output = new StringBuilder();
var direction = Direction.Up;
var currentHeight = 0;
foreach (var c in input)
{
if (c == ' ')
{
output.Append(c);
continue;
}
output.Append(string.Join(string.Empty, Enumerable.Repeat(CARAT, currentHeight)));
output.Append(c);
output.Append(" ");
if (currentHeight <= 0)
direction = Direction.Up;
else if (currentHeight >= MAX_HEIGHT)
direction = Direction.Down;
switch (direction)
{
case Direction.Up:
++currentHeight;
break;
case Direction.Down:
--currentHeight;
break;
}
}
Console.WriteLine(output.ToString());
Console.ReadKey(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment