text:
An infinite FTW
The infinite Fibonacci word is a specific, infinite sequence of binary digits, which are calculated by repeated concatenation of finite binary words.
Let us define that a Fibonacci-type word sequence (or FTW sequence) is any sequence  ⟨Wn⟩ that is formed as follows.

Commence with two arbitrary arrays of binary digits. Let us call these arrays W-1 and W0.
For each n > 0, let Wn ≔ Wn-1 ∥ Wn-2, where ∥ denotes concatenation.

A consequence of the recursive definition is that Wn is always a prefix of Wn+1 and, therefore, of all Wk such that k > n. In a sense, this means the sequence ⟨Wn⟩ converges to an infinite word.
Formally, let W∞ be the only infinite array such that Wn is a prefix of W∞ for all n ≥ 0.
We'll call any infinite word formed by the above process an infinite FTW.
Task
Write a program or function that accepts two binary words W-1 and W0 as input and prints W∞, abiding by the following, additional, rules:

You may accept the words in any order; as two arrays, an array of arrays, two strings, an array of strings, or a single string with a delimiter of your choice.
You may print the digits of the infinite word either without a delimiter or with a consistent delimiter between each pair of adjacent digits.
For all purposes, assume that your code will never run out of memory, and that its data types do not overflow.
In particular, this means that any output to STDOUT or STDERR that is the result of a crash will be ignored.
If I run your code on my machine (Intel i7-3770, 16 GiB RAM, Fedora 21) for one minute and pipe its output to wc -c, it must print at least one million digits of W∞ for (W-1, W0) = (1, 0).
Standard code-golf rules apply.

Example
Let W-1 = 1 and W0 = 0.
Then W1 = 01, W2 = 010, W3 = 01001, W4 = 01001010 … and W∞ = 010010100100101001010….
This is the infinite Fibonacci word.
Test cases
All test cases contain the first 1,000 digits of the infinite FTW.
Input:  1 0
Output: 0100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001

Input:  0 01
Output: 0100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001

Input:  11 000
Output: 0001100000011000110000001100000011000110000001100011000000110000001100011000000110000001100011000000110001100000011000000110001100000011000110000001100000011000110000001100000011000110000001100011000000110000001100011000000110000001100011000000110001100000011000000110001100000011000110000001100000011000110000001100000011000110000001100011000000110000001100011000000110001100000011000000110001100000011000000110001100000011000110000001100000011000110000001100000011000110000001100011000000110000001100011000000110001100000011000000110001100000011000000110001100000011000110000001100000011000110000001100000011000110000001100011000000110000001100011000000110001100000011000000110001100000011000000110001100000011000110000001100000011000110000001100011000000110000001100011000000110000001100011000000110001100000011000000110001100000011000000110001100000011000110000001100000011000110000001100011000000110000001100011000000110000001100011000000110001100000011000000110001100000011000110000001100000011

Input:  10 010
Output: 0101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010

Input:  101 110
Output: 1101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101

Fibonacci-type words FTW!

Pyth, 8 bytes
u,peGsGQ

Input in the form "W-1", "W0".
Proof of completion:
$ time pyth -cd 'u,peGsGQ' <<< '"1", "0"' 2>/dev/null | head -c1000000 > /dev/null

real    0m0.177s
user    0m0.140s
sys 0m0.038s

Proof of correctness:
Here is the series as internally generated. It is printed in concatenation by the program.
[0, 10, 010, 10010, 01010010, 1001001010010,...]

Compare to the following, printed in concatenation, which is simply the string added to the previous string on each step:
[0, 1, 0, 01, 010, 01001, 01001010, 0100101001001, ...]

We want to prove these are equivalent.
Clearly, they are the same through the first few steps. Let's compare them after a bit:
010
  010

10010
  01001

01010010
  01001010

1001001010010
  0100101001001

We see that the pairs of strings are alternately of the forms:
01a 10b
a10 b01

Where a and b are arbitrary sequences on 0s and 1s. Let's continue the sequence for a bit, to prove is continues forever by induction:
01a   10b   10b01a   10b01a10b
  a10   b01   a10b01   b01a10b01

2 steps later, it is of the correct form.
10b   01a   01a10b   01a10b01a
  b01   a10   b01a10   a10b01a10

2 steps later, it is of the correct form.
So by induction, the strings always match once concatenated.

+1 for writing working code that you don't understand.

I believe your 8 byte solution works because it prints starting at W0 but instead of printing W1 it prints W-1 || W0, which is the "wrong" concatenation order. I think this works out to be equivalent, but I haven't come up with a proof...

Haskell, 15 bytes
v%w=w++w%(v++w)

The infix function % produces an infinite string, which Haskell prints forever because Haskell is cool like that.
>> "1"%"0"
"010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101

The recursive idea is similar to Zgarb's solution. Writing f for the function %, and + for string concatenation, it implements:
f(v,w) = w + f(w,v+w)

The infinite output string starts with w, and the remainder of it is the result for the Fibonacci-shifted strings w and v+w.
This has no problem generating a million characters in a minute.

Haskell, 31 bytes
w#v=v++drop(length v)(v#(v++w))

This defines an infix function # that takes two strings and returns an infinite string. Usage:
> let w#v=v++drop(length v)(v#(v++w)) in "11"#"000"
"000110000001100011000000110000...

If I query the millionth element of the sequence defined by "1" and "0", even the online interpreter prints the result in less than a second:
> let w#v=v++drop(length v)(v#(v++w)) in ("1"#"0") !! 1000000
'0'

Explanation
w#v=                             -- The result of w#v is
    v++                          -- v concatenated to
                      v#(v++w)   -- the infinite word v#(v++w),
       drop(length v)            -- with the first v characters dropped.

Basically, we know that w#v == v#(v++w) and w#v begins with v, and use these facts to define the result. Since Haskell is lazy, this "magically" just works.

CJam, 12 11 bytes
llL{@_o+_}h

This takes the two words on separate lines, in the opposite order, e.g.
0
1

gives
0100101001001010010100100101001...

Explanation
The idea is to build up the word naively (by remembering the current word and appending the previous one to it) and while we're doing that, we print whatever we just appended (in order not to repeat the prefix that was already printed). To avoid having to handle the starting point separately, we start from an empty word, such that W0 is the first thing we append (and print).
ll    e# Read the two lines separately.
L     e# Push an empty string.
{     e# Infinite loop...
  @   e#   Pull up the previous FTW.
  _o  e#   Print it.
  +_  e#   Append it to the current FTW and duplicate it.
}h

APL, 24 18
{(,/⌽⍵),⊂⍞←↑⍵}⍣≡⍞⍞

Using xnor's formulation allowed to shave off few characters.
                 ⍞  ⍝ Read W₋₁ as a character string.
                ⍞   ⍝ Read W₀.
{            }⍣≡    ⍝ Apply the following function repeatedly until fixpoint:
                    ⍝ It takes a pair of strings (A B),
         ⍞←↑⍵       ⍝ prints A
 (,/⌽⍵),⊂  ↑⍵       ⍝ and returns (BA A).

On an infinite machine in infinite time it would actually print W∞ thrice—first incrementally while running the loop, and then twice as a result of the whole expression when the ⍣≡ fixpoint operator finally returns.
It's not very fast but fast enough. In GNU APL:
$ printf '%s\n' '{(,/⌽⍵),⊂⍞←↑⍵}⍣≡⍞⍞' 1 0 | apl -s | head -c 100
0100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010$
$ time printf '%s\n' '{(,/⌽⍵),⊂⍞←↑⍵}⍣≡⍞⍞' 1 0 | apl -s | head -c 1000000 >/dev/null
    0m3.37s real     0m2.29s user     0m1.98s system

Two infinite numbers. O.O +1

I didn't know about ⍣≡; it sounds very useful.

Pip, 8 bytes
Hey, tied with Pyth!
(fOba.b)

Straightforward recursive definition borrowed from xnor's Haskell answer. With spaces added for clarity:
(f Ob a.b)

Every program in Pip is an implicit function that takes the command-line args as its arguments (assigned to variables a through e) and prints its return value. O is an operator that outputs and then returns its operand, so the first thing that happens here is the second argument is displayed (sans trailing newline).
Now, the Lisp-inspired syntax (f x y) in Pip is a function call, equivalent to f(x,y) in C-like languages. The f variable refers to the current function--in this case, the top-level program. Thus, the program recursively calls itself with b and a.b as the new arguments.
I was pleasantly surprised to find that this approach is plenty fast:
dlosc@dlosc:~$ time pip -e '(fOba.b)' 1 0 2>/dev/null | head -c1000000 > /dev/null

real    0m0.217s
user    0m0.189s
sys     0m0.028s

It takes about 30 seconds on my Ubuntu machine for the program to hit the max recursion depth, at which point it has printed out somewhere over a billion digits.
This iterative solution is slightly faster and hogs less memory, at the cost of one byte:
W1Sba.:Ob

PowerShell, 97 76 Bytes
param($a,$b)write-host -n $b;while(1){write-host -n $a;$e=$b+$a;$a=$b;$b=$e}

