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
disp(string2)
else
disp(string1)
end
[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.
[0] isn't going anywhere by definition. It makes no sense that it's 'increasing'.
I agree that [0] 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. [0] 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.
good
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));
raq
nice
Good question
for i= 1:(length(x)-1)
if (x(i)< x(i+1))
disp('true');
else
disp('false');
end
end
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,
x=[0]
for i= 1:(length(x)-1)
if (x(i)< x(i+1))
tf=true
else
tf=false
end
end
but your code wont pass the test where x=[0]
The [former] second test case of x = [0] 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.
nice
L=length(x);
if L==1
tf=true; % adding a condition for single element
return %we must close the case for faster operation
end
for ii = 1:(L-1)
if x(ii+1) > x(ii)
tf= true ;
else
tf=false ;
break
end
end
end
kinda cheated but test values were stupid
niceeeeeeeeee
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.
-0--
How is/isn't x = [0]; 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
nice question
you are using MATLAB in a C++ way lol
nice solve!
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.
try all((diff(x))>0)
great answer
(^-^)v
function tf = mono_increase(x)
tf = false;
if x(1,1)>=y(1, length(x))
fprintf('false \n');
elseif x(1,1)==0
fprintf('true\n');
else
fprintf('false\n');
end
end
%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
Nice problem
I agree
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.
cheater.
sahi hai...
this is the solution right???
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 ?
thanks
Can anybody explain me, why this solution is smaler than the version where x = diff(x); is saved befor?
I mean:
x = diff(x);
tf = all(sign(x) > 0) || isempty(x);
all(diff(x)>0)
you can reduce your score by 6 points by removing the logic after ||.its taken care by 'all'
This is simultaneously abusive and beautiful.
good question
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)
assertion 2 of the test suite is monotonically increasing (x = [0])? Don't you have to have at least two numbers?
Nice shot!!!
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 think test 2 is wrong. Is x=0 monotonically increasing? I think not.
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.
3023 Solvers
Project Euler: Problem 7, Nth prime
474 Solvers
Output any real number that is neither positive nor negative
293 Solvers
223 Solvers
What is Sum Of all elements of Matrix
249 Solvers