Skip to content

Instantly share code, notes, and snippets.

@NotFounds
Created February 10, 2017 11:25
Show Gist options
  • Save NotFounds/c93bb6675dff657fe89235acbfb91244 to your computer and use it in GitHub Desktop.
Save NotFounds/c93bb6675dff657fe89235acbfb91244 to your computer and use it in GitHub Desktop.
using System;
public class Test
{
const string PINC = "たのしー!";
const string PDEC = "たーのしー!";
const string INC = "すごーい!";
const string DEC = "すっごーい!";
const string PUT = "なにこれなにこれ!";
const string GET = "おもしろーい!";
const string START = "うわー!";
const string END = "おもしろーい!";
/*
const string PINC = ">";
const string PDEC = "<";
const string INC = "+";
const string DEC = "-";
const string PUT = ".";
const string GET = ",";
const string START = "[";
const string END = "]";
*/
public static void Main()
{
Print("Friends");
}
private static int Put(char c, int cur = 0)
{
var diff = c - cur;
var ope = (diff > 0) ? INC : DEC;
var sqrt = (int)Math.Sqrt(Math.Abs(diff));
var x = sqrt + 1;
var y = sqrt;
var offset = diff - x * y;
if (offset < 0) { offset += y; x--; }
// optimize
for (var i = 1; i < x - 1; ++i)
{
var tmp = diff - (sqrt + i) * (sqrt + i);
if (0 <= tmp && tmp < offset)
{
x = sqrt + i;
y = sqrt - i;
offset = tmp;
}
}
if (diff < (x + y + 3))
{
Console.Write(PINC);
for (var i = 0; i < Math.Abs(diff); ++i)
Console.Write(ope);
Console.Write(PUT);
Console.Write(PDEC);
return c;
}
// set a repeat number
for (var i = 0; i < x; ++i)
Console.Write(INC);
// loop start
Console.Write(START);
Console.Write(PINC);
for (var i = 0; i < y; ++i)
Console.Write(ope);
// loop decriment
Console.Write(PDEC);
Console.Write(DEC);
// loop end
Console.Write(END);
Console.Write(PINC);
for (var i = 0; i < offset; ++i)
Console.Write(ope);
// output
Console.Write(PUT);
Console.Write(PDEC);
return c;
}
private static int Print(string str, int cur = 0)
{
foreach (var c in str)
cur = Put(c, cur);
return cur;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment