32
4
Again inspired by a task for Programming 101 here's another challenge.
Input:
- A positive integer
n >= 3
. (has to be odd)
Output:
n
lines of asterisks, where the first line hasn
asterisks and every new line has two asterisks less than the line before. Until hitting 1 asterisk. From there every new line has two asterisks more than the line before until getting back ton
asterisks. Spaces or something like spaces have to used to align the asterisks so that it really will look like an hourglass.
General rules:
- Trailing newlines are allowed but do not have to be used.
- indentation is a must.
- This is code-golf, so shortest answer in bytes wins.
- Since the course is taught in C++, I'm eager to see solutions in C++.
Test case (n=5):
*****
***
*
***
*****
edited accordingly, thanks :-) – Sickboy – 2016-10-25T11:42:12.227
I don't see how this is the duplicate of "Draw an asterisk triangle". This has indentation and a down-up sequence where the triangle is only upwards. – Karl Napf – 2016-10-25T11:51:09.840
@KarlNapf: Before the last edit you had the option of printing it without indentation meaning it was just a triangle from the other question printed as in that question and once in reverse. – Emigna – 2016-10-25T11:55:09.863
@Emigna Yes i know, already answered like that. But now it isnt anymore, so it should be open again. – Karl Napf – 2016-10-25T11:57:31.467
3
Possible duplicate of Draw an asterisk triangle
– Oliver Ni – 2016-10-25T14:59:52.3703@Oliver Considering OP wrote "Draw an asterisk triangle", I'm not entirely sure that calling this challenge a duplicate is fair. It is definitely related, though. – Sherlock9 – 2016-10-25T16:01:46.713
Can we assume the input is always
>=3
and always odd? – ʰᵈˑ – 2016-10-25T16:04:01.43319Since not everyone here knows the full context, OP originally posted the "Draw an asterisk triangle" and edited this challenge in as an additional challenge. We told them to remove that part and make it a different challenge (which they did). This challenge is not a duplicate. OP is doing what many high rep users, and even a few mods have recommended. – James – 2016-10-25T16:08:16.257
@closevoters could you remove your dupe votes? This question is no longer a duplicate of that question – Blue – 2016-10-25T19:16:09.573
Is it necessary to have enough trailing spaces to make the output square, or is "*****\n ***\n *\n *\n***" acceptable output? (With two spaces before the single asterisk, which SO edits to a single space!) – JDL – 2016-10-26T08:03:01.360
@JDL: As outlined in the rules, it has to be "square" (i.e. has to use indentation). – Sickboy – 2016-10-26T08:06:01.503
@ʰᵈˑ: yes, you don't have to check the input as this would lengthen the code unnecessarily. – Sickboy – 2016-10-26T08:07:03.587
@Sickboy I get that the stars have to align, but do we need any spaces to the right of the stars? – JDL – 2016-10-26T08:23:41.173
2@JDL: No, why would you? Ah, now I understand what you meant by square... :-D – Sickboy – 2016-10-26T08:34:38.743