Edit - Umm, writing out $e.substring($b.length) after we just concatenated $a and $b together is equivalent to writing out just $a ... derp.
Wow, verbose. PowerShell will, by default, spit out a newline every time you output something. Really the only way to get around that is with write-host -n (short for -NoNewLine), and that absolutely kills the length here.
Essentially, this iterates through the sequence, building $e as the "current" Wn as we go. However, since we're wanting to build the infinite word instead of the sequence, we leverage our previous variables to print out the suffix $a that was populated in our previous loop. Then we setup our variables for the next go-round and repeat the loop. Do note that this expects the input to be explicitly delimited as strings, else the + operator gets used for arithmetic instead of concatenation.
Example:
PS C:\Tools\Scripts\golfing> .\infinite-ftw.ps1 "111" "000"
0001110000001110001110000001110000001110001110000001110001110000001110000001110001110000001110000001110001110000001110001110000001110000001110001110000001110001110000001110000001110001110000001110000001110001110000001110001110000001110000001110001110000001110000 ...

Pure bash, 58
a=$1
b=$2
printf $b
for((;;)){
printf $a
t=$b
b+=$a
a=$t
}

I run out of memory before 1 minute, but have plenty of digits by then - after 10 seconds I have 100 million digits:
$ ./ftw.sh 1 0 | head -c100
0100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010ubuntu@ubuntu:~$
$ { ./ftw.sh 1 0 & sleep 10 ; kill $! ; } | wc -c
102334155
$

C, 76 (gcc)
main(c,v)char**v;{int p(n){n>2?p(n-1),p(n-2):puts(v[n]);}for(p(4);;p(c++));}

This is a fairly straightforward recursive printer, implemented as a nested function (a GNU C extension not supported by clang) to avoid having to pass v around. p(n) prints Wn-2, where W-1 and W0 must be provided in v[1] and v[2]. This initially calls p(4) to print W2. It then loops: it calls p(3) to print W1, making the complete output W2W1, which is W3. It then calls p(4) to print W2, making the complete output W4, etc. Performance is slightly better than my earlier answer: I'm seeing 1875034112 values in a minute.

C, 81 (clang)
This is a completely different approach from the above that I feel is worth keeping up, even though it scores worse.
s[],*p=s;main(c,v)char**v;{for(++v;;)for(puts(v[*++p=*++p!=1]);*p+1==*--p;++*p);}

This has all kinds of undefined behaviour, mainly for fun. It works with clang 3.6.2 on Linux and with clang 3.5.2 on Cygwin for the test cases in the question, with or without special command-line options. It doesn't break when optimisations are enabled.
It doesn't work with other compilers.

You may accept the words in any order; as two arrays, an array of arrays, two strings, an array of strings, or a single string with a delimiter of your choice.

I accept the words as command-line arguments in string format.

You may print the digits of the infinite word either without a delimiter or with a consistent delimiter between each pair of adjacent digits.

I use newline as the consistent delimiter.

For all purposes, assume that your code will never run out of memory, and that its data types do not overflow.
In particular, this means that any output to STDOUT or STDERR that is the result of a crash will be ignored.

I access s out of bounds. This must surely end with a segfault or an access violation at some point. s happens to get placed at the end of the data segment, so it shouldn't clobber other variables and give wrong output before that segfault. Hopefully.

If I run your code on my machine (Intel i7-3770, 16 GiB RAM, Fedora 21) for one minute and pipe its output to wc -c, it must print at least one million digits of W∞ for (W-1, W0) = (1, 0).

Testing using { ./program 1 0 | tr -d '\n' & sleep 60; kill $!; } | wc -c, I get 1816784896 digits in one minute on my machine when the program was compiled with -O3, and 1596678144 when it was compiled with optimisations diabled.

Ungolfed, no UB, with explanation:
#include <stdio.h>

// Instead of starting with -1 and 0, start with 0 and 1. I will use lowercase w for that,
// so that wx = W(x-1).

// Declare a variable length array of numbers indicating what has been printed.
// The length is indicated through a pointer just past the end of the values.
// The first element of the array is a special marker.
// [0 3 1] means that w3 w1 has been printed.
// The array is initialised to [0] meaning nothing has been printed yet.
int stack[99999];
int *ptr = stack + 1;

int main(int argc, char *argv[]) {
  ++argv; // Let argv[0] and argv[1] refer to w0 and w1.
  for(;;) {
    // Determine the word to print next, either 0 or 1.
    // If we just printed 1 that wasn't the end of a different word, we need to print 0 now.
    // Otherwise, we need to print 1.
    int word = ptr[-1] != 1;

    // Print the word, and mark the word as printed.
    puts(argv[word]);
    *ptr++ = word;

    // If we just printed w(x) w(x-1) for any x, we've printed w(x+1).
    while (ptr[-1] + 1 == ptr[-2]) {
      --ptr;
      ++ptr[-1];
    }
  }
}

Your evil s[] trick works well with clang (just installed it). I'm quite surprised this actually works. For all purposes, assume that your code will never run out of memory, and that its data types do not overflow. Unfortunately, that means simply printing W97 is not considered valid. Could you call p recursively? That would eliminate the need for a main.

@Dennis To be fair, at the current rate, the version that cheats by printing W97 would do the right thing in printing W∞ for >3000 years. I'll see if I can improve on that. :)

@Dennis I managed to get it working with the same number of bytes for the program, but making it specific to GCC, and no longer having a clean function. I don't see how to put the logic of repeatedly calling p into p itself without adding more code, but if I do find a way I'll edit again.

Mathematica, 56 bytes
$IterationLimit=∞;#0[$Output~WriteString~#2;#2,#<>#2]&

Dyalog APL, 9
{⍵∇⍺,⍞←⍵}

This one uses ∇ to define a recursive function.  It's a direct translation of this xnor's Python 3 answer.  It takes W0 as right, and W−1 as its left argument, both should be character vectors.

Python 2, 67 bytes
a,b=input()
print'\n'.join(b+a)
while 1:a,b=b,b+a;print'\n'.join(a)

