Problem 838. Check if number exists in vector
Solution Stats
Problem Comments
-
9 Comments
Add test vector a = -12;
b = [1,3,4,5,6,7,8,-12,2]; and rescore.
Better is add a=-randi(16); b= [1 2 3 a];
These will eliminate answers like #6.
Tests allow incorrect solution to pass:
function y = existsInVector(a,b)
y=0
for i = 1:numel(b);
if i==a
y=1
break
end
end
end
good
that was fun, took me a couple minutes
y = sum(b == a);
Not too bad
yay
fggga
As difference in solution directly proportional to size of solution
Solution Comments
Show commentsProblem Recent Solvers11682
Suggested Problems
-
Select every other element of a vector
32978 Solvers
-
Reverse the Words (not letters) of a String
440 Solvers
-
Sum all integers from 1 to 2^n
15313 Solvers
-
Find the largest value in the 3D matrix
1521 Solvers
-
Rotate input square matrix 90 degrees CCW without rot90
613 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!