Problem 23. Finding Perfect Squares
Given a vector of numbers, return true if one of the numbers is a square of one of the numbers. Otherwise return false.
Example:
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.
Solution Stats
Problem Comments
-
39 Comments
Show
36 older comments
Christian Schröder
on 20 Oct 2023
@Tran Up to floating point arithmetic, sqrt(a(i))^2 is the same as a(i), so you're really just testing whether the vector a is non-empty.
(Note that the failing cases are the one where the correct answer is "false", while the ones where you succeed are the ones where it is "true").
Oren
on 8 Jan 2024
Nice little problem :)
Umar
on 22 May 2024
It was very interesting
Solution Comments
Show commentsProblem Recent Solvers19244
Suggested Problems
-
Numbers with prime factors 2, 3 and 5.
575 Solvers
-
We love vectorized solutions. Problem 1 : remove the row average.
832 Solvers
-
Multiples of a Number in a Given Range
770 Solvers
-
Create an n-by-n null matrix and fill with ones certain positions
631 Solvers
-
686 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!