Draft
Merge sorted arrays without built-in functions
112szepnapot
Loading description...
Arrays
Logic
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.
Unpublishing a a duplicate.
I have this error?? Traceback (most recent call last): File "/workspace/default/tests.py", line 1, in from solution import * File "/workspace/default/solution.py", line 1, in from preloaded import * File "/workspace/default/preloaded.py", line 22, in test.expect(False, "Cheater. Do not use {}.".format(check.group()), allow_raise=True) ^^^^ NameError: name 'test' is not defined
I have the same problem. Have you found a solution?
You're using something the kata considers "cheating" - probably
list.append()
if I had to guess. Unfortunately the error message is itself bugged. Hint: You can finish this kata with no calls to any methods other than the one you're defining, if you choose to.I did not use any function or method
@beshoynabeih try changing
sorted_array
to something else. I think the anti-cheat wrongly flagged your solution because of that.Code fail is because merely the chars
sort
appear in the code (it doesn't even matter whatever chars may directly surround them, or whether they're in a comment), same withsorted
.Meanwhile, this should (probably) stand as an
issue
for two reasons:NameError: name 'test' is not defined
means the kata needs to be Python updated (afaik).Cheater. Do not use {}
does not inform the user specifically of the reason for fail@Mednoob thank you it helped me.
You're welcome. Marking this as resolved, then.
I think if basic functions like
len()
are disabled, exceptions should be disabled too...If the length of arr1 is n, and the length of arr2 is m, it is possible to do this in O(n+m) time with O(n) (or O(m)) auxiliary space
You should disable built-in functions min/max to prevent solutions like mine.
By the way like kata a lot.
Already raised as an issue.
The anti-cheat is still imperfect.
There is no specification as to what to do if there are duplicate values (either in one array, or across both arrays).
If you're writing random tests you'll have to deal with that.
Seriously!? Not an issue. You sort them, that's all.
Test with duplicates added, anyway.
Well, for some requirements it's required that duplicates are skipped, so...
but that wouldn't be "merging" only, that would be "merging distinct elements" or somehting assimilated. Even if the description is far from perfect, it's impossible (unless the author being a troll) to forget to mention something like that. So it's clear on that side. ;)
There are no random tests.
done (even if, considering the number of tests... But might be they weren't containing arrays with duplicates. I didn't check)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
still the same, it will depend on the context... ;p (maintanability, readability... ;p )
I didn't understand that part. May you clarify please?
This comment has been hidden.
I don't see your point/the problem... :o
You don't need anything fancy to do this. I like this kata, it relies on basic skills we lose when we're too dependent on one-liners and builtins.
Isn't this a duplicate?
https://www.codewars.com/kata/mergesort-merge-function https://www.codewars.com/kata/merging-sorted-integer-arrays-without-duplicates
yep!
big work here...
I invalidated 2/3 of the previous (cheating) submitted solutions... X-D
This comment has been hidden.
not anymore... :p
xD
Well, you still can do this :P
damn thats cool
not anymore ;p
What about this then? xD https://www.codewars.com/kata/reviews/57cc66e1a362c1d44d0000af/groups/5a51184d59513a9792001846
it's python... meaning it a bottomless pit to try to lock all the cheating ways. :p
haha xD
invalidated anyway :p
whelp I'll stop now. :P
HA! ;)
For the second test case the required output shows [-5 -3 -1 0] which should be. But in the running window error pops up saying '[-5 -3 -1 0] should equal [0 -5 -3 -1]' which's also contradictory to other test cases . Problem in Python version :(
swapped assertion. That was your output that was wrong
Instead of trying to disable the builtin features why don't you implement your own list like data type that supports only the allowed functions?
Great idea! It would be more fun to solve and cheat :) First thing I would do is to convert those to
list
and than back.This comment has been hidden.
This comment has been hidden.
The arguments of
assert_equals
are in the reverse order.done
Does this kata really want no built-in functions? Like not using len() and others listed here? https://docs.python.org/3/library/functions.html If so, perhaps explictly forbid them. All but 1 answer so far includes at least 1 in-built function.
This comment has been hidden.
This comment has been hidden.
Can you disable the built-in methods by simply reassigning them? e.g. len = None. This seems to work in interactive python.
This comment has been hidden.
I don't really know how to disable built-ins...:S The main idea was to totally forbid them, but I couldn't find a workaround while working on this kata.
Can you guys check it now? Found a way to disable the built-ins, updated the description etc.
How did you try to do it? I can still do
l.sort()
andl.__len__()
. Also I noticed another solution importing sorted from builtinsthat's how I tried it, but couldn't find a straightforward solution to reassign every possible function. What you guys suggest?
I asked this on Stack Overflow and I am convinced there is no simple full solution http://stackoverflow.com/questions/39355608/disable-python-in-built-function
This comment has been hidden.
I erased the
append
andpop
parts because those are object methods, not functions. So they were never called.