12
1
I was asked this question in an interview but I was unable to figure out any solution. I don't know whether the question was right or not. I tried a lot but couldn't reach any solution. Honestly speaking, nothing came to my mind.
Rocco numbers
A positive integer \$n\$ is a Rocco number if it can be represented either as \$n=p(p+14)\$ or \$n=p(p-14)\$, where \$p\$ is a prime number.
The first 10 Rocco numbers are:
$$32, 51, 95, 147, 207, 275, 351, 435, 527, 627$$
Task
Your code must accept a positive integer as input and determine if it is a Rocco number or not.
Brownie points
- Write a function that calculates and prints the count of Rocco numbers less than or equal to 1 million.
- Write a function that calculates and prints the count of Rocco numbers from the bonus question (above one) that are prime.
5Hi and welcome to PPCG. We host challenges (your's looks really interesting) that have objective scoring and winning criteria. Try editing your post to include that. I recommend [tag:code-golf] as the goal, since it is the easiest to get right. Also, you want to avoid those bonuses; just focus on one clear task. – Adám – 2019-01-29T20:19:30.897
3output would be an integer: Don't you mean a Boolean for whether the input was a Rocco number or not? – Adám – 2019-01-29T20:20:10.217
5Bonus 2:
print 0
. All Rocco numbers are composite(n*..)
, so no primes in any range. – TFeld – 2019-01-29T20:29:58.0171Yeah the bonuses are trivial as golf. To be fair to the OP they do both state "that calculates" (I know, unobservable...). – Jonathan Allan – 2019-01-29T20:44:07.530
confirmed 281 (286 if we were to include negative integers). – Jonathan Allan – 2019-01-29T20:49:26.807
@JonathanAllan If it has to be EITHER
+14
OR-14
(xor, as in the description), i count 233 – TFeld – 2019-01-29T20:50:37.917All duplicates exist where primes are 14 apart (eg. 51 is
3*(3+14)
and17*(17-14)
) – TFeld – 2019-01-29T20:54:55.090@TFeld Yeah, I must have made a typo. 286 with negatives, 281 without. 237 and 233 for xor. – Adám – 2019-01-29T20:55:00.850
@JonathanAllan Sure it "calculates", using the formula a×10²+b×10+c for some very specific values of a,b,c ;-) – Adám – 2019-01-29T20:58:55.340
4The "bonus points" can simply be hardcoded values, and aren't beneficial to the challenge at all. I recommend removing them. – Erik the Outgolfer – 2019-01-30T10:56:22.380
5I've edited the question and the tags. Feel free to either rollback or edit further if you do not agree. As @EriktheOutgolfer said, I think the bonuses should be removed. – Arnauld – 2019-01-30T11:09:08.313
You need to add some test cases. – Shaggy – 2019-01-30T14:12:42.507
2I consider the question is clear and has a valid winning criteria. I would remove the Brownie points tho. Anyway, voted to re-open – Luis felipe De jesus Munoz – 2019-01-31T20:20:19.963
I wish it was open - I have a submission. – Jerry Jeremiah – 2019-02-01T04:54:29.237