6 kyu

Give me a Diamond

13,183 of 38,141jayeshcp

Description:

Jamie is a programmer, and James' girlfriend. She likes diamonds, and wants a diamond string from James. Since James doesn't know how to make this happen, he needs your help.

Task

You need to return a string that looks like a diamond shape when printed on the screen, using asterisk (*) characters. Trailing spaces should be removed, and every line must be terminated with a newline character (\n).

Return null/nil/None/... if the input is an even number or negative, as it is not possible to print a diamond of even or negative size.

Examples

A size 3 diamond:

 *
***
 *

...which would appear as a string of " *\n***\n *\n"

A size 5 diamond:

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

...that is:

"  *\n ***\n*****\n ***\n  *\n"
Strings
ASCII Art
Fundamentals

More By Author:

Check out these other kata created by jayeshcp

Stats:

CreatedMar 13, 2015
PublishedMar 13, 2015
Warriors Trained119084
Total Skips29879
Total Code Submissions219002
Total Times Completed38141
Java Completions7489
Python Completions13183
JavaScript Completions11525
C# Completions3154
Swift Completions855
Rust Completions1244
Ruby Completions502
COBOL Completions9
C Completions429
Scala Completions34
Lua Completions32
Total Stars1948
% of votes with a positive feedback rating88% of 4162
Total "Very Satisfied" Votes3294
Total "Somewhat Satisfied" Votes728
Total "Not Satisfied" Votes140
Ad
Contributors
  • jayeshcp Avatar
  • jhoffner Avatar
  • alchemy Avatar
  • Unnamed Avatar
  • ChristianECooper Avatar
  • bstenzel Avatar
  • anter69 Avatar
  • Blind4Basics Avatar
  • calebkleveter Avatar
  • pavloslav Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • 4500zenja1 Avatar
  • KayleighWasTaken Avatar
  • metatable Avatar
  • saudiGuy Avatar
Ad