Cody Problem 60958 introduced seesaw numbers. A number x is a seesaw number if the next m smaller numbers can be placed on a seesaw to the left of x at the fulcrum and the n larger numbers can be placed to the right to make the net torque about the fulcrum zero. Recall that the torque is equal to the product of the number and its distance from the fulcrum. Let’s take torque leading to counterclockwise rotation as positive and torque leading to clockwise rotation as negative.
This problem deals with seesaw primes, which are like seesaw numbers except that they use primes instead of integers. The number 11 is not a seesaw prime because no values of m and n can be found to make the net torque zero. The minimum value of torque of 2 units occurs with one prime (7) to the left and one prime (13) to the right—i.e.,
.
The number 167 is a seesaw prime because with six primes on the left (137, 139, 149, 151, 157, 163) and five on the right (173, 179, 181, 191, 193) the torque on the left is 15,322 units, the torque on the right is -15,322 units, and the net torque is zero.
Seesaw primes seem to be rare: 167 and 17,750,989 are the only ones smaller than 20,000,000. Although the envelope of the minimum torques increases, the dense cluster of points around zero on a plot with linear axes suggests suggests that other seesaw primes should be possible. A plot of the absolute value of the minimum torque
on semilog axes is less encouraging: for primes between 1 and 20 million, only thirteen have an absolute value of minimum torque less than 72 units.
Write a function to determine whether the input number is a seesaw prime. Also return the minimum torque, and m and n, the number of primes on the left and right when the minimum torque occurs. At least one of m and n must be greater than zero. If the input is not prime, set m, n, and the minimum torque to NaN.
Solution Stats
Problem Comments
7 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers4
Suggested Problems
-
4 Solvers
More from this Author321
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Another fantastic ChrisR special!
Thanks Matthew. And nice job on the code. It's much faster than mine!
Thank you, Tim--fixed.
I also updated the description to include the second seesaw prime.
Oops--I deleted my earlier comment (intending to revise it) before I saw that you responded--never mind.
ChrisR please fix test case 13 : Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values. Error in Test13 (line 4) assert(~tf && isnan(Tmin) && isnan(m) && isnan(n)) , took me the better part of a day to solve this :)
@Nikolaos, it appears that the problem is only with your solutions/attempts.
I have re-tested & re-scored the reference solution and all the submitted correct solutions just now, and they passed the test suite without any error.
True, i thought it was the assertions but it turns out i forgot to set nan for non-prime inputs