6 kyu
Pyramid Array
1,015 of 19,244sahglie
Loading description...
Algorithms
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.
Description should be language-agnostic
done
I was able to hardcode it, as tests only go up to 20. Maybe make that 1000.
what would be the point of that ? your code is much longer and more cumbersome to write than a legitimate solution.
C: Are there any known issues with the tests for freeing memory? I'm fairly confident in my solution, but I'm failing on test
memory_should_be_freed
with the error "you allocated more memory than you freed".The
printf()
calls in your solution allocate memory on the heap, which I had not foreseen when detecting memory leaks. Should be good now, your code passes the tests.C:
free_pyramid
is not tested and tests pass with an empty code in it. It should be either removed, and tests should free the output, or controlled (if possible?) and make it an explicit requirement (though I see no special reason why this should be done in this kata and not in so many others).The setup in C seems to be similar to what I used in the C translation of "Observed PIN" kata, where tests put no requirement on exact allocation routine, but require users to provide a symmetrical deallocation function. This setup has some advantages, but it proved to be problematic in context of CW. It's in my opinion good because it does not introduce unclear requirements on ownership of a returned array, it mimics well real-world APIs, and is more universal. It might be not well suited for CW because apparently some users seem to be confused by it, some consider it an overkill (which I think is incorrect), and, as you noticed, not all parts of it can be reliably tested. There's no good way to test a deallocation routine, because it leaves no effect which can be easily inspected.
You can see some discussions in the discourse of "Observed PIN" kata, where the pattern was discussed on several occasions. I like it, I'd keep it, but opinions can vary.
Added assertions to catch memory leaks.
Most katas do not require users to allocate a multi-dimensional structure/array on the heap, so freeing the returned pointer is usually sufficient. It is not here, because we are working on a dynamic, jagged, 2D array.
Of course, trying to catch all memory leaks from the user in all katas would be silly; but in this case, the freeing function is an integral part of the kata.
Mentioned in description that this would be tested.
I concur with several others; this challenge felt more aligned with a 7 kyu level.
ranks are shared across languages and wont be changed (note that not everyone uses Python)
I wasn't able to complete this kata on my own (that's a bummber). But thanks to the top solution. it was really easy to understand.
Not a 6 kyu according to me, more like a 7 kyu.
At least for Python 3.
ranks are shared across languages and wont be changed
How is it possible to be so stupid I can't figure this out? It's astonishing.
hhhhhhhhhhhhhhhh
What is "hhhhhhhhhhhh"? Apparently I figured it out three hours after I wrote that.
Update to Scala 3
,
i like cheeseburgers. does anyone like cheeseburgers?
easiest kata for 6kyu..
7kyu katas are harder than this one..
Missing return type in initial solution of TS
added
Implemented in this translation
Approved, thanks!
Implemented in this translation
Approved, thanks!
Good kata for beginner
It's a good Kata. Maybe a little easier than 6 Kyu for most languages. I did it in C which requires some knowledge of double pointers, pointers, memory management, etc... which I think a 6 Kyu is sufficient. Took me forever to realize my mistake... I was trying to free the address of a pointer rather than the pointer. Facepalm All because of a simple '&'.
All in all good Kata. For C programmers, 6 Kyu is accurate. Other languages will probably be easier.
This comment has been hidden.
I don't know why I'm getting this results. Repeatedly. [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 5, 1, 1, 1, 1]]. Other thing that I don't know why and which drives me mad is why I can't use Ctrl+V in the comments!!!
seems a bit too simple for 6 kyu
IMHO kata 'overranked'. Though ideal for beginners, and 'KNOW your STL'.
2nd try easy mode
Yeah, def not a 6 kyu
And why even NULL for 0 in C? The only thing it does is adding an unncecessary special case making memory management more complicated.
fine, this is not required anymore
Immutable structures aren't typical for C, so I'd expect the subarrays in the result to be expected not to be shared, but this isn't tested. (Alternatively, it can be made clear that this is allowed.)
i can add a check to verify that the initial row addresses are not the same, would that be enough ?
I'm not sure, they can overlap with different addresses, so I'd probably change one array in the tests and check the rest or sort pointers and check differences.
This comment has been hidden.
C translation (author left Codewars)
Rust error on submission:
error[E0061]: this function takes 2 arguments but 1 argument was supplied --> src/lib.rs:28:25 | 28 | let n = rng.gen_range(0..21); | ^^^^^^^^^ ----- supplied 1 argument | | | expected 2 arguments
Sorry, I messed up the config when deprecating 1.44. It should be fixed now. Try refreshing the page.
It works now, thanks.
Java translation kumited. Please review and approve.
approved
Rust translation kumited.
too easy
This comment has been hidden.
Please read this: https://github.com/codewars/codewars.com/wiki/Markdown-Formatting
Not a kata issue.
answer
isstatic
, so it may not be empty when the function is called multiple times.Is it really worth 6 kyu?
No. I would put it at 7 for sure.
Groovy and Scala translations kumited. Please review and approve. Thanks, suic
This comment has been hidden.
CoffeeScript, Clojure, C++, Crystal, C#, Dart, Elixir, Factor, Elm, Go, Haskell, JavaScript, Julia, Lua, PHP, Racket, Reason, and TypeScript translations kumited.
Gosh! I only know C# and JavaScript, but both of those transitions look good to me, so I've approved those.
Too many translations? :P
When you start providing translations on punch cards, it might be time to slow down :)
Well, when I have that many translations, sometimes I do them a bit too fast. :P
This comment has been hidden.
I'd change
<=
to=
in the Factor example solution. There are no tests with negative numbers. This is confusing. ( It works, though. )0 [1,b]
returning{ 1 0 }
instead of{ }
is ridiculous, of course.done
This comment has been hidden.
Forked everything to fix merge conflict.
Approved Factor.
Then edited the description; everybody can make do with the same example. That probably fscks up your merge conflicts again, sorry :o I didn't realise you had made umpteen translations; I only saw this one ( I worked from Sidebar -> Translations, not this comment ).
Forked them all to fix merge conflict again T_T
Swift 5 translation kumited. Please review and approve if acceptable.
Issues:
Regards,
suic
Plus:
test.expect
Added sample and random tests, plus added a python translation :-)
Nice kata, thanks!!!
This comment has been hidden.
This kata is not about algorithm, but the reference of the language.
The parameter should be called "number" rather than "numbers". It's a single value.
Right you are. I've updated the code, thanks!
Not sure why my solution is not working. I output exactly what the examples are.
Which test case is reporting failure?
Nevermind I had a brainfart. i was outputting [ ] , [[1]], [[2], [2,2]], [[3], [3,3], [3,3,3]]. Instead of just putting 1's in. I even put that in my tests /facepalm
This comment has been hidden.