Given a vector of numbers, return true if one of the numbers is a square of one of the other numbers. Otherwise return false.
Input a = [2 3 4]
Output b is true
Output is true since 2^2 is 4 and both 2 and 4 appear on the list.
Another of the classic "check if MATLAB has a function that does this already" problems...
What about a vector like [2 3 1]? The top solution will still return true because 1^2 is still one but it is not the square of one of the OTHER numbers.
is the Str2func construct really more effective???
Is it possible that this distorts the metric a bit?
It is currently impossible to submit a solution for this problem. The web page will never load.
The problem description states that one of the numbers has to be a square of one of the OTHER numbers. Still, the test suite tests if  gives true. I think  should give false, or that describtion be modified.
Agree with Mattias. the length of input vector should be 2 or larger.
The difference between test 4 and 5 which returns different answers is the number 36.. but 36 is not a square root of any number of the list in test 4!!
Agree with Mattias: the Test Suite is defective, and not consistent with the problem specification.
Having an input of  is OK, but result should be false, as there is no OTHER element to compare the 1 to!
can you share the shortest code?
the word "other" should be ignored in the description...
function b = isItSquared(a)
b = false;
whoops, don't know how I managed to confuse .^ with .* for a bit there ---I was like, "What's WRONG?"
0 and 1 elements in a will show the bug in your code
a vector 'a' with elements 0 or 1 will show the bug in your code
out = any(ismember(a.*a, a))
Wow! This took me a couple of days to solve, but I did it and I’m very proud! :D
Hi. A vector with ones or zeroes as v = [3, 1] will show the bug in your code.
Test case : a = [20:30] contains a square. but its expected error is false. It should be fixed
where do you find a perfect square in [20:30]?
Hi Jann B,
25 is a perfect square, no?
How is the output true if the vector contains only one number? People posting such meaningless solutions: Please have some common sense!
a vector as v = [3,2,7,0,5] will show you your code's bug
a little smaller now
I want to make this code shorter!!
Case2,a = [20:30],fails.
in 2 test suite in a=[20:30] , contains 5^2 =25 so it has to be true not false
But there seems to be a better choice. Why forgetting ismember?
Test 2 in the test suite is wrong!
25 is clearly a perfect square.
the problem is to see if a number is the square of another number in the vector. Although 25 is a perfect square, 5 is not included in the vector
y = n;
for i = 1:1:length(y)
for j = 1:1:length(y)
while y(i) == sqrt(y(j))
while y(i) ~= sqrt(y)
% my code runs successfully in matlab
Though it passes the test suite, I feel like I could make this a better way but I am drawing a blank. Any feedback would be appreciated.
if a = [20:30] the output should be true as 25 is a perfect square, while in the test case output is given to be false.
25 is not a square of any other members of the group. If the group included 5 it would be true.
hur dur durrr durr. sqrt(25)==5, not included in givens
Yeah, I did it
My solution returns false for [20:30]; why not for [6 10 12 14 101]?
Instead of a(1):a(end) you should just write a.
Where did I do wrong？
The desired results are not the character strings 'true' and 'false' but the logical values true and false.
hint ; any and ismember.
submitted tested solution but still showing error......
L 17 (C 1-3): Parse error at END: usage might be invalid MATLAB syntax.
interesting solution... I like it :)
I disagree. Almost every problem has a solution wrapped in this function. It's cheating as it hides the complexity of the code from the scoring algorithm. That's why "eval" is not allowed ...
This is the correctly executing in matlab
I wonder...if you cheat, why even bother to actually solve the problem?
I have not heard of ismember before, thanks.
As primitive as my solutions are, I learn just as much from reading other peoples as doing the problem itself. Great setup mathworks :)
Code works on Matlab, but not on your test suite?
Srtr2func, classic way:)a new thing learned.
a = [20:30] 25 is in that array and is perfect square. Why should it return false?
because 5 isn't in the array. the perfect square and it's root should both be in the array.
test case 3 should be 'false'
it states 'one of the other' numbers, so for a =  it should be false
Assertion 2. is not correct. vector 'a' return with 6th element as 25 & thts a perfect square.. So it must be true!!
vectorization in N
First non-zero element in each column
Rotate and display numbered tile
Simple equation: Annual salary
Find common elements in matrix rows
Return the largest number that is adjacent to a zero
Remove the polynomials that have positive real elements of their roots.
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