I think test 2 is wrong. Is x=0 monotonically increasing? I think not.
I think test 2 is wrong. Is x=0 monotonically increasing? I think not. Why is assertion made against true then?
Does anyone know why this is not working? The code looks chunky, but it should work. Thanks!!
string1 = ['tf is true'];
string2 = ['tf is false'];
tf = diff(x);
w = numel(find(tf==0)) + numel(find(tf<0));
if w > 0
 is monotonically increasing, but [0 0 0 0 0] is not. That's messed up. I agree with Kye Taylor.
All solutions with size 11 use the regexp cheat.
 isn't going anywhere by definition. It makes no sense that it's 'increasing'.
I agree that  should give false by this function, it's not monotonically increasing or increasing at all, right? I also think the test suite should include some vector like [-1 2 3 3] that is sorted but not mon. increasing.
Monotonically increasing means that it is never strictly decreasing.  is monotonically increasing for this reason, as is any constant vector. This problem should be restated as: Determine if the vector x is "strictly" increasing.
Nice one :D
between 'monotonic' and 'strictly' increasing.
Test 3 is incorrect isn't it? By definition, the following is monotonic, and hence also monotonically increasing:
x = [0 0 0 0 0];
One easily understandable size 15 solution is (use rot13 to read it):
shapgvba gs = zbab_vapernfr(k)
gs = vfrdhny(k, havdhr(k));
for i= 1:(length(x)-1)
if (x(i)< x(i+1))
it is providing correct result in my pc but not accepting here
@Sankari Name, Dawg, replace "disp('false')" and "disp('true')" with "tf=false" and "tf=true" respectively. see below,
for i= 1:(length(x)-1)
if (x(i)< x(i+1))
but your code wont pass the test where x=
The [former] second test case of x =  has been removed due to its tendency to cause confusion.
Also, the test case with x = [0 0 0 0 0] has been removed since it was originally marked as false. Technically, a monotonic function "is either entirely nonincreasing or nondecreasing" per Wolfram.com. Per this definition, that answer should have been true, as it would also be true for monotonically decreasing.
can someone explain to me why this code is not good for this problem
function tf = mono_increase(x)
if x(i+1) > x(i)
tf = "true"
#1, you are returning strings of true and false instead of true or false values. Do not use " in the solution.
#2, you are returning a true or false value for each comparison, with each prior result being overwritten. Only the last value will be returned by the function.
Single line solution.
Nice problem. You have to take care of the inequalities.
Eh okay. I dislike this problem.
First, I used a "for loop", but the results were often not logical/ reliable. I than used
a = 1 : 1 : length(x) - 1;
if all( x(a) < x(a + 1))
tf = true;
and it worked. But why can't I use a "for loop"?! I feel like I did not learn anything from this
Compare the number in current index with the number in next index. If it is less than or equal to zero return false.
I truely hate this
I have got some good news for you - These solutions are not valid anymore!
I don't understand your solution?
Hi Hidd, that is logical. The leading solution system is a bit broken, there are a few ways around it. That is why people are calling attention to fixing it. But as far as I know it's existed for 2+ years.
tf=true; % adding a condition for single element
return %we must close the case for faster operation
for ii = 1:(L-1)
if x(ii+1) > x(ii)
tf= true ;
kinda cheated but test values were stupid
in the test suite, test number 3 tests for vector [0 0 0 0 0] if it is monotically increasing, but in the assertion it claims it is false, meaning it is not monotically increasing, which i dont think is true.
the assertion should check it as true.
this is from wikipedia:
[ A function is called monotonically increasing if for all x and y such that x <= y one has f(x)<=f(y) ]
the (issorted) function should be enough to check for monotically increasing.
How is/isn't x = ; monotonically increasing vector when there is no other element to compare?
*Return true if the elements of the input vector increase monotonically (i.e. each element is larger than the previous). Return false otherwise.*
Good pblm ..try with length(unique(x))==length(x) and all(diff(x))>=0)).tis shd be the hint for the pblm
Thanks for the hint
you are using MATLAB in a C++ way lol
One easily understandable size 15 solution is (use rot13 to read it): shapgvba gs = zbab_vapernfr(k) gs = vfrdhny(k, havdhr(k)); raq
Did it in one line...but took me a while to figure it out. Matlab n00b
Nice one ☺
is that guy real :'D
Can anybody helpe me? What's wrongs with this?
What's wrong? I tried it on the matlab desktop,it's okay.
same problem here
sort(x) will always return a increasing vector.
So all(diff(sort(x)))>0 is always true, if x has just unique elements.
function tf = mono_increase(x)
tf = false;
if x(1,1)>=y(1, length(x))
%this is compiling in matlab with all inputs
Could someone help me? I don't know why it's wrong.
You are returning the character strings 'true' and 'false' instead of the logical values true and false (so just remove the quotes).
This solution code must have sth wrong. When i run this code on my matlab, it will give the right answer however when I run it on this web, it doesn't work
true and false are booleans. 'true' and 'false' are strings. It's not the same thing.
Can't improve more. Any help (trick) is appreciated...
the sign function is not needed
I don't understand why this solution is wrong, can I get some help please?
This code returns the strings 'true' and 'false' instead of the logical values: true and false.
Where did I do wrong？Please help me！
You fail test 2, since the vector x has length 1, you never evaluate anything in your loop. This can be fixed by initializing tf before the loop.
Look into recursive solution instead of this loop.
Why are you incrementing the solution with i=i+1? The for loop automatically increments from 1 to n-1. You are also only really testing the last two values in the vector. Your function returns false for each pair in vector but overwrites tf = false with true when it reaches the last two entries. You need to break out of the loop if you detect one false.
This doesn't solve the problem...
lots of things dont.
This will return true for vectors like [1 2 2 3] that are sorted but not monotonically increasing. Try changing the last if to
if length(x) ~= length(unique(x))
Mattias is right!
this is the solution right???
Nice work, champ.
where is the problem here? it gives coreect result in matlab
tf should be TRUE or FALSE, not a string
I dont see any problem in matlab. what is the problem here ?
Can anybody explain me, why this solution is smaler than the version where x = diff(x); is saved befor?
x = diff(x);
tf = all(sign(x) > 0) || isempty(x);
you can reduce your score by 6 points by removing the logic after ||.its taken care by 'all'
why is the requested answer for x = [0 0 0 0 0] false? constant sequences are both, monotonically increasing and decreasing.
You are right, your solution is good. In the problem describson should be "strictly monotonically increasing".
This is simultaneously abusive and beautiful.
don't know how I missed "isequal" the first time around... it's right there in the test suite. DUH.
why this solution is not right? In the fist case, it returns 16, isn't it equal true?
Why does regexp work like this? Is it a bug? If so, could the Cody team please fix this so that players can't use it to score easy points?
This is just gaming the test set for a limited program with an artificially low score...
so I did it in 1 single line but my size is too big :((
Here's my one-liner (similar to yours):
tf = ~sum(x(2:end) - x(1:end-1) <= 0)
you did good job
assertion 2 of the test suite is monotonically increasing (x = )? Don't you have to have at least two numbers?
Didn't think about using all , well played.
Good function of unique!
Really an awesome problem yaar!!
assert(monotonic increasing == nondecreasing,'check the definition')
i dont know why this is not working .
OK, I had to test the leader's work myself, and I get it now. If any values repeat, unique()'s answer is shorter and therefore not equal. Since unique() sorts the answer in ascending order, only a strictly increasing function has both terms equal.
can I say: WOW
Clever although slow
Why doesn't this fail on test 2? Why should diff(0) > 0 be true?
The weirdness is due to this: all() is true.
Find the two most distant points
Distance walked 3D
Inner product of two vectors
Omit columns averages from a matrix
Get the elements of diagonal and antidiagonal for any m-by-n matrix
Remove all the words that end with "ain"
Read a column of numbers and interpolate missing data
The Goldbach Conjecture, Part 2
The Goldbach Conjecture
Most nonzero elements in row
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office