ये ASCII डंडेलियन हैं:
\|/ \ / |
/|\ | \|/ |
| | | _\|/_
| | | /|\
ASCII dandelions के तीन पैरामीटर हैं: स्टेम की लंबाई (1 और 256 के बीच सकारात्मक संख्या, बीज की संख्या (0 और 7 के बीच सकारात्मक संख्या), और अभिविन्यास (^ या v)। उपरोक्त dandelions की लंबाई, बीज और अभिविन्यास, और के लिए है। क्रमशः 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 कला दे सकते हैं।
यह कोड-गोल्फ है , इसलिए बाइट्स जीत में सबसे छोटा कोड है।
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() + ",^";
}
}
^औरv?