26
3
You will need to generate the smallest prime with n
digits, and it will only contain digits specified in the list k
.
Examples:
Input:
4
1 2
For this, you must generate the smallest prime with 4
digits, and that prime must only contain the digits 1
and 2
.
Output:
2111
Input:
10
0 4 7
Output:
4000000007
Input:
6
5 5 5 5 5 5 5 5 5 5 1 5 5 5 5 5 5 5 5 5 5
Output:
115151
You can guarantee that the input will always be in the format you specify, and you can do anything if you get invalid input (such as the input being a single digit n
, without k
.)
If no such solution to an input exists, your program is allowed to do any of the following:
- Print
banana
- Throw an error
- Run forever
- Anything else
Since this is code-golf, try to aim for the shortest code.
The input can be in any format you specify. For example, if you want your input to be like any of the following, that is fine.
4
[1, 2]
[1,2]4
1,2
4
4 12
You can either write a program or a function, and it must either return the correct value or print it.
Whitespace is allowed anywhere.
This challenge inspired by A036229.
2Mandatory question: Can we use any base? (The challenge is much easier in unary.) – flawr – 2017-02-09T22:26:36.080
Can the solution have leading zeros if zero is one of the input digits? – Luis Mendo – 2017-02-09T22:27:32.753
@flawr of course not, i think it may come under standard loopholes (if not, it needs to be added) – Okx – 2017-02-09T22:28:00.687
1@LuisMendo i wouldn't count that as 'proper' number, so no. – Okx – 2017-02-09T22:28:30.510
Can the list be a set literal? And characters instead of integers? (@xnor's Python answer is using those) – mbomb007 – 2017-02-17T17:15:27.630
@mbomb007 Yes, as the input is flexible. – Okx – 2017-02-17T17:34:14.757
Yeah, you said that, but taking input as a set removes duplicates from the list automatically, so I didn't know if it was allowed. – mbomb007 – 2017-02-17T17:36:36.967
@mbomb007 That's allowed – Okx – 2017-02-17T17:37:30.600
Based on the second test case with output
4000000007
I assume we need to support numbers larger than 32-bit? – Kevin Cruijssen – 2017-02-23T14:38:08.907@KevinCruijssen Yes. – Okx – 2017-02-23T15:49:21.567
@Okx Ok, edited my answer. – Kevin Cruijssen – 2017-02-23T15:59:59.897