ASCIIタンポポは次のとおりです。
\|/ \ / |
/|\ | \|/ |
| | | _\|/_
| | | /|\
ASCIIタンポポには3つのパラメータがあります。茎の長さ(1〜256の正の数、種の数(0〜7の正の数)、および方向(^またはv)。上記のタンポポは、長さ、種、および方向、 3,5、^)、(3,2、^)、(2,3、^)および(3,7、v)。
種子は、長さ2のタンポポで示されている次の順序(上下逆さまのタンポポで反転)で塗りつぶされます。
seeds: 0 1 2 3 4 5 6 7
| \ / \|/ \ / \|/ _\ /_ _\|/_
| | | | /|\ /|\ /|\ /|\
| | | | | | | |
チャレンジ:
入力としてASCIIタンポポを指定すると、上記の例と同様にフォーマットされた長さ、シードカウント、方向を返し、その形式のパラメータを指定すると、それらのパラメータでASCIIタンポポを返すプログラム/関数を作成します。括弧を無視して、入力/出力が数字、コンマ、数字、コンマ、^またはのいずれかであると想定できますv。あなたは、のために他の文字を置換してもよい^/ v限り、彼らはまだ簡単に(例えば、「アップ」/「ダウン」として解釈することができるようu/ d)。(2,1、^)と(3,0、^)や(2,1、^)と(2,1、v)など、同じように見えるタンポポを区別する必要はありません。ASCIIアートを考えると、どちらのパラメーターセットも許容可能な出力になり、両方のパラメーターセットは同じASCIIアートを提供できます。
これはcode-golfなので、バイト単位の最短コードが優先されます。
C#のサンプルプログラム(少しでもゴルフではありません):
string Dandelion(string s)
{
if (s.Contains(','))
{
//got parameters as input
string[] p = s.Split(',');
//depth and width (number of seeds)
int d = int.Parse(p[0]);
int w = int.Parse(p[1]);
//draw stem
string art = " |";
while (d > 2)
{
d--;
art += "\n |";
}
//draw head
string uhead = (w % 2 == 1 ? "|" : " ");
string dhead = uhead;
if (w > 1)
{
uhead = "\\" + uhead + "/";
dhead = "/" + dhead + "\\";
if (w > 5)
{
uhead = "_" + uhead + "_\n /|\\";
dhead = "_\\|/_\n " + dhead;
}
else if (w > 3)
{
uhead = " " + uhead + " \n /|\\";
dhead = " \\|/ \n " + dhead;
}
else
{
uhead = " " + uhead + " \n |";
dhead = " |\n " + dhead;
}
}
else
{
uhead = " " + uhead + "\n |";
dhead = " |\n " + dhead;
}
//add head to body
if (p[2] == "^")
{
return uhead + "\n" + art;
}
return art + "\n" + dhead;
}
else
{
//ASCII input
string[] p = s.Split('\n');
int l = p.Length - 1;
int offset = 0;
//find first non-' ' character in art
while (p[0][offset] == ' ')
{
offset++;
}
int w = 0;
if (p[0][offset] == '|')
{
//if '|', either head-down or no head.
if (offset == 0 || p[l][offset - 1] == ' ')
{
//if no space for a head to the left or no head at the bottom, no head.
return l.ToString() + ",1,^";
}
//head must have at least size 2, or else indistinguishable from no head case
w = 6;
if (p[l][offset] == '|')
{
//odd sized head
w = 7;
}
if (offset == 1 || p[l - 1][offset - 2] == ' ')
{
//not size 6 or 7
w -= 2;
if (p[l - 1][offset - 1] == ' ')
{
//not size 4 or 5
w -= 2;
}
}
return l.ToString() + "," + w.ToString() + ",v";
}
else if (p[0][offset] == '\\')
{
//head at least size 2 and not 6/7, or indistinguishable from no head.
w = 4;
if (p[0][offset + 1] == '|')
{
w = 5;
}
if (p[1][offset] == ' ')
{
w -= 2;
}
}
else
{
w = 6;
if (p[0][offset + 2] == '|')
{
w = 7;
}
}
return l.ToString() + "," + w.ToString() + ",^";
}
}
^andの代わりに他のいくつかの異なるシンボルを使用できますvか?