6 kyu
String Pyramid
217 of 719user5036852
Loading description...
Mathematics
Strings
Algorithms
ASCII Art
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Wonderful and enjoyable kata, congratulations.
This comment has been hidden.
Beauifull kata !
For C# is possible to pass tests with not full solution. Tests does not consider cases with reccuring chars, like "1232" or "KEKE". Thats why my solution can't pass example "aaaaa" from description, but i solved this kata.
Funny and cool Kata!
I enjoyed a lot
a lot of work fixing boudaries. the characters = "" case is useless
Nice kata, thx author) thought a lot about the fourth method.
So I am passing all the sample tests and everything I do on my own end but it is throwing and index error any time I try and submit?
Really enjoyed this one. After some refactoring I got a pleasing level of code reuse across the 4 public functions. :)
I get this error message (TypeError: object of type 'NoneType' has no len()) altough the code works perfectly fine in spyder. What am I missing here!? Thanks for any help!
Maybe you should do a check for NoneType before??
From the description: "If the string is null or empty, you should exactly return this value for the watch-methods and -1 for the count-methods."
that's why I put an if-statement at the very beginning (if len .. return ...)
You should check for NoneType BEFORE you do check for the len.
If the object would be NoneType, then this object is not existent and so there is no method "len()". That is why you get the error "TypeError: object of type 'NoneType' has no len()".
Got it, thanks! Still fails afterwards even tough it looks exactly like the example output when I put it in my spyder. Do I have to work with \n in the print statement to make it run? I just wrote a for loop that prints every line seperately. Is that maybe the problem because to me it looks exactly the same ...
Maybe show your code here (mark as spoiler!) and we will see. :-)
This comment has been hidden.
Could you see my comment, @SteffenVogel_79? It's marked as hidden here ...
Where is your "return" in the first two functions? you print it, but you have to return a string.
Ah, that was the hint I needed. Solved it, thanks! I could have seen it myself looking into the test cases but it just doesn't print / return it like it is shown in the example. That was irritating. It might be not the worst idea to mention that the return and the example output look differently, or? Anyways, thanks again!
Count should not be -1 for an input of 0 size, it makes more sense for it to be 0. Other than that, it was fun to do. :)
Yup. The number of bricks visible for an empty string is 0, not -1. One shouldn't have to set up counter-intuitive catches just to match arbitrary tests. Those tests, and this kata, are essentially broken.
Nothing is broken! 217 people did this kata without any problems. So where is the concrete problem?
Hello everyone, I have a System.NullReferenceException with the EmptyTest but I don't anderstand why ? I check IsNullOrEmpty and if it's true I return characters, it works on visual studio but not here :/
C#
Post your code here (mark as spoiler!) and we will see.
Sorry my bad I forgot to check the null value for the count block function like a noob. However good kata :)
I don't know why, but when I hit "Run suite" it gives me Passed: 0 Failed: 0 _EmptyTest
What does it mean? Thanks a lot!
In C++ or JavaScript?
Consider that sentence from the description: "If the string is null or empty, you should exactly return this value for the watch-methods and -1 for the count-methods."
Nice kata, SteffenVogel, but this kata should probably be ranked one higher (to 5kyu).
Thanks. ;-) The rank was set by another warrior.
ranks cannot be changed, sadly -:)
Unusual for Java method names to start with uppercase - eg
BasicTest2
,Visualisation
...Yes, in the next java-translations I will do better. Thanks for the hint!
In this case I can change the names because its only in the tests and all java-solutions will stay valid.
After severeal trys, now its changed. :-)
Almost there...
RandomTest
-->randomTest
myMethodsInterface MyMethods = new myMethodsInterface()
-->MyMethodsInterface myMethods = new MyMethodsInterface()
Interfaces with Capital Letters?
Ok. Done. :-)
FYI - http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html
See section 9.
The Java implementation seemed a bit weird passing that same
characters
parameter to all those static methods each time. Wouldn't it be better to construct aPyramid
instance then only pass the characters to the constructor, and also simplify all the method names?Like this:
I thought first this way for C# and Java. But in JavaScript it would be different and I wanted to have them the same construct, if possible.
But generally you are completely right!!!
This comment has been hidden.
:D Very good! :-)
I'll try to translate more of my katas to Java!
Well, I need some help here. I have done the kata, and it passes the tests. The problem emerges when I submit it. My code fails the null/empty test everytime and the random test most of times, and in both cases, the message given is: "expected:<-1> but was:<1>". Could someone explain to me what am I doing wrong? Thanks!
p.s.: nice kata!
Edit: the message is this: expected:&*lt;-1&*gt; but was:&*lt;1&*gt; (without the asterisk)
Did you read the end of the description? "If the string is null or empty, you should exactly return this value for the watch-methods and -1 for the count-methods."
This comment has been hidden.
Alright, my code was not checking if the String characters was empty, only if it was == null.
Problem solved, thanks :D
Such an original kata, had a lot of fun solving it.
Glad to hear that. :-)
My pyramid for the side view is coorect, but it does not pass. Must i add the same ammount of spaces as i did before the set of charachters? and if so, why?
Look in the example-test at the end of the expected value. :-)
And of course the amount of spaces has to be like in the expected value in the tests....
I hope, these hints help. :-)
but ouldnt the result of the pyramid be the same even without spaces at the end?
The output has to follow the given rules. And the spaces and line-endings have to be exactly like in the description and visible in the example test.
If you want, you can post your code here (marked as spoiler) and I try to help more precisely. :-)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Yes, it contains spoiler. :-)
thanks for the tip. I now pass 61/64 tests. they say for my above test: Expected: F, instead got: F
Expected: j, instead got: j
thx in advance
Even thoug i passesd by repeatedly clicking the submit button, i still would like to know why tose erros occured. thx
Seems that the probleme is the pyramid with only one character. Perhaps there is a line-breake oder a space?
If you send me your actual code, I will have a look on it.
This comment has been hidden.
I struggled with this a lot as a noob (in python) because I got some misleading error messages (Before I learned I should do if (not characters): return characters (or-1)...) For instance, if I made my output -1 when the input was an int, it would say "1 should be -1" even if an entry of 1 really did produce -1. Similarly, sometimes it said "-1 should be '' ", even if I were to make it so that an input of -1 really did give ''. I'm guessing what happened is that your test would test for an empty string '' and then somehow the error message was "1 should be -1" or something. If possible, it would really help future codewar participants if you could use the same language in the error messages as you did in the kata description. (ex "empty string should return an empty string for viewing and -1 for counting funcs"). I'm happy to email you some of the submissions I was getting odd error messages, if you think it is worth the time. My email is in my github acct /lanceculnane
Other than that, I really enjoyed this kata- thanks! I finally got it after I did if not characters: return characters!
Issue? Where is the problem?
Is this why you gave a negative ranking?
Below are the parts of my old code that was raising misleading errors:
... and then for the 'count' methods I had it return -1. Therefore, as you can see, if your testing program were to input (1), then I would output (-1) and yet the error message only said "1 should be -1"
I'd be happy to give a positive ranking if the error message becomes more helpful.
I don't see where is the problem... What is your concrete problem?
you gave a negative ranking because you do not like the error message? are you serious?
Really?
@lanceculnane
,I did the Python translation for this kata and would try to help explain/fix any problem but your issue description is so vague that I don't know what you mean. The katas description clearly states:
If the string is null or empty, you should exactly return this value for the watch-methods and -1 for the count-methods.
watch
functions:None
, you are expected to returnNone
(null is equivalent toNone
in Python)''
, you are expected to return an empty string''
count
functions will only ever return-1
, if the input string isNone
or an empty string''
.Also, Your code example makes no sense to me? The input argument for the two
count
functions is a single string of characters orNone
, not an integer.I would try to help if you can be more specific about your problem. By specific I mean:
Mark as having spoiler content
underneath your comment (so you don't give away the solution to other users)Thanks!
I laughed way too hard at this :D.
I've marked "very" satisfied now. Sorry- I wasn't trying to be a jerk.
This comment has been hidden.
Hey "lanceculnane". :-) And now you changed it back to "Something"? Why?
I think the error message is really full correct. The value should be equal to -1. Your value is 1. So it is wrong. In the description it is said, that -1 is expectet in the cases of empty and null. So where is the problem?
You have had fun and a good challenge with this kata. So give a "very". If you think, it was a bad and stupid kata, then give a "stupid" or "bad". But be honest and fair and do not a revenge voting, because your thoughts about the error message are not like mine and like the others.
Have fun at codewars. Learn. And become a wortful member of the great codewars community! :-)
Hi Steffen, No, I still have it at "very" satisfied because I did learn a lot from this kata and I appreciate that.
And also... I think you are right! The error message is wunderbar. It was my interpretation of it which was wrong. I see indeed, now, that when I run the "count_visible.." func with an empty string "", then it returns "1" instead of "-1" like it should. I'm new to codewars, and didn't know that "1 should equal -1" means that my output was 1 and should be -1... I thought it meant that an input of 1 should equal an output of -1. Thank you for being really responsive to this thread- sorry for taking up your time! I'll be happy to buy you some beers or something if you ever visit Colorado. Cheers! Lance
This comment has been hidden.
Can you better explain how to arrive to the last count? I am trying to visualize it and cannot match the numbers as to what you're asking for. Thanks in advanced!
OK, of course right after I say that I figure out what you mean. Solid is the key here.
So, all is fine and you solved it? :-)
This comment has been hidden.
Look at the end of the string. :-) There might be the difference thats seems to be invisible.
I hope that helps.
OK - thank you. Problem w my line-break add rule.
Thanks for a great kata!
I suppose this kata worth 5 or 4 kyi, very interesting task, thanks SteffenVogel_79.
Thanks. I'm glad, you like it.
Can someone approve this kata?
This comment has been hidden.
And if you now try again?
Could someone try again to approve this kata?
For the standard test cases the kata gives helpful output about how it should look and how it does look. However, the output from BasicTest3 appears in the same hierarchy as the message (for example "Test Passed") from BasicTest2 and the output from BasicTest2 appears outside of the hierarchy (I mean the parts you can fold) altogether. Was it designed this way or is this a mistake?
I really do not unterstand what you mean.
You say, that the output vom BasicTest 3 is like BasicTest2, and the output from BasicTest2 is outside? Outside from what? Can you explain your thoughts again?
Perhaps my english is not good enough....
As you can see, the visualization is equal for all testcases.
Ahhhhhh, now I understand.
But this is a generall CodeWars-problem/behaviour.
The output from a test is always shown before the test-result. And before the first test, there is no test-context.
Perhaps after the next codewars-update it will be better...
In c++, you've used the pow() function for generating solutions, but you haven't used the header file . This results in an error, hence revealing the critical part of the code for the functions solutionCountVisibleCharactersOfThePyramid() and solutionCountAllCharactersOfThePyramid().
Hi sanju,
i added the necessary headers into tests. Please check it. Thanks!
Hi Steffen, You asked for some feedback on your English descriptions. I would suggest the following improvements:
I don't know if it would cause major problems to change the function names, but "view" would be better than "watch." The use of the word "watch" implies that the pyramid will be moving or doing something.
Danke für diese interessante Kata in Javascript! Wie immer ist meine Lösung eine der längsten :-P
This comment has been hidden.
Gern geschehen. Übrigens: Es tut mir Leid, dass ich deine Antwort auf meine Vorschläge erst jetzt lese. Irgendwie habe ich keinen Hinweis darauf bekommen.
Zu Punkt 2 habe ich mich schon gefragt, ob das so gemeint war :-) Und was die Methoden-Namen betrifft, das würde mir auch nicht gefallen, wenn man meine ansonsten einwandfreie Lösung im Nachhinein wegen so einer Kleinigkeit ungültig machen würde.
Am Wochenende besuchen wir den C#-Programmierer (unseren Sohn) in Pittsburgh. Da er jetzt viel näher am Arbeitsplatz wohnt, wird er vielleicht ein bisschen mehr Zeit für Codewars finden, wer weiß?
Gerade gestern habe ich herausgefunden, dass 8 Schüler für meinen JavaScript-Anfängerkurs im neuen Schuljahr angemeldet sind. Einige haben schon bei mir Deutsch gelernt. Ich freue mich sehr darauf -- auch wenn es ein besonders anstrengendes Jahr sein könnte, weil ich als einziger Deutschlehrer an der High School täglich 7 Unterrichtsstunden habe. Ich bin froh, dass so viele Schüler Deutsch lernen wollen, aber das ganze Planen und Korrigieren usw. kann ich dann erst am Abend erledigen. Na ja, dafür habe ich dieses Jahr keine Pausenaufsicht!
Thanks for this kata
@SteffenVogel
, I enjoyed solving this one. As@Dentzil
already mentioned, great tests as well.Python translation kumited!
Also, I tested it using both versions of Python (2 & 3).
Approved!
Thanks for the great translation!
Wow, that was fast! I'm just glad it was up to your standards.
I'm actually working on another kata of yours right now (Vowel shifting). I'll try and approve it when I am done too (looks like
@smile67
was getting 500 errors).Very good translations are always approved very quick. :-)
Thanks for trying to approve vowel shifting. I just opened an issue on github for this problem.
I've been getting 500 errors anytime I click
Edit
on an approved kata too but I'll try to approve this one in a few minutes (just finishing writing some tests for my own repo).Could you try to approve this kata?
@SteffenVogel_79
,Looks like it worked! I ranked it 6 kyu because that was the consensus in the votes.
Thanks a lot!
New challenge for you??? :-)
https://www.codewars.com/kata/5782b5ad202c0ef42f0012cb
@SteffenVogel_79
,I just finished this kata,
Index Difference
, thanks for the link! I wrote it in Python first since I have more experience with Python over JavaScript. Then I just translated my solution to JavaScript.I will do the Python translation right now (as long as nobody beats me to it!). Since I have already written a Python solution for the problem, writing the tests shouldn't take too long!
Yeah! Python-Translation would be great!
C++-Translation kumited!
Signed, sealed and delivered.
You are as always very diliget in writing tests. ;)
Approved!
Thanks for the great translation!
This comment has been hidden.
Did two submits without error, but no "submit final button" appears... closing, opening the kata, a third try and it works... very strange;-)... What is it 7kyu or perhaps 6 - give me a hint;-)?!
Its your decision. :-)
Sometimes it's really difficult (the reason i often give my points without ranking;-))... We will see what happens, perhaps i change it later on... But good one, like such katas more than creating 100 objects and iterfaces without "task/problem" (you know what i mean;-))...
As you can see, switched it to 6kyu...;-) Someone else did it too, so i always (sometimes;-)) will be fair:-)...
Very nice. Thanks a lot!