Accepts input as a comma-separated pair of strings: "1","0", for the example in the question.
No online interpreter because infinite loops are bad. Buffered output made me gain a lot of bytes. :( Thanks Dennis for pointing out that 1 digit per line is valid.
Timing on my (significantly-weaker) machine:
$ time python golf.py <<< '"1","0"' 2>/dev/null | head -c2000000 > /dev/null

real    0m1.348s
user    0m0.031s
sys     0m0.108s

The question allows a consistent delimiter between digits. You can save at least 28 bytes by printing each digit on a separate line.

Perl 5, 45 55 49 bytes
44 bytes, plus 1 for -E instead of -e
sub{$i=1;{say$_[++$i]=$_[$i].$_[$i-1];redo}}

Use as e.g.
perl -E'sub{$i=1;{say$_[++$i]=$_[$i].$_[$i-1];redo}}->(1,0)'

This prints successive approximations to W∞ and thus, if you wait long enough, prints, on its last line of output, W∞ to any desired length, as required. The digits of the word are concatenated without a delimiter.
Since I'm on Windows, I tested it for the "at least one million digits of W∞" requirement by running it with output redirected to a file and killing it after about 59 seconds, then running GnuWin32's wc -L, which printed 701408733.

Update:
The OP clarified in a comment on this answer (and probably I should have realized anyway) that the extra output preceding W∞ disqualifies the above. So instead here's a 55-byte solution that prints only W∞:
sub{print$_[0];{print$_[1];unshift@_,$_[0].$_[1];redo}}

Used the same way, but with the arguments in reverse order, and doesn't require -E:
perl -e'sub{print$_[0];{print$_[1];unshift@_,$_[0].$_[1];redo}}->(0,1)'

Doubtless it can be golfed further, but I don't see how to do so right now.

Further update:
Dennis shaved five bytes by using -a (thus reading <> to remove sub) and reassigning the parameter passed to print at the end of the redo block:
With -ane and reading from <> (both inputs on one line, space-separated, in reverse order); 48 + 2 bytes:
$_=$F[0];{print;unshift@F,$F[0].($_=$F[1]);redo}

And, based on that, I shaved one more byte (same as above, but now the inputs are in the correct order); 47+2 bytes:
$_=$F[1];{print;push@F,$F[-1].($_=$F[-2]);redo}

Javascript (53 bytes)
(a,c)=>{for(;;process.stdout.write(a))b=a,a=c,c=b+a;}

Input should be string and not number ('0' and not just 0).

Welcome to Programming Puzzles & Code Golf! Our rules for code golf challenges state that, by default, submissions must be full programs or functions. As such, they have to accept some sort of user input; hardcoding the input is not allowed. Furthermore, your code prints the sequence Wn, not its limit.

Python 3, 32
def f(a,b):print(end=b);f(b,a+b)

The same recursive idea as my Haskell answer, except the prefix is printed because Python can't handle infinite strings.
Used a trick from Sp3000 to print without spaces by putting the string as the end argument in Python 3

REXX, 48
arg a b
do forever
b=a||b
say b
a=b||a
say a
end

ftw.rex
exec ftw.rex 0 1
Currently can't test performance because I used an online compiler to write it. The "forever" can be replaced with any number where as the printed ftw numbers are (number + 2).
I also wrote a small (messy) solution in Prolog. Didn't figure how to test performance with this one but its probably atrocious anyway.
f(A,B,C):-atom_concat(B,A,D),(C=D;f(B,D,C)).

:- C='0';C='1';(f(1,0,C)).

Prolog, 69 bytes
q(A,B):-atom_concat(B,A,S),write(A),q(B,S).
p(A,B):-write(B),q(A,B).

Example input: p('1','0')

Haven't found a way to remove the extra write.
Should be able to improve on this if I figure out how to do that.

Minkolang 0.11, 62 bytes
(od" "=,6&xI0G2@dO$I)I1-0G($d2[I2:g]Xx0c2*1c-0g0g-d[icO]0G0G1)

Try it here. Expects input in the order W0, W-1 with a space in between.
Explanation
(                             Open while loop (for input-reading)
 od                           Read in character from input and duplicate
   " "=,                      0 if equal to " ", 1 otherwise
        6&                    Jump 6 characters if this is non-zero
          xI0G2@              Dump, push length of stack, move to front, and jump next two
                dO            Duplicate and output as character if 1
                  $I)         Close while loop when input is empty
                     I1-0G    Push length of stack - 1 and move it to the front

Meta-explanation for the following is that at this point in time, we have two numbers followed by a string of "0"s and "1"s with no separation. If the lengths of W0 and W-1 are a and b, respectively, then the two numbers at the front of the stack are <a+b> and <a>, in that order. The word formed by concatenating Wi+1 and Wi, i.e. Wi+1 + Wi, is equal to 2 * Wi+1 - Wi. So the following code duplicates the stack (2 * Wi+1), pops off the top <a> elements (- Wi), and then replaces <a+b> and <a> with their successors, <a+2b> and <b>.
(                                       Open while loop (for calculation and output)
 $d                                     Duplicate the whole stack
   2[I2:g]                              Pull <a+b> and <a> from the middle of the stack
          Xx                            Dump the top <a> elements (and <a+b>)
            0c2*1c-                     Get <a+b> and <a>, then calculate
                                        2*<a+b> - <a> = <a+2b> = <a+b> + <b>
                   0g0g-                Get <a+b> and <a>, then subtract
                        d[icO]          Output as character the first <b> elements
                              0G0G      Move both to front
                                  1)    Infinite loop (basically, "while 1:")

(Note: this doesn't produce 1 million digits in a minute...only 0.5 million. Given that this is naturally a relatively slow language, I think I can be cut a little slack. :P)

Perl, 32 bytes
#!perl -pa
$#F=3}for(@F){push@F,$F[-1].$_

Counting the shebang as two, input is taken from stdin, space separated as W0, W-1. Output for 1MB times at ~15ms, most of which can be attributed to interpreter launch.

Sample Usage
$ echo 0 1 | perl inf-ftw.pl
0100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001001010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010010100101001001010010010100101001001010010100100101001001...

$ echo 110 101 | perl inf-ftw.pl
1101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101101011101011101101011101101011101011101101011101011101101011101...

J, 22 bytes including 6 for input chars
similar to Dyalog APL solution
'1'((]stdout@])$:,)'0'

Try it online!

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
How many decimals are there before I'd need to add 1 when rounding?
When you round a number, if the next digit is >= 5 you add 1. For example:
3.1415926535 rounded to 1dp is 3.1
3.1415926535 rounded to 4dp is 3.1416    <-- Note the 5 changed to 6
3.1415926535 rounded to 5dp is 3.14159

3.1415926535 rounded to 9dp is 3.141592654  <-- Note the 3 changed to 4

You challenge is to receive an integer as input and output the number of decimal places before which you would have to round the square root of the number - i.e. the number of decimal places before anumber digit which is >= 5 occurs.
The integer will be between 0 and 100,000 inclusive so for the edge case of 59752 you need to support 17 decimal points (to check the 17th).
If you programming language can't change the number of decimal points, you can display a "?" message to the user.
Example:
Input    Root                     Output

    5 -> 2.23 606797749979     -> 2
   41 -> 6.40312423 743284     -> 8      (Largest gap under 100)
  596 -> 24.4131112314 674     -> 10     (Largest gap under 1000)
59752 -> 244.44222221212112029 -> 16     (Largest gap under 100000)

Do what you want on perfect squares.
This is code-golf so shortest code wins.

For anyone interested, the number 310,617 is the biggest under 1,000,000 and has 18 before you reach a digit >= 5.

How many decimal places do we need to support at maximum? - No languages store to infinite precision.

Uncertain why, but I get 17 digits for SQRT(59752) (in two different languages).  The other results come out properly.

@JonathanLeech-Pepin are you including the last digit for some reason? or does your program not support enough decimal places.

It never has a digit bigger than 5. My program for example will exit with -1

@muddyfish that's fine.

@Tim In both cases (powershell and elisp) it displays ony 15 decimals, however using (pseudocode) N%1*10 to get each decimal in turn will generate the additional decimals however they do not correspond to what I can find using Wolfram.

CJam, 17 bytes
rie40mQsJ~>'4f>1#

Try it online.

Pyth, 13 bytes
f<5e@=*QC\d2Z

Test suite
Start with Q equal to the input.
At each time step, multiply Q by 100, calculated as chr('d'). Take its square root. Take this mod 10. If the result is greater than 5, terminate. Print the number of iterations it took to terminate, 0-indexed.
In detail:
f<5e@=*QC\d2Z
                   Q = eval(input())
f           Z      Filter for the first truthy result over the infinite sequence
                   starting at Z (= 0)
     =*Q           Q *=
        C\d             chr('d') (= 100)
                   ---------------------
    @  Q   2          Q ^ (1/2)
   e                            % 10
 <5               5 <

