-3
\$\begingroup\$

For the purpose of this challenge, a multi-base prime is a prime which, when written in base 10, is prime in one or more bases smaller than 10 and larger than 1 as well. All single-digit primes are trivially multi-base primes. 11 is also a multi-base prime, as 11 in binary is 3, which is prime (it is also prime in base 4 and base 6). The first few terms are: 2,3,5,7,11,13, 17, 23,31,37,41,43,47,53,61...

Your Task:

Write a program or function that, when given an integer as input, returns/outputs a truthy value if the input is a multi-base prime, and a falsy value if it is not.

Input:

An integer between 1 and 10^12.

Output:

A truthy/falsy valule, depending on whether the input is a multi-base prime.

Test Cases:

3    -> truthy
4    -> falsy
13   -> truthy
2003 -> truthy (Also prime in base 4)
1037 -> falsy (2017 in base 5 but not a prime in base 10)

Scoring:

This is , lowest score in bytes wins!

\$\endgroup\$

closed as unclear what you're asking by Taylor Scott, Mr. Xcoder, NoOneIsHere, Toto, JungHwan Min Oct 10 '17 at 21:37

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Could you add a test case that's prime in base-2 and base-10 only? I haven't been able to find any such numbers yet but if any do exist, I'll need to update my solution. \$\endgroup\$ – Shaggy Oct 10 '17 at 11:15
  • 3
    \$\begingroup\$ @Shaggy 173,1259,1277,2069,2099,2237,2797,2801,3331,3539,3541,3851,3929,3989,4261,4349,4373,5077,5087,5279,5399,6047,6269,6389... \$\endgroup\$ – user72269 Oct 10 '17 at 11:37
  • 1
    \$\begingroup\$ Thanks, @StraklSeth. I'd since found a couple but my solution needed to be updated anyway. \$\endgroup\$ – Shaggy Oct 10 '17 at 11:59
  • 3
    \$\begingroup\$ The binary evaluation of 19 would be eleven (2^1×1+2^0×9=11), so it seems we are to explicitly ignore evaluating those possibilities that include "excessive digits" - is this correct? \$\endgroup\$ – Jonathan Allan Oct 10 '17 at 21:24
  • 1
    \$\begingroup\$ I nominated this question for reopening but I now realize it is unclear. I would like to see the "excessive digit" problem solved. \$\endgroup\$ – Wheat Wizard Oct 10 '17 at 23:06
1
\$\begingroup\$

Python 2, 159 137 bytes

f=lambda n:p(n)*any(p(b(n,i))for i in range(2,10))
p=lambda n:all(n%x for x in range(2,int(n**0.5)+1))
b=lambda n,i:n and n%i+10*b(n/i,i)

Try it online!

Saved 22 bytes thanks to ovs.

\$\endgroup\$
  • \$\begingroup\$ 137 bytes \$\endgroup\$ – ovs Oct 10 '17 at 16:58
0
\$\begingroup\$

Mathematica, 60 bytes

Or@@(p=PrimeQ)[FromDigits/@IntegerDigits[#,2~Range~9]]&&p@#&

Try it online!

\$\endgroup\$
  • \$\begingroup\$ As it stands 19 should be falsey even though 1,9 in "binary" is 1*2+9=11 which is prime. Edit - I've posted a comment under the OP to ask about this. \$\endgroup\$ – Jonathan Allan Oct 10 '17 at 21:22
  • \$\begingroup\$ @JonathanAllan I don't really get you...19 in binary is 10011... \$\endgroup\$ – J42161217 Oct 10 '17 at 21:52
  • 1
    \$\begingroup\$ The question poses it the other way around: "11 is also a multi-base prime, as 11 in binary is 3, which is prime" \$\endgroup\$ – Jonathan Allan Oct 10 '17 at 22:11
0
\$\begingroup\$

Japt, 15 14 bytes

j ©Ao2@sX nÃdj

Try it


Explanation

Implicit input of integer U.

j

Test if input is prime (Boo-urns to input validation!).

©

Logical AND (&&).

Ao2@    Ã

Generate an array of integers from 2 to 9 and pass each through a function where X is the current element.

sX n

Convert U to a base-X string (s) and back to an integer (n).

dj

Check if any of the numbers in the array are prime.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.