6 kyu

String Pyramid

216 of 717user5036852

Description:

You have to build a pyramid.

This pyramid should be built from characters from a given string.

You have to create the code for these four methods:

public static string WatchPyramidFromTheSide(string characters)

public static string WatchPyramidFromAbove(string characters)

public static int CountVisibleCharactersOfThePyramid(string characters)

public static int CountAllCharactersOfThePyramid(string characters)
public static String watchPyramidFromTheSide(String characters)

public static String watchPyramidFromAbove(String characters)

public static int countVisibleCharactersOfThePyramid(String characters)

public static int countAllCharactersOfThePyramid(String characters)
function watchPyramidFromTheSide(characters)

function watchPyramidFromAbove(characters)

function countVisibleCharactersOfThePyramid(characters)

function countAllCharactersOfThePyramid(characters)
std::string watchPyramidFromTheSide(std::string characters)

std::string watchPyramidFromAbove(std::string characters)

int countVisibleCharactersOfThePyramid(std::string characters)

int countAllCharactersOfThePyramid(std::string characters)
watch_pyramid_from_the_side(characters):

watch_pyramid_from_above(characters):

count_visible_characters_of_the_pyramid(characters):

count_all_characters_of_the_pyramid(characters):

The first method ("FromTheSide") shows the pyramid as you would see from the side.
The second method ("FromAbove") shows the pyramid as you would see from above.
The third method ("CountVisibleCharacters") should return the count of all characters, that are visible from outside the pyramid.
The forth method ("CountAllCharacters") should count all characters of the pyramid. Consider that the pyramid is completely solid and has no holes or rooms in it.

Every character will be used for building one layer of the pyramid. So the length of the given string will be the height of the pyramid. Every layer will be built with stones from the given character. There is no limit of stones.
The pyramid should have perfect angles of 45 degrees.


Example: Given string: "abc"

Pyramid from the side:

  c
 bbb
aaaaa

Pyramid from above:

aaaaa
abbba
abcba
abbba
aaaaa

Count of visible stones/characters:

25

Count of all used stones/characters:

35

There is no meaning in the order or the choice of the characters. It should work the same for example "aaaaa" or "54321".
Hint: Your output for the side must always be a rectangle! So spaces at the end of a line must not be deleted or trimmed!
If the string is null or empty, you should exactly return this value for the watch-methods and -1 for the count-methods.

Have fun coding it and please don't forget to vote and rank this kata! :-)

I have created other katas. Have a look if you like coding and challenges.

Mathematics
Strings
Algorithms
ASCII Art

Stats:

CreatedJul 26, 2016
PublishedJul 27, 2016
Warriors Trained3452
Total Skips1058
Total Code Submissions8758
Total Times Completed717
C# Completions68
JavaScript Completions121
C++ Completions157
Python Completions216
Java Completions157
TypeScript Completions38
Total Stars108
% of votes with a positive feedback rating88% of 203
Total "Very Satisfied" Votes164
Total "Somewhat Satisfied" Votes29
Total "Not Satisfied" Votes10
Ad
Contributors
  • user5036852 Avatar
  • zebulan Avatar
  • Dentzil Avatar
  • Blind4Basics Avatar
  • FArekkusu Avatar
  • hobovsky Avatar
Ad