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
Similar Kata:
Stats:
Created | Mar 13, 2015 |
Published | Mar 13, 2015 |
Warriors Trained | 119084 |
Total Skips | 29879 |
Total Code Submissions | 219002 |
Total Times Completed | 38141 |
Java Completions | 7489 |
Python Completions | 13183 |
JavaScript Completions | 11525 |
C# Completions | 3154 |
Swift Completions | 855 |
Rust Completions | 1244 |
Ruby Completions | 502 |
COBOL Completions | 9 |
C Completions | 429 |
Scala Completions | 34 |
Lua Completions | 32 |
Total Stars | 1948 |
% of votes with a positive feedback rating | 88% of 4162 |
Total "Very Satisfied" Votes | 3294 |
Total "Somewhat Satisfied" Votes | 728 |
Total "Not Satisfied" Votes | 140 |