Comma quibbling: Difference between revisions
Content deleted Content added
New draft task and Python solution. |
+ D entry |
||
Line 15: | Line 15: | ||
Note: Assume words are non-empty strings of uppercase characters for this task. |
Note: Assume words are non-empty strings of uppercase characters for this task. |
||
=={{header|D}}== |
|||
<lang d>import std.stdio, std.string; |
|||
string quibbler(in string[] seq) pure /*nothrow*/ { |
|||
if (seq.length <= 1) |
|||
return format("{%-(%s, %)}", seq); |
|||
else |
|||
return format("{%-(%s, %) and %s}", seq[0 .. $-1], seq[$-1]); |
|||
} |
|||
void main() { |
|||
//foreach (immutable test; [[], |
|||
foreach (const test; [[], |
|||
["ABC"], |
|||
["ABC", "DEF"], |
|||
["ABC", "DEF", "G", "H"]]) |
|||
test.quibbler.writeln; |
|||
}</lang> |
|||
{{out}} |
|||
<pre>{} |
|||
{ABC} |
|||
{ABC and DEF} |
|||
{ABC, DEF, G and H}</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |