Skip to main content
Notice removed Reward existing answer by Razetime
Bounty Ended with a stone arachnid's answer chosen by Razetime
Notice added Reward existing answer by Razetime
Bounty Started worth 100 reputation by Razetime
Tweeted twitter.com/StackCodeGolf/status/1088723299910250496
edited body
Source Link
Oliver Ni
  • 10.6k
  • 3
  • 38
  • 107

Again inspired by a task for programmingProgramming 101 here's another challenge.

Input:

  • A positive integer n >= 3. (has to be odd)

Output:

  • n lines of asterisks, where the first line has n 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 to n 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):

*****
 ***
  *
 ***
*****

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 has n 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 to n 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):

*****
 ***
  *
 ***
*****

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 has n 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 to n 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):

*****
 ***
  *
 ***
*****
Post Reopened by Karl Napf, adrianmp, DJMcMayhem, AdmBorkBork, betseg
deleted 308 characters in body
Source Link
Sickboy
  • 1.2k
  • 1
  • 10
  • 10

Again inspired by a task for programming 101 here's another challenge.

Input:

  • A positive integer n >= 3. (has to be odd for the indentation variant)

Output:

  • With indentation: n lines of asterisks, where the first line has n 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 to n asterisks.
  • Without: n*2-1 lines of asterisks, where the first line has n asterisks and every new line has one asterisk less than the line before. Until hitting 1 asterisk. From there every new line has one asterisk more than the line before until getting back Spaces or something like spaces have to nused 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 cases (n=5):

With indentationTest case (n=5):

*****
 ***
  *
 ***
*****

Without:

*****
****
***
**
*
**
***
****
*****

Again inspired by a task for programming 101 here's another challenge.

Input:

  • A positive integer n >= 3. (has to be odd for the indentation variant)

Output:

  • With indentation: n lines of asterisks, where the first line has n 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 to n asterisks.
  • Without: n*2-1 lines of asterisks, where the first line has n asterisks and every new line has one asterisk less than the line before. Until hitting 1 asterisk. From there every new line has one asterisk more than the line before until getting back to n asterisks.

General rules:

  • Trailing newlines are allowed but do not have to be used.
  • 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 cases (n=5):

With indentation:

*****
 ***
  *
 ***
*****

Without:

*****
****
***
**
*
**
***
****
*****

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 has n 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 to n 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):

*****
 ***
  *
 ***
*****
Post Closed as "Duplicate" by trichoplax is on Codidact now, jacksonecac, TuxCrafting, Emigna code-golf
Source Link
Sickboy
  • 1.2k
  • 1
  • 10
  • 10

Draw an hourglass

Again inspired by a task for programming 101 here's another challenge.

Input:

  • A positive integer n >= 3. (has to be odd for the indentation variant)

Output:

  • With indentation: n lines of asterisks, where the first line has n 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 to n asterisks.
  • Without: n*2-1 lines of asterisks, where the first line has n asterisks and every new line has one asterisk less than the line before. Until hitting 1 asterisk. From there every new line has one asterisk more than the line before until getting back to n asterisks.

General rules:

  • Trailing newlines are allowed but do not have to be used.
  • 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 cases (n=5):

With indentation:

*****
 ***
  *
 ***
*****

Without:

*****
****
***
**
*
**
***
****
*****