7 kyu
Monotone travel
582 of 6,748bkaes
Loading description...
Lists
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.
python new test framework is required. updated in this fork
Approved
This comment has been hidden.
Fixed in OP's fork
Description is confusing, decreasing (or non-increasing) sequences are also monotonic...
COBOL translation (author inactive).
approved
This comment has been hidden.
Fixed in latest fork
Wrong example in Kata description causes unnecessary confusion.
I don't think so.
Looks to be a problem with
C
translation only?my error. fixed, thanks
Not the best description. Some users think the items should never drop below the first item, others (like me) read it as there should be at least 1 element for which all successors are either the same or bigger. Make it clear that by
any
you mean that the condition should be true forall
.I managed to come up with something in Python that works and it was accepted, but when I tried it again (the exact same code), it said "should work on random lists: True should equal False". Not sure why that is
It's means that your solutions fails in a random test. "True should equal False" means that the test expected a False and your functions return True. I just checked your function and works fine but if you want you could print the inputs to see when your function fails. Happy coding!
Thanks, I refactored it.
top kata
C translation kumited
please scrutinize for approval
domo!
Thanks :)
Note that the first test is
is_monotone(range(1, 11))
, which will fail for Python 3 (becauserange
returns arange
object and not a list).According to the descriptions the input should be a list, so this is not correct.
Fixed
"Your job is to check whether for any x all successors are greater or equal to x" - so how come int a = {3, 2, 2} is a false?? Any which means a1 == a2 - so it should to be true.
The task is to check for any
x
, all successors are equal tox
or greater. In this case,x
refers to any particular element in the supplied collection, where successors would be any elements that come afterwards. It's kind of weird language, but basically the task is to check that, if given any element in the array, all succeeding elements are equal or greater.My mistake :/
This comment has been hidden.
CoffeeScript translation kumited! Please Accept :D
Just a heads up on this one. Do not modify the heights input parameter.
The random test case was failing for me because I modified heights. I made a copy of heights instead and the test case passed.
(I did the python version)
This comment has been hidden.
Never post your solution as a comment, unless you have a problem.
I had problem submitting the solution with 'unknown error' that's why posted the solution code here. Please check my previous comment.
Don't know why my code won't work. Getting 'unknown error' while submitting though all possible test cases including kata tests are passing.
See https://github.com/Codewars/codewars.com/wiki/Error-messages:-Unknown-error. There's nothing I can do about that.
Thanks for the pointer @bkaes
This comment has been hidden.
Make sure to place your code between three backticks:
That being said, your
for
exits after a single step due to yourelse
.Wow thank you so much bkaes! :)
This comment has been hidden.
The description, example, and tests don't make it clear that each consecutive number must be equal to or greater than each previous. I had taken it to mean that they must not dip below the starting altitude. Clarification on that point would be helpful. Maybe just another example like isMonotone([3,4,3]) == false
This comment has been hidden.
You're attempting to iterate through an empty array, which seems to be the problem here. Be sure to use your conditional statement outside of the for-loop.
As Daredevil mentioned, putting the length condition in the for loop is the problem. When you get an empty array in input, the for loop never runs! So, none of your return statements are called. The function returns undefined by default which leads to a failed test.
Also, your function won't work on lists like
[1, 3, 2]
Because you return true as soon as you find an element being smaller than the next one instead of checking if all the elements satisfy this property.thx guys, I was feeling confused but now it totally makes sense.
Can't submit working solution, due to this error: "test.hs out of memory, requested x bytes"
This comment has been hidden.
The list can be infinite. Check the last public test:
You need another approach (hint: this is possible in O(n)).
Thanks for your hint.
This comment has been hidden.
That has been reported several times, but cannot get fixed due to current Codewars editing restrictions.
I am unable test my program, submit button does not work :-(
That's a codewars issue, not a kata related one. I've noticed a sub-par performance on Codewars lately. If the error persists please file an issue on the github page. Otherwise, if the Submit button works later on please resolve the issue.
It's interesting.How to put the own code in here.
This comment has been hidden.
Sorry for the late answer. Actually, your algorithm is completely off, you return after the first comparison. Did you try some more examples by hand? (Also, this isn't an issue, but a question)
hey,
my code passes all the initial tests, but when i want to submit my solution, it fails about 20%-25% of the final test. I have no clue why. can anyone give me some pointers?
Add your code in a comment. Don't forget to use proper formatting.
Seems to work, but fails sometimes? Sounds like edge conditions. Are you dealing with negative numbers? Empty sets? Sets of all the same number? Try to think of worst-case situations where your solution might fail.
This comment has been hidden.
Inspect the argument in your second to last line. Try
[1,2,0]
. What happens in the second to last line? What should happen?Thanks, thought the splice function worked differently.
Great. Keep in mind that you can tag top comments. Your comment could have been tagged as "question". Tagged comments can be filtered, that way, one can see questions/issues/suggestions a little bit faster.
I fail the constant list test in CodeWars, however my code works in my text editor. Can someone point me in the right direction? The CodeWars output doesn't tell me anything.
You could post your code in a comment. Don't forget to use correct markup and mark it as a spoiler.
This comment has been hidden.
Ok, go through your code step by step with the following input:
[0,0]
. It should return true. Why doesn't your code? How can you fix this? Then, keep in mind the following instruction in the description:Thanks, I guess I should have read the details more thoroughly!
This comment has been hidden.
Unfortunately, the test cases are locked, so I cannot edit them anymore :/. Also, the Python translation and Ruby translations aren't mine, but where provided by other warriors. (That's the reason I would really like a beta for translations)
No use keeping the issue open then.
This comment has been hidden.
This comment has been hidden.
Many thanks for looking over my code and spotting this :)
I translated it into ruby: I admit it was a bit tricky with the random arrays (I had little experience dealing with it), but it all should be fine now, in case you want to add it to this simple, yet entertaining and stimulating kata :)
This comment has been hidden.
This comment has been hidden.
What does the "||" in "heights = [Integers] || [Floats]" mean?
It's either a list of integers or of floats.
Thanks for your reply! Why use 2 "|" instead of just 1? I thought "|" itself means "or".
In C-like languages (or C styled languages like C, C++, C#, Java, JavaScript, …),
|
is bitwise or, while||
is logical or.My solution clearly shouldn't pass.
I.e. you need to make a copy of the original array to compare against otherwise it can be mutated in the solution.
My first solution, which should have worked, didn't pass because I mutated the array.
Done. Next time I'll probably use
var expect = function(should, is){ Test.expect(is, should); }
, which circumvents the problem a little bit.This comment has been hidden.
This comment has been hidden.
Monotone is a common term to designate either increasing or decreasing sequence/function. So your kata and test cases are very ambiguous.
In mathematics [3,2,1] is monotonic for example [3,2,2] too.
Neither nor are:
That makes clear that we're looking for non-decreasing sequences.
I am a bit annoyed by: "isMonotone([3,2,1]) == false"
Hm, I get that, but a change at this point would invalidate 190 solutions. In JavaScript/Python, one could easily fix this with some preloaded code and/or undefined checks, but the Haskell solutions wouldn't be salvageable if one would rename the function to
isNonDecreasing
.This comment has been hidden.
That's not the "official" documentation, but just a simple page of the Haskell wiki. The wiki provides many solutions to many problem sites out there, even to Project Euler. Also, nothing hinders one from posting the problem on StackOverflow.
IMHO this is a 6kyu or 7kyu kata, so it probably exists somewhere and has a solution ;).
Some typos in test cases
Anything else beside the typo in "decreasing"?
Was ok for be beside that