6 kyu
Give me a Diamond
7,399 of 37,553jayeshcp
Loading description...
Strings
ASCII Art
Fundamentals
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.
Diamonds are forever
No random tests in Java
added
had to turn to chatgpt to figure out how to center the stars and the solution was so clever. If you know, you know.
this would be much easier and less confusing, if we'd use "_" instead of " " characters.
Not really, because then we'd have to end it with
_
, but this way we just drop the trailing spaces.too late now with more than 10 languages and 37,000 completions
This comment has been hidden.
you are hardcoding the amount of memory, even though the amount is dynamic and depends on the input. you do not allocate enough memory for large
n
and write out of bounds, hence the crashSo.... Is Jamie trying to smash James's girlfriend? I am very confused. Am I Jamie?!?!? My name is not Jamie. What does James's girlfriend look like? Maybe I can be Jamie.
Lua translation!
Approved
Nice Kata!
30 minutes spent cuz didnt see that last star should also have \n .....xd
My Rust solution should work, but adding the appropriately placed newline characters gives this result. This only pops up when the answer is correct - if I add a newline character at the start of the string, the test fails and no error occurs.
memory allocation of 9223372036854775806 bytes failed
Caused by: process didn't exit successfully:
/workspace/target/debug/deps/challenge-07bd72047d917620 --show-output -Z unstable-options --format json
(signal: 6, SIGABRT: process abort signal)The problem comes from your code. You are casting a negative number to
usize
, which results in a really big unsigned number. And then you use this number as the bound in a loop in which you allocate memory, hence the allocation failure.This one really took a toll on me! TvT
This comment has been hidden.
When your result looks like the expected one, but still fails, it is helpful to print your string between delimiters and escape whitespace characters.
For your situation:
for
n = 1
, this prints:"*\n \n"
while the expected answer is:
"*\n"
fiddly, im not sure what i learnt from this
getting this problem '\n\n*\n' should equal ' \n\n *\n' can anyone help?
A problem with your code is not a kata issue. Read the error message:
I spent too much time on this 😒
python new test framework is required. updated in this fork
Approved
Think i am making a mistake somewhere but i don't know where, any suggestions or possible mistakes i could have made. (in C)
some mistakes that i see:
size
bytes, but then you accessret[size]
, this is an out-of-bounds access, the last character is atret[size - 1]
ceil(n / 2)
is equivalent to justn / 2
, since you are diving 2 integers\n
), but you are not adding oneThanks for the response, i knew about that integer thing but didn't use it.
Thank you for this kata! Really enjoyed it! Gave myself an extra challenge for doing it in C.
How did you guys manage the formatting with JavaScript?
HELP, What does it mean?
expected '*\n' to equal '*\n'
Which language?
several problems with your code:
Scala translation
Approved
Really nice kata, but there is a problem with Swift. Some of tests fails till change return type from String to String?
fixed
For Swift: You have to manually change the return type from String to String? to solve this (Maybe this will get fixed in the future).
fixed
i used expressions like f'{"*" * i:^{n}}' and i've got a diamond,but it won't accept my solution.I got a result that is equal to the test result
Traceback (most recent call last):
File "/workspace/default/tests.py", line 6, in
not enough info, tests do not crash or generate warnings with the initial code in Python
Hello! My language is JavaScript. I got a result that is equal to the test result absolutely so I cannot understand what a problem passing the test is. I need your help.
Don't escape the backslash, it's
"\n"
, not"\\n"
.Thank you so much. It works well. Your advice was very useful and helped me to resolve my problem.
You're welcome.
Noone wrote a code in the shape of diamond, though) Well, who'll take the challenge?
I think James needs to find another line of work.
This was a very satisfying Kata.
It took me a LONG time to complete, but for each problem I had with my initial solution, a logical fix emerged.
Challenging without any funky edge cases, thanks.
I was able to complete this in Python and really enjoyed it! Great kata!
Unhandled rejection TestError: Expected: ' \n*\n \n', instead got: ' \n\n *\n' they are identical. What is the roblem here?
Amazing!
This comment has been hidden.
Please mention the language when reporting an issue.
I am sorry, i didn't read the assignment well.
Nice kyu.
C# Function name should use
PascalCase
Implemented in this translation
This comment has been hidden.
You can try to ask your question in the Discord group of Codewars.
This comment has been hidden.
This comment has been hidden.
Please use markdown to format your code, or it's unusable: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
Don't use global variables, they remain between the function calls.
C translation 💎 (author gone)
This comment has been hidden.
Approved :)
COBOL translation.
approved
This comment has been hidden.
It's just this point of the description: Return null/nil/None/... if the input is an even number or negative.
You need to use a special condition for those cases, which is what the line you added is doing fine. It's ok.
Those cases are sort of input validation. Nowadays it's better to avoid this in katas (it's not interesting and leads to have all sort of disparate exceptions depending on the languages), but this kata is 7 years old and a lot of katas included it at that time.
Since you solved the kata, I mark this question as resolved :)
This comment has been hidden.
Just three sentences (about guy and his girlfriend) at the start of the kata's discription, but it make this kata more "warm" and interesting. This is better than typical "okay, dude, here the list and here the task" in most another katas.
nice kata~!
This comment has been hidden.
It seems you have extra leading spaces at each line.
BTW this is not a kata issue (= a bug), maybe a question.
This does not work on Swift because you need to return either nil or String, but both options cannot be made in Swift. Either String or "nil"
You need to change the return type to
String?
. I think it's a mistake from the translator that should be fixed (?).if i change the return type to String? I will have to make force unwrapping to get non-optional answer, but the answer can be nil. Force unwrapping of nil is a error. I mean not "nil. I mean nil
I have no idea about what you're talking about (I don't do much Swift), but whatever, the fact is that, with a very few exceptions, all the published solutions do it, that's what the reference solution does, I did it too, and it works.
With Rust it's the same as in needing to return either a String or None, but it works fine for this kata.
I only had one problem with this task, the formatting for the result string was a little difficult to match. It initially seemed that the string was padded with spaces on both sides of the stars but it was not all of the time. It seemed as if the desired string by the tests would change. It may just be a qlitch but thought I would share.
This comment has been hidden.
Ruby 3.0 should be enabled, see this to learn how to do it
Please organize the structure of test fixture as following (although it has been mentioned in the attached link, I'm repeated here again)
Organized
approved
Please HELP, check the @verdugo's issue* below. There is a problem in Swift version of this question.
Best
A workaround is to use
String?
in the function signature.I close since this has already been raise as an issue below.
.
jamie bouta swipe james' girl.
Whew, my answer is way so much sloppier than most others. But hey, it worked!
This comment has been hidden.
This type of problem really shows my weakness as a developer and makes me want to quit my career. I don't know how people can visualize and break down problems like these and come up with a solution. It makes me feel like a friggin idiot.
relatable. feelsbadman.
If you really are into programming, if it makes your heart pound faster and you lose yourself when start to code, don't give up just yet! Take a look at my code: in terms of quality, it really sucks, nonetheless it works just fine. I know, frustration can be overwhelming, but just keep on going, man: either you think you can or you can't do shit, you're absolutely right. And one last thing: don't jump right into the code - pen and paper could be of great help.
Hope you don't give up and become stronger with time.
I wanna know if you quit after 4 years! You probably gunna be able to do it right now if you didn't quit :)) lol I just started as well but I feel that getting great coding skills takes so much time. I couldn't do this exercise right now but I will eventually. I know that. Cheers!
I’m really frustrated with this.
I either get:
cannot force unwrap value of non-optional type 'String' XCTAssertEqual(diamond(3)!, " *\n***\n *\n”)
orXCTAssertEqual failed: ("Optional("nil")") is not equal to ("nil")
.The test looks like it’s force unwrapping a non-optional type ‘String’, so is the test wrong? Also, if I change that test to not force unwrap diamond(3)!, I get the second error,
("Optional("nil")") is not equal to ("nil")
. Sometimes I get that error 3 times. No idea what to do. Also, all my tests work fine locally. Negative numbers, 0, 1, even numbers, and large numbers all work fine.No, You shouldn't my friend! This is a serious mistake for the Swift example. Example designed as a non-optional, but the Test case was written with an optional scenario. So, must be one or another, not both.
*** PLEASE, URGENT HELP ***
Everything depends on this question on earth right now!
Note: I was planning to listen to the "Rihanna - Diamonds" but now I'm listening to the "The Cardigans - Nil" song.
A workaround is to use
String?
in the function signature.fixed
I'm struggling to figure out how to 'center' the diamond. I'm able to output a diamond based on the input of an odd positive integer, but my diamond lines are justified on the left margin. I need to add the appropriate amount of spaces to the left side of each line (well, each line except the 'center'/ largerst line) - just need to come up with a clean way of doing it... Any suggestions? I'm using python.
Look for patterns. How much should each be indented, does that relate to any other known information?
I had to step away from it for a little while to clear my head. I think that I can use my counter, and the input provided (diamond size) to determine the amount of leading spaces. I just need to figure out how...
figured this out, thank you. Your comment helped.
center around the max value. the max value is already provided.
Sorry if this is just me being dumb, I'm stuck with the error: Test Failed Expected: null But was: <string.Empty>
I am returning a null value with : return null;
Is this not the way to do it in C#? I've tried googling but found nothing but discussion on the difference between null and String.Empty, which doesn't exactly help me.
Your code must be not reaching that line, because null and empty string are 2 different things.
I think you're exactly right, tried changing it to return a literal string and it's still labeled String.Empty, thank you for your help :)
Check your previous returns and try to see why it's returning early, or why it's not reaching the 'else' part. Console.WriteLine is your friend.
I had completely janked up my if logic. All sorted now!
so bed tests
Nope it's a good kata and very detailed description. Try writing it on a paper. Look for increament between diamond.
the test IS bad though. sometimes it expects a space after \n and sometimes it does not. I also completed this kata but could not pass the tests because my string doesn't have the same " " as the test, and there was no clear instruction for how he wants that or why it changes betwee values 1 and >1
Originally, as the instructions stated, I used null to return when n was either negative or even. However, only None is accepted.
Shine on, you crazy diamond!
Hi. can't really seam to get this one to work in java, when i run it on my own computer it works just fine, but when i test it here it fails, don't know if this is because i have done somthing wrong in my code or if its the test. If anybody have managed to clear it in java please let me know :D
This kata is perfectly solvable in Java, or at least I had no problem with it. I am closing the issue as invalid.
Maybe this FAQ would be helpful, or just tell us what exactly is your problem?
For what reason in the test add space before result string and in the reverse loop the same spaces but after each element?
Skipping based on the cliche sexism.
Came here to say this.
cereal??
Right, no woman would ever deserve a diamond ring. Treat them all like garbage. TB4L.
Just done the JavaScript version (and passed). However the description is not showing the multiple spaces for size 5 diamond. It shows as:
...that is: " *\n ***\n*****\n ***\n *\n"
which should instead be something like:
...that is:
Thanks.
Great Kata. I really enjoyed this one!
I think something is wrong with testing here. On my computer, all these tests pass. But here, on the server, it doesn't.
Hello everyone, for some reason I cannot make a for loop work. Does anyone else has the same issue?
I tried a simple loop as a test but the program clearly skips them; The solutions it gives me are totally empty, because I am adding "*" and " " inside nested for loops. The tests with 0, even numbers or negative numbers pass without problem.
I wrote:
for (int i = 0; i > 5; i++){System.out.println("BEANS!");}
but no BEANS!BEANS!BEANS!BEANS!BEANS!BEANS! in the log :/
Edit: this happened to me on other katas, but I just used a for each loop and no problems. I even tried a while loop and printed something, that works just fine...
Take a closer look at your loop declaration.
No wonder that your beans! are missing from the log I guess. (> != <)
Cheers
Thank you for the answer, I believe I wrote it wrong on this forum, as soon as I have access to my pc I'll double check! I kinda hope that's the issue though haha!
Beautiful kata! Print the string before returning it, if you want to see them :)
Challenge accepted! (even-sized diamonds are totally possible)
bad tests for task: why should there be at the end \n ? e.g. if n = 1 must be return \n (it may be just ), if n = 3 \n\n\n but \n\n will be th same visual result it is not necessary!
Go translation
this translation seems busted. it's not published, but I can edit it (i wasnt aware that you could edit other people's translations ...). However, when hitting
publish
, it always fails withKumite was published with failed tests!
, even though the tests do not fail. Another Codewars mystery !How does the instructions say "no trailing spaces" but then I get this result from one of the tests?
Expected: ' *\n \n**\n ***\n *\n', instead got: ' *\n \n**\n ***\n *\n'
I originally had no spaces but the code failed. And now the test expects random extra spaces between them? Especially weird considering the previous test passes with:
Test Passed: Value == ' \n**\n *\n'
But the second test wants two spaces before the first astrix?
The formatting of the comment changes some astricks into bold text... you'll have to trust me that they are there. The only difference between expected result is two spaces at the front. Which it only wants one space for the previous test.
Use markdown formatting when posting code here.
worked out my issue! nevermind.
This comment has been hidden.
not an issue, a question. you need to put some space chars on the left (the correct number)
This comment has been hidden.
Not sure what this error means: expected: < *
*[ ]> but was: < *
*[]>
The only difference between the 2 are the [] but I can't figure what's causing it. The program output is just as expected, and I made sure there wasn't any trailing white spaces.
You missed a new line at the end.
Response received but no data was written to STDOUT or STDERR.
That's a CW issue, not a Kata issue. Try reloading the page.
Reloading shouldn't help because this is the code runner saying no output (stdout/stderr) was produced by the submitted code. Most likely the solution crashed.
Someone might be able to help if you post your solution here, marking as a spoiler.
Thanks for your help! Indeed I had a spacing error when copying over from local machine. Thanks
This comment has been hidden.
Fixed description
Python:
No randomized testing.done
Ruby translation kumited, including updated description. Please check and approve
.
This comment has been hidden.
OP solved it, closing
lol f*** you, James, I buy my own diamonds
This is the best response to the weird intro.
I might be picky here, but it says "must implement the diamond(n) method". As far as I know, method is a function that's called from a certain object or a class, but here we have a plain function.
I would use suggestion for this.
description being shared through all languages, I guess we can pass over this one.
my codes include
print('something', end='')
which is unavailable in python2 :/Passing every single test except ONE in RandomTest/Tests Random Diamonds, 4th from last (just before 49). I get
which makes no sense because I return nil the second the size parameter is even or < 3. I can't see what the test case is doing so there's no way for me to understand what's going on. Using Swift 4.your logic is worng: what about
n=1
?This comment has been hidden.
This comment has been hidden.
STDERR : Max Buffer Size Reached (1.5 MiB). I'm getting this error inspite of all the test cases being passed. Help Please?
don't print to the console, that's all. ;)
Thank you, Blind4Basics
Hi there,
I'm seeing Execution Timed Out (12000 ms) for the random test but I can easily test sizes past 1000. Is this the same issue that Fr3qu3ntFly3r had?
Thanks!
try again, I changed the swift version. It should be good, now.
It works now ty!
Hey guys,
I have the same ServerTimeOut error, when I attempt.
I don't know what is in random tests, but in the sample test I tested it with Int.max and it passes without a problem.
Some pointers would be highly appreciated.
Thanks in advance.
server trouble, not kata trouble.I read too fast... x)
anyway, it seems there is a rpoblem with the swift version (already raised below), so... You'll have to wait for someone fixing that problem, sorry.
should be good, now.
I think this is why I give up with Swift in codewars. The tests run and pass in 6ms but the process timesout in 12000ms and fails.
Passed: 2 Failed: 0 Errors: 1 Test Results: SolutionTest Tests From Example (pass in 4.5ms) Tests Large Diamonds (pass in 0.3ms) Completed in 6.611ms RandomTest STDERR: Process was terminated. It took longer than 12000ms to complete
should be good, now.
I just tried it. It works now.
Got daimonds with \n tags and it cannot accept it as vaild answer. Why? c# Ok i Got it - I need to return whole string, not write it with Console.Write(temp); My bad.
This comment has been hidden.
Interesting problem, but the description was very unclear. I had to try a couple different things and see the errors just to understand what it was asking for. At the very least, having more sample tests showing a range of desired results would make it easier to figure out what's being asked.
(why the fuck not any language has the same sample tests than the others... x/ )
will be handled soon...
The instructions indicate "The line above and below will be centered and will have 2 less *’s than the middle line." The sample test expects " *\n*** *\n" which aligns things to the right, not centered.
This comment has been hidden.
not an issue.
This comment has been hidden.
should be good now.
This comment has been hidden.
Don't post an issue if something is wrong with your code.
You could post your full code here as a spoiler if you someone to help you with it
This comment has been hidden.
Not an issue
From what I see, the tests don't fully meet the requirement. Am I suposed to add more tests?
This comment has been hidden.
gah ' * \n*\n * \n' should equal ' \n\n *\n'
It fixed.
Swift 3.1.1.... can't submit a valid solution. It times out.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
My code passes the sample tests and runs great in a playground, but when I click "Attempt" I get a Server Error: [object Object] output. Any idea what that means?
I pass all sample tests but when trying attempt tests I have an error: [object Object]
"The shape that will be returned from print method resembles a diamond ..."
Like others here I spent a ton of time displaying the diamonds in the diamond function instead of returning a string that has the appropriate amount of whitespace and new line returns so the shape can be manufactured by the calling routine.
For me, the instructions are not clear enough for beginners learning python.
#java I'm passing the tests but why I run attempt I get timeout errors. I don't get it, the code does not take that long...
For those using Python, be aware that this Kata is only working for Python 2.7.6 , and therefore the functions may act differently than you are used to with Python 3! It caught me out for a while.
This kata seems to have issue with running tests using Swift 3.0 All sample tests were passed. However, when you try to attempt it, it keeps producing ("Optional("nil")") is not equal to ("nil")
I am sure, I am not returing an optional value. If that was the case, sample tests should not have been passed.
shhould be good now.
This was quite a satisfying problem to work on. The trailing spaces once was a bit of an issue since it's not clearly visible...had to keep highliting the text to check them. The trick is to write down the number of '*' and ' ' in a given line wrt to 'n' on a piece of paper to see an emerging pattern.
This comment has been hidden.
To everyone who has problems with this kata, make sure you don't have any trailing spaces.
I spent probably far too much time on this, but it was great practice. I didn't have any problem with the description, just with overcoming my own mental hurdles.
This comment has been hidden.
This Kata is a not worth effort and time. Even I print correct diamond I can't pass those test cases.
This comment has been hidden.
python version for sure.
This comment has been hidden.
This comment has been hidden.
I'm consistently able to generate arbitrarily large diamonds, however, I'm failing most of the test cases. I've attempted to prepend a new line at the end before the final string return, and still not getting the proper result. Has anyone had other issues with seemingly perfect diamonds failing the tests?
I am, I think the author is appending a new line character before making sure that the asterisks are aligned
not an issue.
rubbish task details, don't need the stupid story
The tests don't pass even if I get correct output. Am I missing something?
Another one
You have trailing spaces in your answer
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Can this kata get a less "girls like diamonds herp" prompt?
This comment has been hidden.
the test values include negative integers. make sure your conditional logic takes that into consideration.
This comment has been hidden.
This comment has been hidden.
Please see the test cases, they clearly show that a new line has to be added after the last
*
in any row. Purpose of having test cases is to document how the code behaves, and should be used for building the solution. Thank you.I don't think he can see your message, because you hide the comment, but he doesn't solve the kata.
But he has a way that is post a reply, and then he can see your message.
The task asks you specifically to print the diamond, but the tests only accept return. I spent hours trying to find what I did wrong before realizing that the author of the kata simply just lied. That's not acceptable. Boo.
"but the tests only accept return". Can you please explain what you mean by that ?
The tests aren't looking at what was printed (ie, to the console) but instead are looking at the string that is returned when the method is called.
Correct. The task says the challenge is to
print
a diamond. The challenge is actually toreturn
a diamond. The problem is that I would have tried both if the description didn't insist thatprint
is the correct one."The shape that will be returned from
print
method resembles a diamond..."I see now that there is a misunderstanding, and that the description technically speaking isn't completely wrong, but you'd have to be very lucky to decipher the description(well, to first assume there is something fishy you would have to be extremely cynical).
Wow I spent so much time to figure out why my code failed the tets. Thank you!
have been handled on the description side, at least... :/
This comment has been hidden.
well, I'd like to see you print a negative asterisk. Or eat a negative apple.
I think it's self-evident that you don't accept negative input. (or input below 2, for that matter)
Well yes it makes LOGICAL sense, this is a program. We should be told what to do, especially since we're told how to handle even numbers. How hard can it be to add more detail into a description?
It told you to print a diamond with a certain absolute width. Something cannot be (-x) units wide in absolute terms. Therefore you cannot accept the request for a negative width. You might as well ask why it doesn't specify not to accept a dictionary of the word "yo" repeated. It's simply outside of the logical validity of the task. Sorry for being crude, but expecting to be explicitly told not to do things that are clearly inappliccable is just picky. You won't be led by the hand in real programming. In fact I think these tasks are a bit stupid at times, with how they remind you to not accept empty strings for algorithms that can only apply to ones that are not. If you do programming, knowing what kind of variable to accept is the very basics.
That being said, I'm no expert. People have different backgrounds and contexts for reacting to different things. But not being told every minor detail is just something I think everyone should get used to. The entire point of programming is to invent.
This comment has been hidden.
I have a Python solution to this that works with any number I pass to it, but when I submit to this Kata, I'm getting this error:
✘ None should equal ' *\n***\n *\n'
What does this mean?
The problem is that it asks for the function to print the diamond. Guess what, it only accepts return. You're not supposed to have the word print in the whole damn thing. So I wasted hours on trying to debug when the only problem was that it doesn't give you the correct information.
This comment has been hidden.
range in Python 3 is the same as xrange in Python2, so just use range :)
handled
This comment has been hidden.
I just revisited this & managed to resolve the issue.
For some reason, manual casting is required on the online compiler. I had to change the lines that use
math
to:Does anyone know why casting is required to be explicit on the online compiler, when implicit casting works fine on an actual native compiler?
I wrote code which correctly produced diamonds, but the test kept failing because apparently my diamond wasn't the same as the desired diamonds. The 'expected' and 'actual' output seemed exactly the same and it took me over an hour to figure out the difference; the test expects a newline appended at the end of diamonds.
This shouldn't be a requirement. It's not listed in the requirements and the tests don't really show this either. I wasted an hour tracking this down. I want my hour back.
It doesn't help that the 'actual' test output always has a space character prepended, further confusing me/the programmer.
✘ Expected:" "pre *
instead got :pre *
I am having the same problem as you. My diamond comes out perfectly but isnt passing because they included that uncessary space between : and pre.... not sure how to get through it?
Thank you man for clarifying this <3 You saved me from alot of hassle! I had the exact same problem and it was very confusing for me because my diamonds are working fine ..
This comment has been hidden.
This will happen if your code is creating an infinite loop. Check all your loops to make sure you aren't going off the rails.
OP solved it, closing
Hi its killing me. But why does
if not n: return None
not satisfy the test case: '' should return None?This comment has been hidden.
I'm able to print diamonds in Eclipse, but I don't know how to return my printed output as a single String like it wants me to. Can anyone offer any hints?
it will not show as single string. In the console, the '\n' will show up as a new line. Your tests should pass;
I have attempted to submit but get a failure on the 4th test: '' should equal None. I though this might be saying that an empty string for n (i.e. an invalid input) should return None but I got that working and it tested just fine. Could anyone offer insight into what that failure might indicate that they are testing against?
Probably how your function is handling a negative number as input.
That was exactly it. Thank you!
Can someone explain what the square brackets mean in the test cases?
expected:< *
[] *
[*** ] *
I'm not sure why my square brackets have three stars in them, but the example doesn't. Also very confused as to where these brackets are comine from. Any assistance would be greatly appreciated!
This comment has been hidden.
.
My diamonds are good, but test still fails. Maybe problem is in outputed string. That should exactly match, not diamonds. Example for string: " \n**\n *\n". So, no space characters on a end of every row. Am I right?
I did it in java script and the issue I had was adding a '\n' at the end. Please try that in the final statement. add a '\n' to the return string.
I am getting the proper diamonds but still failing. Can someone help?
Not sure about the use of platform-specific line ending '\n' - IMHO we should be encouraging the use of techniques like StringBuilder.AppendLine() instead.
Where is the error here?
Expected: *
Can anyone help me understand why I keep getting error TypeError: Object has no method 'repeat' on here? When I run the code on repl.it, it works fine and meets requirements. I've read others have the issue, but the solution is a spoiler so I can't see it. Please help :)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
It is not resolved. I am still getting the same error. Seems like tests are running in environment withou ''.repeat(). All you have to do is define it yourself:
String.prototype.repeat = function(n) { var ret = this; while(--n) ret += this; return ret; };
Can somebody explain why this doesn`t pass? // * //*** // * None should equal ' \n**\n *\n' It actually draws a diamond.
.
if anyone is having problems with the final tests even though they look the same you apparently have to add one more "\n" to the end. That's all i did and then it passed the final tests. Also my code wouldn't pass the test case because the first test expected result comes out like this //* //*** //* when it's supposed to be centered. so i just went straight to the submit hiddent tests
Why n = 1 should display *
This comment has been hidden.
Read this part carefully -->
Return null/nil/None/... if the input is an even number or negative
This comment has been hidden.
This comment has been hidden.
if you are getting diamonds but failed just few tcs? make sure you return null for even and Negative numbers also
I can print out a perfect diamond shape with * characters, but it says I failed.
Getting diamonds but not passing the tests? Remember to include the final '\n' in your result!
already stated in description
This comment has been hidden.
If you could post all your code it would be helpful :)
This comment has been hidden.
This comment has been hidden.
There most likely are white spaces but when using console.log it prints it in html format and the spaces seem to join dissapear, if you want to easily see the spaces just do a replace with another character when you print the string. Good Luck! :)
behavior of the console changed since that message.
(Python) After 3 successful tests I'm getting: Traceback: in in diamond MemoryError
Can anyone help me figure out what that means?
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
done
JS translation kumited.
(Description modified; 'print' renamed 'diamond' as in Python version)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
(n&1) == 0. What is this line doing?
It checks if a number is even. Just an alternative way of saying
n % 2 == 0