Mathematica 60 bytes
(Position[Drop@@RealDigits[N[Sqrt@#,99]],x_/;x>4][[1,1]]-1)&

Example
(Position[Drop@@RealDigits[N[Sqrt@#, 99]], x_ /; x > 4][[1, 1]] - 1) &[59752]

16

You can remove the whitespace around the Apply.

Thanks.  The byte count stays the same because I had not counted those spaces.

CJam, 29 26 28 bytes
rimqs_'.+'.#)>{'5<}%0#]W'?er

Try it Online.
Puts a "?" if the number does not appear that can be rounded up (perfect square or too long).

Pyth, 22 bytes
J`%@Q2 1x.e<\4@Jbr2lJ1

Explanation
                       - Autoassign Q to evaluated input
   @Q2                 - Get the square root of Q
J`%    1               - Get the stuff after the decimal point and put it in a string. Store in J
         .e      r2lJ  - Create a range between 2 and the length of the string (forget about the 0. bit) and enumerate over it
              @Jb      - Get the current decimal place
           <\4         - Is it bigger than 4
        x            1 - Find the position of the first True value

I'm absolutely certain this can be golfed. If the input doesn't have a digit higher than 4, it will print -1. Supports 17dp.

Javascript, 59 bytes
f=a=>(a=/\.(.*?)[5-9]/.exec(Math.sqrt(a)),a?a[1].length:'?')

Returns ? for 59752 because JavaScript only uses double precision.

Linux shell, 52 bytes
dc -e'34k?vp'|cut -d. -f2|sed 's/.[5-9\s].*//'|wc -m

I tried for a pure dc solution, but failed. Precision is adjustable (first number).
As the OP kindly specifies that "you can do what you want on perfect squares", in this case this solution outputs the precision + 1, in this case 35.

Ruby, 46 Bytes
This may not be valid, as it only fits 16 digits.
p (gets.to_i**0.5).to_s.split('.')[1]=~/[5-9]/

What is the output on 59752?

nil, as no digit past 4 is in the entire string. It may depend on the ruby version.

It needs to support 59752 - so needs 17 dps

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Counting +1 primes
Define that the natural number p is a +1 prime of the natural number n if p is a prime number and the standard binary representation (i.e., without leading zeroes) of p can be obtained by adding (i.e., prepending, appending or inserting) a single 1 to the standard binary representation of n.
For example, the binary representation of 17 is 100012. The distinct natural numbers that can be formed by adding a 1 to 100012 are 1100012 or 49, 1010012 or 41, 1001012 or 37, and 1000112 or 35.
Among these, 41 and 37 are prime numbers, so 17 has two +1 primes.
Task
Write a program or function that accepts a strictly positive integer n as input and prints or returns the number of distinct +1 primes of n.
Input and output must either be an integer, or its decimal or unary string representation.
Standard code-golf rules apply.
Test cases
Input:  4
Output: 0

Input:  1
Output: 1

Input:  17
Output: 2

Input:  33
Output: 3

Input:  553
Output: 4

Input:  3273
Output: 5

Input:  4145
Output: 6

Input:  4109
Output: 7

Input:  196869
Output: 8

Cool! If I had time tonight I would answer right now

Pyth, 20 bytes
s/LPd{mij\1c.BQ]d2hQ

Test Suite
s/LPd{mij\1c.BQ]d2hQ
                        Q = eval(input())
      m           hQ    For insertion position in [0 ... Q]
            .BQ         Convert Q to binary string
           c   ]d       Chop at insertion position
        j\1             Join on '1'
       i         2      Convert to integer
     {                  Deduplicate
 /LPd                   Map each number to the number of times it occurs in its
                        prime factorization, e.g. whether or not it is prime.
s                       Sum and print.

Huh, "deduplicate" is actually a word.

JavaScript ES6, 141 bytes 143 147 160
Saves 13 bytes, thanks to @Naouak
n=>[...t=n.toString(2)].map((l,i)=>t.slice(0,v=i+1)+1+t.slice(v)).filter((l,i,a)=>a.indexOf(l)==i&&(p=(n,c)=>n%c&&c>n-2||p(n,++c))('0b'+l,2))

Similar method to my TeaScript answer, uses RegExp (you heard me right) to check for primes.
Ungolfed
n=>
   [...t = n.toString(2)]                  // To binary
   .map((l,i)=>                            // Make cycles
               t.slice(0, v = i+1)
               + 1
               + t.slice(v)
   ).filter((l,i,a)=>
                     a.indexOf(l) == i &&  // Remove Duplicates
                     (p=(n,c)=>            // Prime checking
                               n % c &&
                                 c > n - 2 ||
                                 p(n,++c)
                     )('0b'+l,2)
   ).length

I think you can shorten a bit checking prime like this: (p=(n,c)=>n%c!=0?c>=n-1?1:p(n,++c):0)('0b'+l,2) instead of !Array(+('0b'+l)+1).join(1).match(/^1?$|^(11+?)\1+$/)

@Naouak Awesome that saves 13 bytes! :)

TeaScript, 22 bytes
x÷¿®x÷E(i¬,1)¤©d¡F(¥)n

TeaScript is starting to look like APL... The special characters are converted to longer, commonly repeated sequences
Online interpreter be sure to check "Inputs are numbers."
Explanation && Ungolfed
xT(2)s``m(#P(xT(2)E(i+1,1),2))d()F($P)n

xT(2)      // Take input, convert to binary
s``m(#     // Loop over input

  P(         // Convert to decimal...
     xT(2)     // Input to binary
     E(i+1,1)  // Inset 1 into (above) at current index in loop
  ,2)

)d()       // Remove duplicates
F($P)      // Filter items that aren't prime
n          // Grab length.

It's 31 bytes, by the way, using gedit on Xubuntu

It's 31 bytes with UTF-8 encoding, but 22 bytes with ISO-8859-1.

Julia, 55 52 bytes
n->sum(isprime,∪(2n+(k=2.^(0:endof(bin(n))))-n%k))

k=2.^(0:endof(bin(n))) generates an array containing the powers of 2 from 1 to the highest power less than n. 2n+k-n%k then uses array operations to determine all of the possible "+1 numbers". ∪ (equivalent to union, which does the same thing as unique in this situation) removes the repeat values. Then sum(isprime,) counts the number of primes on the list.

CJam, 26 bytes
Not a winner, but it beats the existing CJam answers quite solidly and it's the first time I got to use the 0.6.5 command e\.
1ri2b+_,{_)e\_}%_&{2bmp},,

Test it here.
Explanation
1       e# Push a 1 (this is the 1 we'll be inserting everywhere).
ri      e# Read input and convert to integer.
2b      e# Convert to base 2.
+       e# Prepend the 1.
_,      e# Duplicate and get the number of bits N.
{       e# Map this block over i from 0 to N-1...
  _)    e#   Create a copy and increment to i+1.
  e\    e#   Swap the bits at positions i and i+1, moving the 1 one step through the array.
  _     e#   Duplicate so we keep this version on the stack.
}%
_&      e# Remove duplicates via set intersection with itself.
{       e# Filter the remaining digit lists based on this block...
  2b    e#   Convert bits back to an integer.
  mp    e#   Test for primality.
},
,       e# Get the length of the remaining list.

One thing worth noting is that we swap the bits at 0 and 1 before making the first copy, so we lose the original array with the 1 prepended to the front. However, the input is always positive, so the leading digit will always be one. That means after prepending another one, the digit list will always start with [1 1 ...] so the first swap will be a no-op in any case.

Julia, 110 108 104 87 bytes
n->sum(i->isprime(parse(Int,i,2)),(b=bin(n);∪([b[[1:i;1;i+1:end]]for i=1:endof(b)])))

This creates an unnamed function that accepts and integer and returns an integer. To call it, give it a name, e.g. f=n->....
Ungolfed:
function f(n::Integer)
    # Get the binary representation of n as a string
    b = bin(n)

    # Construct an array consisting of binary strings with
    # a one prepended, appended, and each insertion
    x = [b[[1:i; 1; i+1:end]] for i = 1:endof(b)]

    # Count the number of primes
    c = sum(i -> isprime(parse(Int, i, 2)), unique(x))

    return c
end

Saved 17 bytes thanks to Glen O!

bin has to start with a 1, so you don't need to separately handle "1"b. And when i=length(b), you'll have b[i+1:end] equivalent to "", so no need for that entry (just need to handle b=bin(n) at some point). And sum will do the same thing as count for two fewer bytes.

Also, since you're going to use a range over the length of b anyway, might as well get it with a bit of a trick - b=bin(n)[s=1:end] and then for i=s for the comprehension.

You can also save another byte by using the fact that the first bit in bin should be 1, and you'll get this: n->sum(i->isprime(parse(Int,i,2)),(b=bin(n);unique([b[[1:i;1;i+1:end]]for i=1:endof(b)]))) - this brings the count down to 90 bytes.

In fact, take off one more byte, by replacing unique with union - it will do the same thing, if given only one array as input. Or better yet, ∪ instead of union.

@GlenO You're the master. Thank you, 先生!

Minkolang 0.11, 54 52 bytes
n1(2*d0c`,)(0c1c$%$r2*1c*1c++1g2:d1G)rxSI1-[0g2M+]N.

Explanation
n             Get integer from input (let's call it n)
1(       )    Get the smallest power of 2 (say, k) greater than input (starting with 1)
  2*d         Multiply by 2 and duplicate
     0c`,     Copy n and see if it's greater (while loop breaks on 0)

(0c1c$%                       Copy n, copy k, and divmod (pushes n//k, n%k)
       $r                     Swap top two elements
         2*                   Multiply by 2
           1c*                Copy k and multiply
              1c+             Copy k and add
                 +            Add
                  1g2:        Get k and divide by 2
                      d1G)    Duplicate and put one copy back in its former place

rx            Reverse and dump (dumps n and top of stack is now 0)
S             Remove duplicates
I1-[     ]    Check each element for primality
    0g        Get potential prime from bottom of stack
      2M      1 if prime, 0 otherwise
        +     Add (this is why I didn't dump the left-over 0 earlier)
N.            Output as integer and stop.

I'm always excited to say another Minkolang version.

Mathematica, 87 bytes
Union[#~FromDigits~2&/@StringReplaceList[#~IntegerString~2,a_:>a<>"1"]]~Count~_?PrimeQ&

CJam, 58 bytes
L{:TQ\=A+Q\+TWe\-2<s:~2b}q~2b0+:Q,(%{:BLe=!{B+:L}&}%~:mp:+

This took me a day, and this was my 4th iteration.

Japt -x, 14 11 bytes
Æ¤iX1Ãâ ®Íj

Try it or run all test cases
Æ¤iX1Ãâ ®Íj     :Implicit input of integer U
Æ               :Map each X in the range [0,U)
 ¤              :  Convert U to binary string
  iX1           :  Insert "1" at 0-based index X
     Ã          :End map
      â         :Deduplicate
        ®       :Map
         Í      :  Convert to decimal
          j     :  Is prime?
                :Implicit output of array sum

PHP, 145 bytes
I've added a newline for readability:
function($n){for($b=base_convert;++$i<=strlen($s=$b($n,10,2));$r+=!$s[$i]&$k<=$j)
for($j=1;($k=$b(substr_replace($s,1,$i,0),2,10))%++$j;);echo$r;}

CJam, 34 bytes
li2b_,),\f{_2$<@@>1\++}_&2fb{mp},,

Try it online
First version, will update if I come up with something better.

APL, 55
{+/{2=+/0=⍵|⍨⍳⍵}¨∪⍵{2⊥(⍵↑X),1,⍵↓X←⍺⊤⍨N⍴2}¨-1-⍳N←1+⌊2⍟⍵}

2 bytes shorter Dyalog-specific version:
{+/2=+/¨0=|⍨∘⍳⍨¨∪⍵{2⊥⍵(↑,(1∘,↓))⍺⊤⍨N⍴2}¨-1-⍳N←1+⌊2⍟⍵}

Matlab (120)
n=input('');a=dec2bin(n);g=arrayfun(@(x)bin2dec(cat(2,a(1:x),49,a(x+1:end))),1:log2(n));nnz(unique(g(find(isprime(g)))))

More golfing in progress ...

Brachylog, 17 bytes
{ḃ~c₂{,1}ʰc~ḃṗ}ᶜ¹

Try it online!
Input through the input variable and output through the output variable.
{             }ᶜ¹    Count every unique
             ṗ       prime number
           ~ḃ        the binary representation of which is
 ḃ                   the binary representation of the input
  ~c₂                partitioned into two (possibly empty) lists
     {  }ʰ           with the first list
      ,1             having a 1 appended
          c          and the two lists then being concatenated back into one.

Jelly, 13 bytes
BLṬkj1ʋ€$QḄẒS

Try it online!

Husk, 18 17 bytes
#oṗḋużoJ1eḣḋ¹mtṫḋ

Try it online!
Different approach to Razetime's Husk answer, saving 2 3 bytes.
How?
#oṗḋużoJ1eḣḋ¹mtṫḋ
#o                      # how many
  ṗ                     # prime numbers
   ḋ                    # among numbers formed by binary digits of
    u                   # unique elements of
     żo                 # zip together 2 lists of lists,
       J1e              # joining each pair with the digit '1'
          ḣḋ¹           # list 1:
          ḣ             # all prefixes of
           ḋ¹           # binary digits of input
             mtṫḋ       # list 2:
             mt         # remove first element from
               ṫ        # all suffixes of
                ḋ       # binary digits of input

Very nicely done.

Husk, 20 bytes
←#ṗumȯḋJ1`Cḋ¹oSze↔ŀḋ

Try it online!
Barely got away with a single byte.
Husk, 21 bytes
#oṗḋumJ1§z§e↑↓oΘŀo¢;ḋ

Try it online!
There's probably a much shorter way to do this.

Down to 18 bytes now...

Python 2, 103 bytes
lambda n:sum(all(i%j for j in range(2,i))for i in{n%2**i+((n>>i)*2+1<<i)for i in range(len(bin(n))-2)})

Try it online!

Vyxal 3 s, 11 bytes
bƛ?bm1ỊB}uṄ

Try it Online! (link is to literate version)
Explained
'uniquify( to-binary map<
  (input to-binary) 'insert (ctx-m 1)
  from-binary}
)

prime?

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Fun With Permutations
Who doesn't absolutely love permutations, right? I know, they are amazing––so much fun!
Well, why not take this fun and make it funner?
Here's the challenge:
Given an input in the exact form: nPr, where n is the pool taken from and r is the number of selections from that pool (and n and r are integers), output/return the exact number of  permutations. For those of you that are a bit rusty with the terminology: Permutation, def. 2a.
However, this is where the challenge comes into play (makes it not too easy):

You may not use any built in library, framework, or method for your permutation function. You may not use a factorial method, permutation method, or anything of the sort; you must write everything yourself.

If further clarification is needed, please, do not hesitate to tell me in the comments and I will promptly act accordingly.

Here is an I/O example:
Sample function is permute(String) -> int
Input:
permute("3P2")

Output:
6

This is code-golf, so shortest code wins!

Aww. I thought that this challenge would be on permutation groups. Cool stuff. This is cool too, and closely related to permutation groups. Love the challenge.

When you say no built-in or library methods, do you mean for permutations, or for anything? Can I use the built-in split to split the input at the P? What about a function that converts a string to a number?

Are we allowed to use a built-in that takes the product of a list of numbers?

May answers assume that 0 <= r <= n?

@PeterTaylor - great question! Yes, r and n are integers greater or equal than 0

@xnor - you may not use a built in that does something as big like that--that helps get around a crucial part of the challenge (I'm talking about a permutation function or a factorial function). However, you may definitely use a function that converts a string to a number. You may also use split.

@PeterTaylor - and also r is greater than n.

@Dopapp Do you mean that r isn't greater than n?

@Dennis sorry. Correct. As Peter Taylor correctly said, " 0<=r<=n"

It looks like most answers use built-ins to calculate the product of a list of numbers, which based on the clarifications in the comments would not be allowed. Some of those answers were submitted before the clarification was made. Not sure how you want to deal with this, but it will probably make this an unfortunate challenge either way. Either you ask a bunch of posters to update (or delete) their answers, or there will be no motivation to submit answers that follow the latest definition.

@RetoKoradi - I suppose that in an effort to not force most posters to redo their answers, you are just not allowed to use any factorial or permutation methods/functions.

CJam, 15 14 bytes
r~\;~\),>UXt:*

Try it online in the CJam interpreter.
How it works
r              e# Read a token ("nPr") from STDIN.
 ~             e# Evaluate. This pushes the numbers n, Pi and r on the stack.
  \;           e# Discard Pi.
    ~          e# Take the bitwise NOT of r. Pushes -(r+1).
     \)        e# Increment n.
       ,       e# Turn n+1 into [0 ... n].
        >      e# Keep only the last r+1 elements.
         UXt   e# Replace the first element with 1.
               e# This avoid dealing with the egde case nP0 separately.
            :* e# Compute their product.

Perl, 27 bytes
#!perl -pl61
$\*=$`-$%++for/P/..$'}{

Counting the shebang as 4, input is taken from stdin.

Sample Usage
$ echo 3P2 | perl npr.pl
6

$ echo 7P4 | perl npr.pl
840

What sort of option is l61?

@feersum it sets $\ to 1 (char 49, octal 61).

Haskell, 71 66 bytes
p s|(u,_:x)<-span(/='P')s,(n,k)<-(read u,read x)=product[n-k+1..n]

Pretty straightforward stuff: split at the 'P' then take the product between (n-k+1) and n.
Thanks to nimi for their idea to use pattern guards rather than a where clause, it shaved off 5 bytes.

Julia, 63 58 48 bytes
s->((n,r)=map(parse,split(s,"P"));prod(n-r+1:n))

This creates an unnamed function that accepts a string and returns an integer. To call it, give it a name, e.g. f=s->....
Ungolfed:
function f(s::AbstractString)
    # Get the pool and number of selections as integers
    n, r = map(parse, split(s, "P"))

    # Return the product of each number between n-r+1 and n
    return prod(n-r+1:n)
end

This uses the fact that the number of permutations is n(n-1)(n-2)...(n-k+1).
Saved 10 bytes thanks to Glen O!

No need for Int, so you can just use map(parse,...).

@GlenO My mind has been blown. I didn't realize Int was necessary in that situation. Thanks so much!

Minkolang 0.11, 13 25 19 bytes
Thanks to Sp3000 for suggesting this!
1nnd3&1N.[d1-]x$*N.

Try it here.
Explanation
1        Push 1
n        Take integer from input (say, n)
n        Take integer from input (say, k); ignores non-numeric characters in the way
d3&1N.   Output 1 if k is 0
[   ]    Loop k times
 d1-     Duplicate top of stack and subtract 1
x        Dump top of stack
$*       Multiply all of it together
N.       Output as integer

This uses the same algorithm as Alex's: n P k = n(n-1)(n-2)...(n-k+1).

Bash + Linux utils, 33
jot -s\* ${1#*P} $[${1/P/-}+1]|bc

jot produces the sequence of r integers starting at n-r+1, and separates them with *.  This expression is piped to bc for arithmetic evaluation.

MATLAB, 54 bytes
[n,r]=strread(input(''),'%dP%d');disp(prod((n-r+1):n))

Tried to make it smaller, but one of the things MATLAB is really bad at is getting inputs. It takes 32 characters just to get the two numbers from the input string!
Fairly self explanatory code. Get the input in the form %dP%d where %d is an integer. Split that into n and r. Then display the product of every integer in the range n-r+1 to n. Interestingly this works even for xP0 giving the correct answer of 1. This is because in MATLAB the prod() function returns 1 if you try and do the product of an empty array. Whenever r is zero, the range will be an empty array, so bingo we get 1.

This also works perfectly with Octave as well. You can try it online here.

Python 2, 66
def f(s):a,b=map(int,s.split('P'));P=1;exec"P*=a;a-=1;"*b;print P

Pretty straightforward. Processes the number input as a,b. Keeps a running product as P, which is multiplied by the first b terms of a, a-1, a-2, ....

I don't see how input() could not result in an error.

@feersum I tried it and it indeed throws a syntax error.

I was taking input with quotes like "3P2", which I think is usually allowed, but here the challenge says "an input in the exact form", so I change it to a function which takes a string.

Javascript, 59 57 bytes
s=>(f=(n,k)=>k?(n- --k)*f(n,k):1,f.apply(f,s.split('P')))

TI-BASIC, 52 bytes
Ans→Str1
expr(sub(Ans,1,⁻1+inString(Ans,"P→P        ;n
1
If expr(Str1                               ;If n^2*r ≠ 0
prod(randIntNoRep(P,P+1-expr(Str1)/P²
Ans

TI-BASIC has a "product of a list" function, so getting around the restriction on builtins isn't too hard. However, TI-BASIC doesn't support empty lists—so we need to
To extract the two numbers, I extract the first number as a substring. This is expensive; it takes up the whole second line. To keep from needing to do this again for the second number, I set the variable P to that number, and evaluate the whole string using expr(, then divide by P².
Finally, I take a random permutation of the list between the two numbers (taking care to add one to the second number) and take the product.

Java(594 - bytes)
import java.util.*;import java.lang.*;public class Perm {private String a;private static int[] nr=new int[2];private static int sum=1;Scanner in=new Scanner(System.in);public String input(){a=in.nextLine();return a;}public void converter(String a){this.a=a;String b=a.substring(0,1);String c=a.substring(2);nr[0]=Integer.parseInt(b);nr[1]=Integer.parseInt(c);}public int param(){for(int counter=0; counter < nr[1]; counter++){sum=sum*nr[0]--;}return sum;}public static void main(String args[]){Perm a;a=new Perm();String k=a.input();a.converter(k);int ans=a.param();System.out.println(ans);}}

J, 23 bytes
^!._1/@(".;._1)@('P'&,)

An anonymous function. Example:
   f =. ^!._1/@(".;._1)@('P'&,)
   f '10P4'
5040

Explanation:
       (  ;._1)@('P'&,)   Split over 'P', and on each slice,
        ".                read a number.
      @                   Then,
^!._1/                    fold (/) with the built-in "stope function" (^!.k) for k=1.

The stope function I used might border on counting as a built-in... It rests somewhere between the generality of the multiplication operator and the specificity of the factorial operator.

APL, 23
{{×/⍵↑⍳-⍺}/-⍎¨⍵⊂⍨⍵≠'P'}

Takes the string as argument. Explanation:
              ⍵⊂⍨⍵≠'P'  ⍝ Split by 'P'.
           -⍎¨          ⍝ Convert to numbers and negate making a vector (−n −r)
 {       }/             ⍝ Reduce it by a defined function, which
      ⍳-⍺               ⍝ makes a vector of numbers from 1 to n (⍺)
    ⍵↑                  ⍝ takes r last elements (⍵←−r)
  ×/                    ⍝ and multiplies them together.

Which APL is this? I get an error with my copy of Dyalog.

@ThomasKwa Use ⎕ML←3 in Dyalog.

Ouroboros, 47 45 bytes
Some of this is pretty ugly--I'd imagine it could be golfed further.
Sr.r-1(
)s.!+S1+.@@.@\<!@@*Ys.!+*S.!!4*.(sn1(

Each line of code in Ouroboros represents a snake eating its tail.
Snake 1
S switches to the shared stack. r.r reads one number, duplicates it, and reads another. (Nonnumeric characters like P are skipped.) - subtracts the two. If the input was 7P2, we now have 7, 5 on the shared stack. Finally, 1( eats the final character of the snake. Since this is the character that the instruction pointer is on, the snake dies.
Snake 2
)s does nothing the first time through. .!+ duplicates the top of snake 2's stack, checks if it's zero, and if so adds 1. On the first iteration, the stack is empty and treated as if it contained infinite zeros, so this pushes 1; on later iterations, the stack contains a nonzero value and this has no effect.
Next, S switches to the shared stack, where we have the number n and a counter for calculating the product. 1+ increments the counter. .@@.@\<! duplicates both numbers and pushes 1 if n is still greater than or equal to the counter, 0 otherwise. @@*Y then multiplies the counter by this quantity and yanks a copy onto snake 2's stack.
s.!+ switches back to snake 2's stack and uses the same code as earlier to convert the top number to 1 if it was 0 and keep it the same otherwise. Then * multiplies the result by the partial product that was sitting on this stack.
We now go back to the shared stack (S), duplicate the counter-or-zero (.), and negate it twice (!!) to turn a nonzero counter into a 1. 4*.( multiplies this by 4, duplicates, and eats that many characters from the end of the snake.

If we haven't reached the halting condition, we've got a 4 on the stack. The four characters after the ( are eaten, and control loops around to the beginning of the code. Here ) regurgitates four characters, s switches back to snake 2's stack, and execution continues.
If the counter has passed n, we've got a 0 on the stack, and nothing is eaten. sn switches to snake 2's stack and outputs the top value as a number; then 1( eats the last character and dies.

The result is that the product (r+1)*(r+2)*...*n is calculated and output.
Try it out

// Define Stack class
function Stack() {
  this.stack = [];
  this.length = 0;
}
Stack.prototype.push = function(item) {
  this.stack.push(item);
  this.length++;
}
Stack.prototype.pop = function() {
  var result = 0;
  if (this.length > 0) {
    result = this.stack.pop();
    this.length--;
  }
  return result;
}
Stack.prototype.top = function() {
  var result = 0;
  if (this.length > 0) {
    result = this.stack[this.length - 1];
  }
  return result;
}
Stack.prototype.toString = function() {
  return "" + this.stack;
}

// Define Snake class
function Snake(code) {
  this.code = code;
  this.length = this.code.length;
  this.ip = 0;
  this.ownStack = new Stack();
  this.currStack = this.ownStack;
  this.alive = true;
  this.wait = 0;
  this.partialString = this.partialNumber = null;
}
Snake.prototype.step = function() {
  if (!this.alive) {
    return null;
  }
  if (this.wait > 0) {
    this.wait--;
    return null;
  }
  var instruction = this.code.charAt(this.ip);
  var output = null;
  console.log("Executing instruction " + instruction);
  if (this.partialString !== null) {
    // We're in the middle of a double-quoted string
    if (instruction == '"') {
      // Close the string and push its character codes in reverse order
      for (var i = this.partialString.length - 1; i >= 0; i--) {
        this.currStack.push(this.partialString.charCodeAt(i));
      }
      this.partialString = null;
    } else {
      this.partialString += instruction;
    }
  } else if (instruction == '"') {
    this.partialString = "";
  } else if ("0" <= instruction && instruction <= "9") {
    if (this.partialNumber !== null) {
      this.partialNumber = this.partialNumber + instruction;  // NB: concatenation!
    } else {
      this.partialNumber = instruction;
    }
    next = this.code.charAt((this.ip + 1) % this.length);
    if (next < "0" || "9" < next) {
      // Next instruction is non-numeric, so end number and push it
      this.currStack.push(+this.partialNumber);
      this.partialNumber = null;
    }
  } else if ("a" <= instruction && instruction <= "f") {
    // a-f push numbers 10 through 15
    var value = instruction.charCodeAt(0) - 87;
    this.currStack.push(value);
  } else if (instruction == "$") {
    // Toggle the current stack
    if (this.currStack === this.ownStack) {
      this.currStack = this.program.sharedStack;
    } else {
      this.currStack = this.ownStack;
    }
  } else if (instruction == "s") {
    this.currStack = this.ownStack;
  } else if (instruction == "S") {
    this.currStack = this.program.sharedStack;
  } else if (instruction == "l") {
    this.currStack.push(this.ownStack.length);
  } else if (instruction == "L") {
    this.currStack.push(this.program.sharedStack.length);
  } else if (instruction == ".") {
    var item = this.currStack.pop();
    this.currStack.push(item);
    this.currStack.push(item);
  } else if (instruction == "m") {
    var item = this.ownStack.pop();
    this.program.sharedStack.push(item);
  } else if (instruction == "M") {
    var item = this.program.sharedStack.pop();
    this.ownStack.push(item);
  } else if (instruction == "y") {
    var item = this.ownStack.top();
    this.program.sharedStack.push(item);
  } else if (instruction == "Y") {
    var item = this.program.sharedStack.top();
    this.ownStack.push(item);
  } else if (instruction == "\\") {
    var top = this.currStack.pop();
    var next = this.currStack.pop()
    this.currStack.push(top);
    this.currStack.push(next);
  } else if (instruction == "@") {
    var c = this.currStack.pop();
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(c);
    this.currStack.push(a);
    this.currStack.push(b);
  } else if (instruction == ";") {
    this.currStack.pop();
  } else if (instruction == "+") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a + b);
  } else if (instruction == "-") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a - b);
  } else if (instruction == "*") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a * b);
  } else if (instruction == "/") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a / b);
  } else if (instruction == "%") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a % b);
  } else if (instruction == "_") {
    this.currStack.push(-this.currStack.pop());
  } else if (instruction == "I") {
    var value = this.currStack.pop();
    if (value < 0) {
      this.currStack.push(Math.ceil(value));
    } else {
      this.currStack.push(Math.floor(value));
    }
  } else if (instruction == ">") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a > b));
  } else if (instruction == "<") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a < b));
  } else if (instruction == "=") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a == b));
  } else if (instruction == "!") {
    this.currStack.push(+ !this.currStack.pop());
  } else if (instruction == "?") {
    this.currStack.push(Math.random());
  } else if (instruction == "n") {
    output = "" + this.currStack.pop();
  } else if (instruction == "o") {
    output = String.fromCharCode(this.currStack.pop());
  } else if (instruction == "r") {
    var input = this.program.io.getNumber();
    this.currStack.push(input);
  } else if (instruction == "i") {
    var input = this.program.io.getChar();
    this.currStack.push(input);
  } else if (instruction == "(") {
    this.length -= Math.floor(this.currStack.pop());
    this.length = Math.max(this.length, 0);
  } else if (instruction == ")") {
    this.length += Math.floor(this.currStack.pop());
    this.length = Math.min(this.length, this.code.length);
  } else if (instruction == "w") {
    this.wait = this.currStack.pop();
  }
  // Any unrecognized character is a no-op
  if (this.ip >= this.length) {
    // We've swallowed the IP, so this snake dies
    this.alive = false;
    this.program.snakesLiving--;
  } else {
    // Increment IP and loop if appropriate
    this.ip = (this.ip + 1) % this.length;
  }
  return output;
}
Snake.prototype.getHighlightedCode = function() {
  var result = "";
  for (var i = 0; i < this.code.length; i++) {
    if (i == this.length) {
      result += '';
    }
    if (i == this.ip) {
      if (this.wait > 0) {
        result += '';
      } else {
        result += '';
      }
      result += escapeEntities(this.code.charAt(i)) + '';
    } else {
      result += escapeEntities(this.code.charAt(i));
    }
  }
  if (this.length < this.code.length) {
    result += '';
  }
  return result;
}

// Define Program class
function Program(source, speed, io) {
  this.sharedStack = new Stack();
  this.snakes = source.split(/\r?\n/).map(function(snakeCode) {
    var snake = new Snake(snakeCode);
    snake.program = this;
    snake.sharedStack = this.sharedStack;
    return snake;
  }.bind(this));
  this.snakesLiving = this.snakes.length;
  this.io = io;
  this.speed = speed || 10;
  this.halting = false;
}
Program.prototype.run = function() {
  this.step();
  if (this.snakesLiving) {
    this.timeout = window.setTimeout(this.run.bind(this), 1000 / this.speed);
  }
}
Program.prototype.step = function() {
   for (var s = 0; s < this.snakes.length; s++) {
    var output = this.snakes[s].step();
    if (output) {
      this.io.print(output);
    }
  }
  this.io.displaySource(this.snakes.map(function (snake) {
      return snake.getHighlightedCode();
    }).join("
"));
 }
Program.prototype.halt = function() {
  window.clearTimeout(this.timeout);
}

var ioFunctions = {
  print: function (item) {
    var stdout = document.getElementById('stdout');
    stdout.value += "" + item;
  },
  getChar: function () {
    if (inputData) {
      var inputChar = inputData[0];
      inputData = inputData.slice(1);
      result = inputChar.charCodeAt(0);
    } else {
      result = -1;
    }
    var stdinDisplay = document.getElementById('stdin-display');
    stdinDisplay.innerHTML = escapeEntities(inputData);
    return result;
  },
  getNumber: function () {
    while (inputData && (inputData[0] < "0" || "9" < inputData[0])) {
      inputData = inputData.slice(1);
    }
    if (inputData) {
      var inputNumber = inputData.match(/\d+/)[0];
      inputData = inputData.slice(inputNumber.length);
      result = +inputNumber;
    } else {
      result = -1;
    }
    var stdinDisplay = document.getElementById('stdin-display');
    stdinDisplay.innerHTML = escapeEntities(inputData);
    return result;
  },
  displaySource: function (formattedCode) {
    var sourceDisplay = document.getElementById('source-display');
    sourceDisplay.innerHTML = formattedCode;
  }
};
var program = null;
var inputData = null;
function showEditor() {
  var source = document.getElementById('source'),
    sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
    stdin = document.getElementById('stdin'),
    stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');

  source.style.display = "block";
  stdin.style.display = "block";
  sourceDisplayWrapper.style.display = "none";
  stdinDisplayWrapper.style.display = "none";

  source.focus();
}
function hideEditor() {
  var source = document.getElementById('source'),
    sourceDisplay = document.getElementById('source-display'),
    sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
    stdin = document.getElementById('stdin'),
    stdinDisplay = document.getElementById('stdin-display'),
    stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');

  source.style.display = "none";
  stdin.style.display = "none";
  sourceDisplayWrapper.style.display = "block";
  stdinDisplayWrapper.style.display = "block";

  var sourceHeight = getComputedStyle(source).height,
    stdinHeight = getComputedStyle(stdin).height;
  sourceDisplayWrapper.style.minHeight = sourceHeight;
  sourceDisplayWrapper.style.maxHeight = sourceHeight;
  stdinDisplayWrapper.style.minHeight = stdinHeight;
  stdinDisplayWrapper.style.maxHeight = stdinHeight;
  sourceDisplay.textContent = source.value;
  stdinDisplay.textContent = stdin.value;
}
function escapeEntities(input) {
  return input.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
}
function resetProgram() {
  var stdout = document.getElementById('stdout');
  stdout.value = null;
  if (program !== null) {
    program.halt();
  }
  program = null;
  inputData = null;
  showEditor();
}
function initProgram() {
  var source = document.getElementById('source'),
    stepsPerSecond = document.getElementById('steps-per-second'),
    stdin = document.getElementById('stdin');
  program = new Program(source.value, +stepsPerSecond.innerHTML, ioFunctions);
  hideEditor();
  inputData = stdin.value;
}
function runBtnClick() {
  if (program === null || program.snakesLiving == 0) {
    resetProgram();
    initProgram();
  } else {
    program.halt();
    var stepsPerSecond = document.getElementById('steps-per-second');
    program.speed = +stepsPerSecond.innerHTML;
  }
  program.run();
}
function stepBtnClick() {
  if (program === null) {
    initProgram();
  } else {
    program.halt();
  }
  program.step();
}
function sourceDisplayClick() {
  resetProgram();
}
function stdinDisplayClick() {
    resetProgram();
}
.container {
    width: 100%;
}
.so-box {
    font-family:'Helvetica Neue', Arial, sans-serif;
    font-weight: bold;
    color: #fff;
    text-align: center;
    padding: .3em .7em;
    font-size: 1em;
    line-height: 1.1;
    border: 1px solid #c47b07;
    -webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
    background: #f88912;
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
}
.control {
    display: inline-block;
    border-radius: 6px;
    float: left;
    margin-right: 25px;
    cursor: pointer;
}
.option {
    padding: 10px 20px;
    margin-right: 25px;
    float: left;
}
h1 {
    text-align: center;
    font-family: Georgia, 'Times New Roman', serif;
}
a {
    text-decoration: none;
}
input, textarea {
    box-sizing: border-box;
}
textarea {
    display: block;
    white-space: pre;
    overflow: auto;
    height: 50px;
    width: 100%;
    max-width: 100%;
    min-height: 25px;
}
span[contenteditable] {
    padding: 2px 6px;
    background: #cc7801;
    color: #fff;
}
#stdout-container, #stdin-container {
    height: auto;
    padding: 6px 0;
}
#reset {
    float: right;
}
#source-display-wrapper , #stdin-display-wrapper{
    display: none;
    width: 100%;
    height: 100%;
    overflow: auto;
    border: 1px solid black;
    box-sizing: border-box;
}
#source-display , #stdin-display{
    font-family: monospace;
    white-space: pre;
    padding: 2px;
}
.activeToken {
    background: #f93;
}
.nextActiveToken {
    background: #bbb;
}
.swallowedCode{
    color: #999;
}
.clearfix:after {
    content:".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}
.clearfix {
    display: inline-block;
}
* html .clearfix {
    height: 1%;
}
.clearfix {
    display: block;
}

<textarea id="source" placeholder="Enter your program here" wrap="off">Sr.r-s1(
)s.!+S1+.@@.@\<!@@*Ys.!+*S.!!4*.(sn1(</textarea>

<textarea id="stdin" placeholder="Input" wrap="off">3P2</textarea>

<input type="button" id="run" class="control so-box" value="Run" onclick="runBtnClick()" /><input type="button" id="pause" class="control so-box" value="Pause" onclick="program.halt()" /><input type="button" id="step" class="control so-box" value="Step" onclick="stepBtnClick()" /><input type="button" id="reset" class="control so-box" value="Reset" onclick="resetProgram()" />

<textarea id="stdout" placeholder="Output" wrap="off" readonly></textarea>

Steps per Second:
20

Husk, 11 bytes
FöΠ↑↔ḣmrx'P

Try it online!
How?
        x'P    # split input on the character 'P'
      mr       # and map each of the 2 strings to a value;
Fö             # now, fold over these 2 values by calculating
  Π            # the product of
   ↑           # the first r elements (where r = second value) of
     ḣ         # the series 1..n (where n = first value)
    ↔          # reversed


text:
Crazy Librarian's Interesting Prime Permutation Index Number Generator
You saved the day with your prime sequence code, and the math teacher loved it. So much so that a new challenge was posed to the librarian (a/k/a, your boss). Congratulations, you get to code the solution so the librarian can once again impress the math teacher.
Start with the sequence of natural numbers in base-10, \$\mathbb N\$

0, 1, 2, 3, 4, 5, 6 ...

Excluding 0 and 1, every number in this sequence either is prime, \$\mathbb P\$

2, 3, 5, 7, 11, 13 ...

or composite, \$\mathbf C\$

4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20 ...

Reflecting on how the librarian thought to insert an integer digit into the decimal expansion of a number from \$\mathbb P\$, the math teacher instead created a function \$G(x,y)\$ that takes a number \$x\$ from \$\mathbb N\$ with \$1 \le x \le 9\$ and a number \$y\$ from \$\mathbf C\$ and inserts \$x\$ into the decimal expansion of \$y\$ in every position, in order left-to-right, selecting only unique numbers.
For example, \$G(3,14)\$ is \$314, 134, 143\$. However, \$G(1,14)\$ is only \$114, 141\$, as whether you prepend or insert the \$1\$ into \$14\$, the same number \$114\$ is generated.
The math teacher wondered how many times you'd have to do these permutations before you get a number that's in \$\mathbb P\$, if you took \$x\$ in increasing order. The math teacher called this the Composite-Prime Index of a number, and wrote it as \$\text{CPI}(y)\$.
For example, \$4\$ only needs to be done twice: \$14, 41\$, since \$41\$ is prime, so \$\text{CPI}(4)\$ is \$2\$. However, \$8\$ needs to be done 6 times, \$18, 81, 28, 82, 38, 83\$ before reaching \$83\$ as a prime number, so \$\text{CPI}(8)\$ is \$6\$.
Your task is to write code that will output this Composite-Prime Index, given an input number.
Input

A single integer \$y\$, such that \$y\$ is in \$\mathbf C\$, input via function argument, STDIN, or equivalent.
For the purposes of calculation, you can assume \$y\$ will fit in usual integer ranges (e.g., assume \$2^{31}-1\$ as an upper bound).
Behavior for \$y\$ not in C is undefined.

Output
The resultant Composite-Prime Index, calculated as described above, output to STDOUT or equivalent, with two exceptions:

If the very last permutation (i.e., appending \$9\$ to \$y\$) is the one that results in a prime, output -1. An example, expanded below, is \$y=14\$.
If there is no permutation (i.e., \$G(x,y)\$ is a subset of \$\mathbf C\$ for all \$1 \le x \le 9\$), output 0. An example, expanded below, is \$y=20\$.

Examples
 y -> operations             : output
 4 -> 14, 41                 : 2
 6 -> 16, 61                 : 2
 8 -> 18, 81, 28, 82, 38, 83 : 6
 9 -> 19                     : 1
10 -> 110, 101               : 2
12 -> 112, 121, 212, 122, 312, 132, 123, 412, 142, 124, 512, 152, 125, 612, 162, 126, 712, 172, 127 : 19
14 -> 114, 141, 214, 124, 142, 314, 134, 143, 414, 144, 514, 154, 145, 614, 164, 146, 714, 174, 147, 814, 184, 148, 914, 194, 149 : -1
15 -> 115, 151               : 2
16 -> 116, 161, 216, 126, 162, 316, 136, 163 : 8
18 -> 118, 181               : 2
20 -> 120, 210, 201, 220, 202, 320, 230, 203, 420, 240, 204, 520, 250, 205, 620, 260, 206, 720, 270, 207, 820, 280, 208, 920, 290, 209 : 0

Restrictions

This is code-golf, since you'll need to transcribe this to an index card so the librarian can show the math teacher, and your hand cramps easily.
Standard loophole restrictions apply. The librarian doesn't tolerate cheaters.

Leaderboard

var QUESTION_ID=63191,OVERRIDE_USER=42963;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+(?:[.]\d+)?)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

For 9, 19 is prime, so shouldn't the output be 1?

Wow, cool answer chart!

@cascading-style If you mean the Leaderboard, that's primarily Martin's handiwork.

IMO the first exception ("If the very last permutation (i.e., appending 9 to y) is the one that results in a prime, output -1") ruins this challenge

Pyth, 35 bytes
&sKm}dPdsm{msj`dcz]khlzS9|%hxK1lK_1

Test suite

Haskell, 166 161 bytes
p n=mod(product[1..n-1]^2)n>0
q=p.read
n#c=[h++c:t|i<-[0..length n],(h,t)<-[splitAt i n]]
[y]%i|q y= -1|1<2=0
(y:z)%i|q y=i|1<2=z%(i+1)
f n=((n#)=<<['1'..'9'])%1

Usage examples: f "8" -> 6, f "14"-> -1, f "20"-> 0.
How it works: p is the primality test (stolen from @Mauris' answer in a different challenge). q a wrapper for p to convert types from strings to integer. n # c inserts c at every position in n. % takes a list of numbers and an index i. When the first element of the list is prime, return i, else recure with the tail of the list and i+1. Stop when there's a single element left and return -1 if it's prime and 0 otherwise.

Minkolang 0.11, 85 bytes
n1(l*$d`)d9[i3G(0c2c$%$r2c*l*2c3c1+*++2gl:d2G)2gx1c2G3gx]r3XS(2M4&I)N.ikI1-4&1~N.1+N.

Try it here.
Explanation (coming soon)
n            Take integer from input (say, n)
1(           Calculate smallest power of 10 greater than n (say, a)
  l*         Multiply by 10
    $d`      Duplicate stack and push n>a
       )     Close while loop (ends when n<=a)
        d    Duplicates a (let's call it b)

9[                                                 For loop that runs 9 times
  i1+                                              Loop counter + 1 (say, i)
     3G                                            Puts the loop counter in position 3
       (                                           Opens while loop
        0c2c$%                                     Copies n and b and pushes n//b, n%b
              $r                                   Swaps top two elements of stack
                2c*l*                              Copies b and multiplies by 10
                     2c3c*                         Copies b and i and multiplies them
                          ++                       Adds it all together (inserts i)
                            2gl:                   Gets b and divides by 10
                                d2G                Duplicates and puts one copy back
                                   )               Closes while loop (breaks when b=0)
                                    2gx            Gets and dumps b
                                       1c2G        Copies a and puts it in b's place
                                           3gx     Get and dumps i
                                              ]    Close for loop

r       Reverses stack
 3X     Dumps the top three elements (namely, n, a, and b)
   S    Removes duplicates

(                           Opens while loop
 2M                         Pushes 1 if top of stack is prime, 0 otherwise
   4&                       Jump four spaces if prime
     I)N.                   If the loop actually finishes, then all were composite,
                             so output 0 and stop.
         ik                 Pushes loop counter and breaks
           I1-              Pushes length of stack minus 1 (0 if last one was prime)
              4&1~N.        If this is 0, pushes -1, outputs as integer, and stops.
                    1+N.    Adds 1, outputs as integer, and stops.

Javascript, 324 bytes
y=>(p=(n,c)=>n%c!=0?c>=n-1?1:p(n,++c):0,u=a=>a.filter((c,i)=>a.indexOf(c)==i),g=(x,y)=>u(((x,y,z)=>z.map((c,i)=>z.slice(0,i).join("")+x+z.slice(i).join("")).concat(y+x))(x,y,y.split(''))),h=(x,y)=>g(x,y).concat(x==9?[]:h(++x,y)),i=h(1,y).reduce((r,c,i)=>r?r:p(c,2)?i+1:0,0),console.log(p(y,2)||y<2?'':i==h(1,y).length?-1:i))

If y not in C, then STDOUT output is empty.
Explanation
y=>(
    //Prime Test function
    p=(n,c)=>n%c!=0?c>=n-1?1:p(n,++c):0,

    //Unique function
    u=a=>a.filter((c,i)=>a.indexOf(c)==i),

    //Generates numbers from a couple x and y
    g=(x,y)=>u(((x,y,z)=>z.map((c,i)=>z.slice(0,i).join("")+x+z.slice(i).join("")).concat(y+x))(x,y,y.split(''))),

    //Generates all possible numbers from y using recusion
    h=(x,y)=>g(x,y).concat(x==9?[]:h(++x,y)),

    //Check if any prime in the generated numbers
    i=h(1,y).reduce((r,c,i)=>r?r:p(c,2)?i+1:0,0),

    console.log(
        //Is Y in C ?
        p(y,2)||y<2?
            ''
            :
            // Check if the answer is not the last one
            i==h(1,y).length?-1:i)
    )

Might be very late on commenting this, but couldn't you save a few bytes by replacing n%c!=0 with n%c; c>=n-1 with c>n-2; and x==9 with x-9?

Jelly, 25 bytes
D-ṭJœṖ€$jþ9ẎṖ€ḌQẒµL,-yi1$

Try it online!
+6 bytes to allow for:

If the very last permutation (i.e., appending 9 to y) is the one that results in a prime, output -1

How it works
D-ṭJœṖ€$jþ9ẎṖ€ḌQẒµL,-yi1$ - Main link. Takes n on the left
D                         - Digits of n
 -ṭ                       - Append -1; Call this D
       $                  - To D:
   J                      -   Indices; Yield [1, 2, ..., len(D)]
      €                   -   For each index i:
    œṖ                    -     Partition D at index i
          9               - Generate the range [1,2,3,4,5,6,7,8,9]
         þ                - Pair up all pairs from the range and the partitions:
        j                 -   Join each partition with the corresponding integer
           Ẏ              - Tighten into a list of lists
            Ṗ€            - Remove the -1 from each
              Ḍ           - Convert back to integers
               Q          - Deduplicate
                Ẓ         - Replace primes with 1 and composites with 0
                 µ        - Call this list of bits B
                  L       - Length of B
                   ,-     - Pair with -1
                        $ - To B:
                      i1  -   Yield the first index of 1, or 0 if not found
                     y    - If the index is equal to the length, replace with -1

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/