text:
The Snail in the Well
Background
There's a common riddle that goes something like this:

A snail is at the bottom of a 30 foot well. Every day the snail is able to climb up 3 feet. At night when they sleep, they slide back down 2 feet. How many days does it take for the snail to get out of the well?

The intuitive answer is

 30 days, because the snail climbs at 1 foot per day for 30 days to reach the top,

but actually the answer is

 28 days, because once the snail is 27 feet in the air (after 27 days), they will simply climb the remaining 3 feet to the top on the 28th day.

Challenge
This challenge generalizes this riddle. Given three positive integers as input, representing the total height, the climb height, and the fall height, return the number of days it will take to climb out of the well.
If the snail cannot climb out of the well, you may return 0, return a falsy value, or throw an exception. You may also write code that will halt if and only if a solution exists.
If you wish, you may take the fall height as a negative integer.
Test Cases

(30,  3,  2) -> 28
(84, 17, 15) -> 35
(79, 15,  9) -> 12
(29, 17,  4) -> 2
(13, 18,  8) -> 1
( 5,  5, 10) -> 1
( 7,  7,  7) -> 1
(69,  3,  8) -> None
(81, 14, 14) -> None

Scoring
This is code-golf, so the shortest answer in each language wins.

Related

I'll probably award a bounty if someone answers in Gray Snail. The Esolangs page is just an empty stub, but there is some information and an online compiler available, as well as a sample program for the 99 bottles of beer problem.

I thought this would just be a simple formula, but the casework is surprisingly interesting.

You still have "how many hours....". The answer being 27*24 + 12 (assuming a 12 hour 'day').

@musicman523 To which answer did you intend to award the bounty?  Both Keyu Gan and myself have made answers.  Keyu Gan's was first but mine is quite a deal shorter.

@WheatWizard I will award the bounty to the shortest Gray Snail answer

Still waiting for that SnailBASIC answer...

Gray Snail, 1206 bytes for numeric I/O, 149 bytes for unary I/O
For fun. Composition of first program:

451 bytes, converting number into dots
121 bytes, core function (a separated version is written below)
634 bytes, converting dots into number

Take numeric input and output.
Input is A, B, C respectively. Compared to other (near) O(1) answer, the code has a complexity of O(n). But for large number, it may eat up your memory first.
Hang if no solution is found.
INPUT p
POP Z r .!
f
POP Z o .
q
POP Z p [p]
GOTO [Z]
0
POP Z n .
GOTO w
1
POP Z n ..
GOTO w
2
POP Z n ...
GOTO w
3
POP Z n ....
GOTO w
4
POP Z n .....
GOTO w
5
POP Z n ......
GOTO w
6
POP Z n .......
GOTO w
7
POP Z n ........
GOTO w
8
POP Z n .........
GOTO w
9
POP Z n ..........
GOTO w
w
POP Z o .[o][o][o][o][o][o][o][o][o][o][n]
GOTO [r] [p]
GOTO q
!
POP Z A .[o]
INPUT p
POP Z r .@
GOTO f
@
POP Z B .[o]
INPUT p
POP Z r .#
GOTO f
#
POP Z C .[o]
POP H N .[B]
U
POP Z A [A]
POP Z B [B]
GOTO D [A]
GOTO $ [B]
GOTO U
$
POP Z A .[A][C]
POP Z H ..[H]
POP Z B .[N]
GOTO U
D
POP Z r .
POP Z M .
POP Z N ...........
POP Z z .[N]
POP Z V .[H]
+
GOTO l[V] [H]
POP Z H [H]
POP Z z [z]
GOTO ( [z]
GOTO +
(
GOTO ) [H]
POP Z z .[N]
POP Z M ..[M]
POP Z V .[H]
GOTO +
)
POP Z r .0[r]
POP Z M ..[M]
POP Z H .[M]
POP Z M .
POP Z V .[H]
POP Z z .[N]
GOTO +
l
POP Z r .0[r]
GOTO -
l.
POP Z r .1[r]
GOTO -
l..
POP Z r .2[r]
GOTO -
l...
POP Z r .3[r]
GOTO -
l....
POP Z r .4[r]
GOTO -
l.....
POP Z r .5[r]
GOTO -
l......
POP Z r .6[r]
GOTO -
l.......
POP Z r .7[r]
GOTO -
l........
POP Z r .8[r]
GOTO -
l.........
POP Z r .9[r]
GOTO -
-
GOTO / [M]
POP Z H .[M]
POP Z M .
POP Z V .[H]
POP Z z .[N]
GOTO +
/
OUTPUT [r]

f is a (maybe) recursive function to convert integers into dots. Argument is saved in [p] and output in [o].
U is a function testing S1>=S2, storing parameter in B, A while saving A-B into A.
Code starting from D is a stub converting dots into numbers.
The underlying principle is the same with my C answer (ripping off falsy output for impossible solutions).
Standalone version, 149 156 157 167 170 230 bytes, only support unary I/O
Input needs to be dots, e.g. .......... for 10.
INPUT A
INPUT B
INPUT C
POP N H .
GOTO U
$
POP N A .[A][C]
POP Z H ..[H]
U
POP Z A [A]
POP Z N ..[N]
GOTO D [A]
GOTO $ .[B] [N]
GOTO U
D
OUTPUT .[H]

U calculates A=A-B, and jumps to D when A<=0. Otherwise $ assigns A+C to A and call U.
Hang if no solution is found.
Tricks: abuse the "compiler"'s ability to interpret empty string. You can rip off conditions in GOTO statement to make unconditioned jumps and the same trick works for POP.
Remark: I may golf it more by 3 bytes but by doing so, mine and WheatWizard's answer would have the exact same logic. The result is probably the shortest GraySnail solution and I'm trying to prove it.

You made it first

Hey I just thought I'd let you know that I've made mine shorter than yours again.  Its only a byte shorter and it draws some inspiration from your latest golf.

@WheatWizard I have a 155-byte solution based on your old answer. But for sportsmanship, I will not view it as my answer.

@KeyuGan No, go ahead.  I don't care about the rep its all about the game.  I'm happy to be beaten.  If my code can be golfed is my fault for not seeing it.  :)

@WheatWizard Me neither. I'm sure it is the best time I've ever had on PPCG.

I used your golf of my golf, to take of another 10 bytes.

Note: the byte count is being questioned by Martin Ender in the comments. It seems there is no clear consensus about what to do with named, recursive lambda expressions in C# answers. So I have asked a question in Meta about it.

C# (.NET Core), 32 31 bytes
f=(a,b,c)=>a>b?1+f(a-b+c,b,c):1

Try it online!
A recursive approach. If the snail cannot escape, it ends with the following message: Process is terminating due to StackOverflowException.

1 byte saved thanks to LiefdeWen!

You can save a byte byte changing a<=b to a>b and swapping the following parts

Exact same code works in ES6 f=(a,b,c)=>a<=b?1:1+f(a-b+c,b,c)

You'll have to count the code that assigns the function to a name if you're relying on that name being f for the recursive call.

@MartinEnder done!

I don't golf in C# so I'm not entirely sure what the consensus is, but I would've expected this to require a full statement with a declaration of f and a semicolon if it's named. The first thing I found is this but there's no clear consensus here.

(The usual rules are "either your submission is an expression that evaluates to a function object, or your submission is a statement that can stand on its own and results in a named function being defined".)

@MartinEnder so, should I add the previous System.Func<int,int,int,int>f=null; and the trailing ; to the byte count? I don't think it adds anything to the code, but if I am to stick to the rules, so be it...

@CarlosAlejo Well I guess you'd just put the expression where the null is to have it all in one statement.

@MartinEnder if you mean System.Func<int,int,int,int>f=(a,b,c)=>a>b?1+f(a-b+c,b,c):1;, I can't do that because f is unassigned at the moment I try to call it recursively, hence the previous sentence to declare it as null.

@CarlosAlejo Oh I see. In that case, I suppose you need to use the null version. But wouldn't a regular named method be shorter at that point?

@MartinEnder yes, but then a non-recursive, anonymous lambda expression using a formula similar to other answers would be even shorter, losing the elegant, recursive approach.

@MartinEnder I usually just do as Carlos has done here, as the declaration is only f=... I'm unsure as to whether or not we should add the semi-colon on the end though.

Thank Mathematica for having #0

For the record, Scala has the same problem and I've never included the type declarations in my Scala answers, though those were mostly non-recursive. This C# consensus should probably apply to Scala as well.

I thought it required a runnable program with all the usings, class def etc

I don't think anybody would argue int f(int a,int b,int c)=>a>b?1+f(a-b+c,b,c):1; is valid at 47 bytes. Not as cool as a recursive anonymous function thought :)

GRAY SNAIL, 219 206 169 167 159 156 146 bytes (unary IO)
INPUT a
INPUT u
INPUT d
POP U c
GOTO 1
3
POP f a [a][d]
POP U c ..[c]
1
GOTO 2 [a]
GOTO 3 [U] [u]
POP f U ..[U]
POP f a [a]
GOTO 1
2
OUTPUT [c].

I think I can golf this down a bit.

Congratulations!

JavaScript (ES6), 31 28 27 bytes
Saved a few bytes thanks to @Arnauld
I hadn't realized we could fail with an exception. Pretty sure this is optimal:
u=>d=>g=h=>h>u?1+g(h-u+d):1

Assign to a variable with e.g. f=, then call like f(climb)(fall)(height). Throws InternalError: too much recursion if the climb is impossible.

JavaScript (ES6), 38 bytes
f=(h,u,d=0)=>h>u?u>0?1+f(h-u,u-d):+f:1

A recursive function that returns the number of days, or NaN for never.
Test cases

let f=(h,u,d=0)=>h>u?u>0?1+f(h-u,u-d):+f:1;

[
  [30,  3,  2],
  [84, 17, 15],
  [79, 15,  9],
  [29, 17,  4],
  [13, 18,  8],
  [ 5,  5, 10],
  [ 7,  7,  7],
  [69,  3,  8],
  [81, 14, 14]
].map(x => console.log(x + '', '->', f.apply(null, x)))

That's obvious: If snail does too much recursion, then climb is impossible. :)

Maybe 27 with a reversed currying syntax? d=>u=>g=h=>h>u?1+g(h-u+d):1

@Arnauld Thanks, that works surprisingly well...

I'm a it confused re the byte count- in one the variable the function is assigned t is included, the other not?

@Orangesandlemons in the top version, you have g= in the middle because this variable stores the intermediate function needed for the recursive call. The longer answer does a recursive call on f, which mandates that the name be included in the byte count.

Excel, 51 46 bytes
-1 byte thanks to @Scarabee.
-4 because INT(x) = FLOOR(x,1)
=IF(B1<A1,IF(C1<B1,-INT((B1-A1)/(B1-C1)-1)),1)

Input taken from Cells A1, B1 and C1 respectively.
Returns FALSE for invalid scenarios.

ceiling(x) is always equal to -floor(-x), so I think you could save 1 byte by replacing CEILING((A1-B1)/(B1-C1)+1,1) with -FLOOR((B1-A1)/(B1-C1)+1,1).

C (gcc), 39 43 44 46 47 58 60 bytes
Only on 32-bit GCC and all optimizaitons turned off.
f(a,b,c){a=a>b?b>c?1+f(a-b+c,b,c):0:1;}

Return 0 when solution is impossible. A modified version of original recursive solution.
Inspired by @Jonah J solution and @CarlosAlejo C# solution.
I'll update the expanded version later (after I finish my Grey Snail answer).

Nice one!
could u please include the analytical (non-compressed) solution?

@koita_pisw_sou Sure.

It doesn't "return" anything at all. You assign to a local parameter, whose value evaporates once the function returns. The snail is stuck in eternal limbo.

@CodyGray it uses a stable but undefined behavior in GCC. I could show you a link later.

@CodyGray https://codegolf.stackexchange.com/questions/2203/tips-for-golfing-in-c Assign instead of return

Sigh, more bad advice given out to code golfers by people who don't know the language. If it's undefined behavior, it isn't valid code. This doesn't work reliably. For example, it doesn't work here. (And yes, CodePad uses GCC as the C compiler.) It doesn't work on my machine, either.

It works on TIO. https://tio.run/##HckxCoAwDADAva8IgpDQFKpuFtu3tJGKgyLiJr49iuuduEVEtWLmwkJ3nnIsqURJnf3QFSt/jH7swqPrfsGW1x3J3AYAjvOTik07NwwVB88wMPREwTz6Ag

@CodyGray btw, it requires all optimizations turned off

Codepad uses -O to compile code, which may alter undefined behavior. As discussed in https://codegolf.meta.stackexchange.com/questions/5486/is-an-answer-allowed-to-use-undefined-but-consistent-behaviour , it is acceptable to utilize consistent undefined behavior. I should mention it more clearly in the title.

Java (OpenJDK 8), 35 bytes
(a,b,c)->b<a?c<b?(a+~c)/(b-c)+1:0:1

Try it online!
Math wins!
Credits

-1 byte thanks to Kevin Cruijssen

It's been a while, but a-c-1 → a+~c.

Thanks @KevinCruijssen It's been a while, but golf is golf, no matter when it happens :-)

My thoughts exactly. On a few occasions I golfed about halve my original bytes when I looked at some of my first answers. ;)

Python 2, 37 bytes
f=lambda x,y,z:x-y<1or 1+f(x-y+z,y,z)

Try it online!
Finally got my recursive version below my standard calculation (I was passing a count to my function instead of adding one before calling it).
Python 2, 43 46 bytes
#43 bytes
lambda x,y,z:y/x>0 or[1-(x-y)/(z-y),0][z/y]
#46 bytes
lambda x,y,z:y/x and 1or[1-(x-y)/(z-y),0][z/y]

Try it online!
Shaved 3 bytes by trading "__ and 1" for "__>0".
Using boolean trickery, essentially executes:

if floor(y/x) > 0:
    return True # == 1
elif floor(z/y) == 1:
    return 0
elif floor(z/y) == 0:
    return 1-floor((x-y)/(z-y))
    # Python 2 implicitly treats integer division as floor division
    # equivalent: 1 + math.ceil((y-x)/(z-y))
    # because: -floor(-x) == ceil(x)

You have to put f= in front of your code (the first solution), and your byte count becomes 37, because it is recursive, so you can't leave it anonymous. f= can be dropped for a lambda only when it is not recusive.

Noted and addressed. Thanks for letting me know.

36 bytes, elminitating a space by using -~x instead of 1+x

Perl 5, 37 bytes
35 bytes code +2 for -pa.
$i-=$F[2]while++$\,($i+=$F[1])<$_}{

Try it online!

Haskell, 30 29 27 bytes
(b!c)a=1+sum[b!c$a+c-b|a>b]

Try it online!
Shorter than the existing Haskell answer.  Perhaps someone else can beat me.
This uses a recursive approach to solving the problem.  Each recursion is essentially a day of movement for the snail.  If the distance left to the end is less than the distance still required we end our recursion.

Save 1 byte with infix notation: (b#c)a=1+sum[(b#c)$a+c-b|a>b].

@Laikoni Didn't know that could be done. Thanks for the tip.

You can drop the parens around b!c in the list comprehension.

R, 43 bytes
Borrowing from other answers:
g=function(a,b,c)`if`(b<a,1+g(a-b+c,b,c),1)

Gives error if no solution.

Nice answer. Welcome to PPCG!

J, 25 bytes
First a nice solution, which is a cheat, since it assumes that "anything other than a positive integer result" equals "None":
>.>:%/2-/\

explanation

2-/\ use windows of length 2 across our 3 item input, placing a minus sign between each one, which for the input 30 3 2, eg, returns 27 1
%/ put a division symbol between each element of the list, in our case the list has only two items, so it means "divide 27 by 1"
>: increment by 1
>. take the ceiling

official solution
Here is the official solution that converts negatives and infinity to 0, which part i was not able to find a satisfyingly terse solution for:
0:`[@.(>&0*<&_)>.>:%/2-/\

TIO

If the snail cannot climb out of the well, you may return 0, return a falsy value, or throw an exception. For the purpose of writing the test cases, I simply chose None to indicate that there was no answer. Would you also consider adding an explanation and a Try it Online link?

@musicman523 fixed and done.

PHP>=7.1, 60 bytes
prints 0 for no escape

[,$h,$u,$d]=$argv;echo$h>$u?$u>$d?ceil(($h-$d)/($u-$d)):0:1;

PHP Sandbox Online
PHP>=7.1, 67 bytes
prints nothing for no escape

for([,$h,$u,$d]=$argv;($u>$d?:$h<=$u)&&0<$h+$t*$d-$u*++$t;);echo$t;

PHP Sandbox Online

PowerShell, 95 94 bytes
$g=$args[0]
$c=$args[1]
$f=$args[2]
$p=0
$d=0
1..$g|%{$d+=1;$p+=$c;if($p-ge$g){$d;exit}$p-=$f}

Try it online!

Ruby, 49 47 bytes
->h,a,b{h-a<1?1:(1.0*(h-a)/[a-b,0].max+1).ceil}

Throws exception if snail can't climb out
Try it online!

@Jonah fixed it

What's the reasoning behind the proc? h-a<1?1:(1.0*(h-a)/[a-b,0].max+1).ceil passes the test cases, and saves 9 bytes.

Mathematica, 47 40 39 bytes
If[#==#2,1,⌈(#-#3)/(#2-#3)⌉~Max~0]&

-7 bytes from @KeyuGan

You need to deal with input as 69, 3, 8 and ⌈ is counted as 3 bytes as far as I think.

all fixed! try it now

you may use Max to replace If statement. If[#<=#2,1,Max[⌈(#-#3)/(#2-#3)⌉,0]]&

Python v2 & v3, 44 Bytes
f=lambda x,y,z:1+f(x-(y-z),y,z)if x>y else 1

^Infinite recursion (error) for None case.

You can use lambda. Also, this seems similar to my (Java) answer so allow me to suggest an improvement in the formula: (x-z-1)//(y-z)+1. I don't do much Python, so I might be wrong...

You can eliminate f= from the byte count, remove some spaces around ifs and elses, and switch to Python 2 where integer division is a single /

Thanks @musicman523.  I ended up taking all of your advice.

I realized that my "clean" (no infinite recursion) code had lots of corner-case issues when used with other inputs (ie. 4, 3, 8). @musicman523 I think I'm starting to see the "proofs" that you speak of.

QBIC, 31 23 bytes
Just noticed the requirements changed. This version doesn't check if the snail will ever reach the top of the well.
≈:-:>0|q=q+1┘a=a-b+:]?q

The explanation below, for the original version that does check if a solution exists, covers all relevant parts of this code too.

Original, 31 byte answer:
~:>:|≈:-a>0|q=q+1┘c=c-a+b]?q\?0

Explanation
~           IF
 :          cmd line arg 'a'  (the increment of our snail)
  >         is greater than
   :        cmd line arg 'b'  (the decrement, or daily drop)
    |       THEN
≈           WHILE
 :          cmd line arg 'c'  (the height of the well)
  -a        minus the increment (we count down the hieght-to-go)
    >0|     is greater than 0 (ie while we haven't reached the top yet)
q=q+1       Add a day to q (day counter, starts at 1)
┘           (syntactic linebreak)
c=c-a+b     Do the raise-and-drop on the height-to-go
]           WEND
?q          PRINT q (the number of days)
\?0         ELSE (incrementer <= decrementer) print 0 (no solution)

Try it online! (OK, not really: this is a translation of QBIC to QBasic code run in repl.it 's (somewhat lacking) QBasic enviroment)

Batch, 66 bytes
@set/an=%4+1,a=%1-%2+%3
@if %1 gtr %2 %0 %a% %2 %3 %n%
@echo %n%

The second last test case printed nothing, and the last test case actually crashed CMD.EXE...

05AB1E, 19 bytes
0[¼²+D¹<›i¾q}³-D1‹#

Explanation:
0                   Initialise stack with 0
 [                  while(true)
  ¼                   increment the counter variable
   ²+                 add the second input to the top of the stack
     D¹<›i            if it is greater than or equal to the first input
          ¾             push the counter variable
           q            terminate the program
             }        end if
              ³-      subtract the third input from the top of the stack
                D     duplicate top of stack
                 1‹   if it is less than 1
                   #  break the loop

For invalid values, this may return any value less than 1. However, in 05AB1E, only 1 is truthy so this meets the requirement that the output for an invalid value should be falsy.
Try it online!

05AB1E, 12 bytes
.×ηO<²›1k2÷>

Try it online!
Prints 0 if impossible.
Input format:
[climb, -fall]
height

PHP, 60 bytes
[,$h,$v,$d]=$argv;echo$h>$v?$v>$d?ceil(($h-$d)/($v-$d)):N:1;

prints N for None. Run with -r.

Japt, 12 bytes
@UµV-W §W}aÄ

Test it online!
Outputs undefined for never, after possibly freezing your browser for a while, so please be careful.
I'm not convinced this is optimal. oWV-W l works on all but the last three cases...

Came up with this for 11 bytes by changing the order of the inputs.

Excel VBA, 47 Bytes
Anonymous VBE immediate window function that takes input in from the range [A1:C1] from the ActiveSheet object outputs to the VBE immediate window
This primarily Excel formula based solution appears to be smaller than any purely VBA solution that I can come up with :(
?[If(B1>C1,-Int((B1-A1)/(B1-C1)-1),Int(A1=B1))]

HP-15C Programmable Calculator, 26 Bytes
The three numbers are loaded into the stack in order before running the program. The fall height is entered as a negative number. If the snail cannot climb out of the well, the result is either a negative number or error #0 (zero divide error).
Op codes in hex:
C5 C1 B4 C5 FB 74 1A C4 FA B4 C5 FD C1 C1 A3 70 C6 F0 B4 FA EB F1 FA B2 0A F1

Instruction meanings:
x↔y
ENTER
g R⬆
x↔y
−
g TEST x≤0
GTO A
R⬇
+
g R⬆
x↔y
÷
ENTER
ENTER
f FRAC
TEST x≠0
EEX
0
g R⬆
+
g INT
1
+
g RTN
f LBL A
1

You can try the program with this HP-15C simulator.

This is awesome! Welcome to PPCG :)

Common Lisp, 49 bytes
(defun f(a b c)(if(> a b)(1+(f(+(- a b)c)b c))1))

Try it online!
Recursive function, stack overflow if no solution found.

Jelly, 10 bytes
ẋ;\m2S€<i0

Try it online!

Haskell, 47 55 bytes (48 if tuple required)
f d c s|d<=c=1|c<s= -1|d>c||c<s=1+(f(d-c+s)c s)

tuple variation
f(d,c,s)|d<=c=1|c<s= -1|d>c||c<s=1+(f(d-c+s)c s)

Explanation
f d c s       function that does all the heavy lifting =)
              d - depth
              c - climb per day
              s - slide per night

 |d<=c=1             recursion terminator. 1 day of climbing
 |c<s= -1            possibility check. top can't be reached
 |otherwise=1+(f(d-c+s)c s)  1 day plus the rest of the distance

You can replace d>c||c<s just with 0<1, as you already implicitly do in your explanation, because otherwise is just a synonym of True. 2. The recursive call in your tuple version is still curried. 3. You can define your function as (d#c)s instead of f d c s to save two more bytes.

You also need c<=s instead of c<s.

Reordering and using 0 instead of -1 as allowed by the OP yields 38 bytes: Try it online!

Can you use an infix identifier to save any bytes?

I don't know, if I should post edited anser since it is esentialy @Laikoni's answer

Feel free to use it, it's still the same approach based on your answer.

Python 3, 41 Bytes
f=lambda a,b,c:int(b>=a)or 1+f(a-b+c,b,c)

Error for Never
Outgolf @veganaiZe

Welcome to PPCG! Nice first answer :)

I don't know much Python, but could you change int(b>=a) to 1-(b<a) to save 2 bytes?

Google Sheets, 43 Bytes
Worksheet cell function that takes input from cells A1:C1 and outputs to the calling cell
=if(B1>C1,-int((B1-A1)/(B1-C1)-1),int(A1=B1

Excel, 45 Bytes
Same as above, but formatted for MS Excel
=If(B1>C1,-Int((B1-A1)/(B1-C1)-1),Int(A1=B1))

Excel solution does not seem to handle cases where climb distance =  well depth. (5,5,10) (7,7,7)

@Wernisch, good catch! I've corrected this by replacing 0 in the if statement with a INT(A1=B1) call

APL (Dyalog), 13 bytes
(⌈+÷⊢)/0⌈2-/⊢

Try it online!

Errors on division by zero if the snail cannot climb out of the well.

C# (.NET Core), 37 bytes
(h,c,f)=>h>c?f<c?1+(h-f-1)/(c-f):0:1;

Non-recursive lambda. Uses formula found here. Could be shortened by 6 bytes if "any negative result" is a valid way to return failure; currently returns 0 instead.

It's been a while, but h-f-1 can be h+~f.

Jelly, 8 bytes
ẋ+\<i0HĊ

Try it online!
How it Works
ẋ+\<i0HĊ - main link. The inputs are a list and an int, e.g. 3,-2 and 30
ẋ          - repeat the first input a number of times equal to the second input
               e.g. 3,-2,3,-2,3,-2,3,-2,...3,-2 (60 elements total)
 +\        - cumulative sum, e.g. 3,1,4,2,5,3,6,4,7,5,8,...32,30
   <       - less than (the second element)
    i0     - get the index of the first 0
      HĊ   - halve and round up

bash, 39 bytes
echo $((d=$2-$3,d>0?$1/d-$3/d:$2/$1%2))

Try it online!

Kotlin, 70 bytes
fun s(h:Int,c:Int,f:Int):Int=if(h>c)if(c>f)1+s(h-c+f,c,f)else 0 else 1

Try it online!

@yBASIC, 45 bytes
@__
_=_+_%-_#__=__+!.GOTO(@_)+"_"*(_>_%)@_?__

The language has no support for input so you have to set variables _, _%, and _# to the well depth, fall distance, and climb distance, respectively. (Is this allowed?)
Try it online! (Experimental)

GolfScript, 30 bytes
:c-.{(c@-.{/))}{;1<}if}{;;1}if

The code in the header is purely to make the input easier - it just swaps around the order into another valid inpu format, just for ease of copying examples.
I thought this was going to be an 8-bte solution! And it is... kinda. Turns out we need two catches here, and each of them add a ton to make sure GS doesn't error out. Oh well. It works :)
Try it online!

PowerShell, 60 59 bytes
-1 byte thanks to mazzy

param($g,$c,$f)for(){++$d;if(($p+=$c)-ge$g){$d;exit}$p-=$f}

Try it online!
An optimization of root's answer. If you like this, upvote his.
This runs forever on tests that are impossible. It also exits the script altogether on return so the test script is a bit sillier than normal.

?

PowerShell, 50 bytes
for($g,$c,$f=$args;($p+=$c)-lt$g;++$d){$p-=$f}1+$d

Try it online!

R, 50 bytes
f=function(x,y,z)`if`(y>z,ceiling((x-z)/(y-z)),0)

Similar logic to others, let down by ceiling and function being such long words..
Usage:
> f(30,3,2)
[1] 28

> f(30,3,20)
[1] 0

f(5, 5, 10) should be 1.

Clojure - 80 70 bytes
(defn snail[x y z](cond(>= y x)1(> y z)(Math/ceil(/(- x z)(- y z))):else false))

Ungolfed version:
(defn snail [x y z]
  (cond
    (>= y x) 1
    (> y z)  (Math/ceil (/ (- x z) (- y z)))
    :else    false))

As a (shorter) anonymous function:
#(cond(<= %2 %1)1(> %2 %3)(Math/ceil(/(- %1 %3)(- %2 %3))):else false)

My original thinking (without checking, naturally) was that the % chars in the substitution markers would outweigh the benefit of getting rid of defn snail [x y z]. Apparently NOT! :-)

This is great! Since the function is not recursive, can you define it as an anonymous function instead to save bytes?

I'd originally glanced at it and thought that the % chars on all the parameter references would outweigh the benefit of getting rid of defn snail [x y z]. Thanks for prodding me to reconsider this. :-)

Add++, 31 bytes
D,f,@@@,¿@>,@$_+abRbUp${f}1+,1¿

Try it online!
First ever use of the ternary expression! Raises an Exception on invalid inputs
How it works
D,f,@@@,		; Declare a triadic function
			; Example arguments: 		[30 3 2]. Labelled [A B C] here
	¿		; If...
		@>	; 	A > B
	,		; Then...
		@	; 	Reverse;	STACK = [2 3 30]
		$_	; 	Swap subtract;	STACK = [2 27]
		+	; 	Add;		STACK = [29]
		abRbU	; 	Reversed args;	STACK = [29 2 3 30]
		p$	; 	Pop and swap;	STACK = [29 3 2]
		{f}	; 	Call 'f';	STACK = [27]
		1+	; 	Add 1;		STACK = [28]
	,		; Else...
	1		; 	Push 1;
	¿		; Endif
			;			Returns  28

Try it online!

Python 3, 36 bytes
f=lambda h,a,b:h and-~f(h>>a<<b,a,b)

Try it online!
I/O format is questionable, but I think the idea is interesting enough for it to be posted.
Input:

h: If the depth of the well is d, h is an integer whose binary representation has d digits (ignoring leading zeros). For example, if d = 4, h can be 0b1111.
a: The climb distance
b: The fall distance, (positive integer).

Output: Number of days for the snail to climb out of the well. If it's impossible to climb out, runs forever.
Explanation
h>>a<<b will have the number of binary digits equals to the remaining height after one day. If the snail reaches the top during the day, then h>>a is 0, thus h>>a<<b is still 0.
The function is a recursive function that returns 0 if h==0, else recurs on h = h>>a<<b. The golfed code use the fact that -~x == 1+x to save 1 space.

authors: Bob Jarvis - Слава Україні

authors: Евгений Новиков


text:
Golf the Lucas Lehmer Primality Test
your task is to write a program that uses the Lucas-Lehmer primality test to check whether an input number is prime or not. This prime number candidate has the form 2p-1 with p being prime. (Mersenne prime number)
The Lucas-Lehmer-test
The n-th Mersenne number is prime if it is a divisor of the (n-1)-th Lucas-Lehmer number (LLN).
You can calculate the LLN, similiar to the Fibonacci numbers, based on a recursive algorithm:
L<n> = (L<n-1>)^2 - 2

The LLN for 2 is 14. So, for p=3, LLN<3-1>=14
Evaluation

You have to submit a function that takes p as input (Remember: 2^p-1)
The shortest solution will win.
Your solution has to use the Lucas-Lehmer test
The code must be executable.
Output: boolean value or 1=prime/0=not prime

Tests:
p --> 2^p-1  --> LLN<n-1> --> ?
3 --> 7      --> 14  --> prime
5 --> 31     --> 37634 > prime (1214*31)

Good Luck

Related

@PeterTaylor, No, I request the LLT. The other one just any possible test.

I linked to an answer which implements the LLT. Besides, what does "related" mean if a question which asks for a specific test of a property is not related to a question which asks for any test of the same property?

O.k. but maybe there are other (shorter) solutions, e.g. in other languages.
Only because someone somewhere posted something this is not a duplicate.
Of course it is related. But there are 48 search results on Mersenne and 467 on prime test. And only two especially on the LLT. And only one of them is a question.
And if I am expecting a special test, this is a different challenge. Of course there are matches within the possible answers. But as stated: there are a lot of prime test competitions with possible matching answers

He didn't say it was a duplicate, he said Related

Also I'm pretty sure this falls under unobservable criteria

@Mayube It does not. At least not in theory.

05AB1E, 11 bytes
o<4IÍFnÍ}sÖ

Try it online!
Explanation
o<            # push 2^p-1
  4           # push 4
   IÍF        # p-2 times do:
      nÍ      # square and subtract 2
        }     # end loop
         sÖ   # LLN(n) % Mp == 0

If we didn't need boolean value output we could save a byte with 4IÍFnÍIo<%  which returns 0 for prime and non-zero otherwise.

Python 2, 51 bytes
p=input()
s=4
exec's=(s*s-2)%(2**p-1);'*(p-2)
s>0>x

Try it online!
Output is via exit code

Isn't this a snippet?

@OlivierGrégoire it takes input in the first line and outputs by crashing / not crashing in the last line, which is meant by Output is via exit code. This is a valid output method.

Ok, it's a full program. I didn't read it as such, my bad! :)

Haskell, 47 43 41 bytes
Thanks @Kittsil for saving me 2 bytes!
f n=iterate(\v->mod(v^2-2)$2^n-1)4!!n-2<1

Try it online!

Using pattern matching instead of guards saves you 4 bytes in this case
p 2=4;p n=p(x-1)^2-2
Try it online!

Mathematica 44 Bytes
(s@3=14;s@n_:=Mod[s[n-1]^2-2,2^#-1];s@#==0)&

Test:
{#, %[#]} & /@ Prime[Range[2, 20]]

Too bad we can't use MersennePrimeExponentQ (22 bytes) since it doesn't appear to always use the LLT.

Python 3, 61 bytes
l=lambda x:4*(x<3)or l(x-1)**2-2
f=lambda p:not l(p)%(2**p-1)

Try it online!
I'd like to note that the Lucas-Lehmer test only applies to odd primes Mersenne numbers of the form 2p-1 where p is an odd prime. This program uses a recursive function for the Lucas-Lehmer numbers, and then a function that just tests if the n-th LLN is divisible by Mn.

The Lucas Lehmer test only applies to Mersenne primes. And 2 is no Mersenne prime. So they have to apply to odd primes only.

@PaulStrobach Should have been more specific. The Lucas-Lehmer test only applies to Mersenne primes of the form 2^p-1 where p is an odd prime. I am aware that 2 is no Mersenne prime, but 2^2-1 is, which will not be detected by this test.

ok. misunderstood you: L<2>=4, 4 % 3 != 0

PHP, 58 bytes
for($s=4;++$i+1<$argn;)$s=($s**2-2)%(2**$argn-1);echo+!$s;

Try it online!

APL, 28 bytes
{0=(¯1+2*⍵)|(¯2+×⍨)⍣(⍵-2)⊢4}

Explanation:
                         ⊢4    ⍝ to the number 4,
                   ⍣(⍵-2)      ⍝ apply this function ⍵-2 times,
            (¯2+×⍨)            ⍝ N*N - 2
   (¯1+2*⍵)|                   ⍝ modulo 2^⍵ - 1
 0=                            ⍝ is the result 0?

source: Stack Exchange

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

sort: votes


text:
Square root a number
The task is as follows: Given a positive integer x and a prime n > x, output the smallest positive integer y such that (y * y) mod n = x.  An  important part of this question is the time limit specified below which excludes brute force solutions.
If there is no such value y then your code should output N.
Test cases
(2, 5, N),
(3, 5, N),
(4, 5, 2),
(524291, 1048583, N),
(529533, 1048583, N),
(534775, 1048583, 436853),
(540017, 1048583, 73675),
(536870913, 1073741827, 375394238),
(542239622, 1073741827, 267746399),
(547608331, 1073741827, N),
(552977040, 1073741827, 104595351),
(1099511627676, 1099511627791, N),
(1099511627677, 1099511627791, 269691261521),
(1099511627678, 1099511627791, 413834069585),
(1267650600228229401496703204376, 1267650600228229401496703205653, 5312823546347991512233563776),
(1267650600228229401496703204476, 1267650600228229401496703205653, N)
(1267650600228229401496703204576, 1267650600228229401496703205653, N)
(1267650600228229401496703204676, 1267650600228229401496703205653, 79905476259539917812907012931)

Input and output
You may take input and give output in any way that is convenient. If you don't like to output N then any Falsey value will do.
Restrictions
Your code must answer all the test cases in under 1 minute on a standard desktop. This time limit is only to prevent brute force answers and I expect good answers to run almost instantly. You may not use any library or builtin that solves this problem or that tests if a number is a quadratic residue.

So languages without support for big-integer data type are ruled out. Pity

@LuisMendo Not if you can code up support for 1267650600228229401496703205653 yourself or if you have 128 bit support such as __int128 in gcc. There are also a number of 256 bit int libraries out there for various languages. Last, lots of languages have an arbitrary precision int library.

Pyth, 83 82 bytes
=eAQM.^GHQKf%=/H=2;1=gftgT/Q;1HJg~gGHh/H2WtG=*J=gT^2t-K=Kfq1gG^2T1=%*G=^T2Q;hS%_BJ

Test suite
This program implements the Tonelli-Shanks algorithm. I wrote it by closely following the Wikipedia page. It takes as input (n, p).
The absence of a square root is reported by the following error:
TypeError: pow() 3rd argument not allowed unless all arguments are integers

This is very intricately golfed code, written in the imperative style, as opposed to the more common functional style of Pyth.
The one subtle aspect of Pyth I'm using is =, which, if not immediately followed by a variable, searches forward in the program for the next variable, then assigns the result of the following expression to that variable, then returns that result. I will refer throughout the explanation to the wikipedia page: Tonelli-Shanks algorithm, as that is the algorithm I am implementing.
Explanation:
=eAQ

A takes a 2-tuple as input, and assigns the values to G and H respectively, and returns its input. Q is the initial input. e returns the last element of a sequence. After this snippet, G is n, and H and Q are p.
M.^GHQ

M defines a 2 input function g, where the inputs are G and H. .^ is Pyth's fast modular exponentiation function. This snippet defines g to mean exponentiation mod Q.
Kf%=/H=2;1

f defines a repeat until false loop, and returns the number of iterations it runs for, given 1 as its input. During each iteration of the loop, we divide H by 2, set H to that value, and check whether the result is odd. Once it is, we stop. K stores the number of iterations this took.
One very tricky thing is the =2; bit. = searches ahead for the next variable, which is T, so T is set to 2. However, T inside an f loop is the iteration counter, so we use ; to get the value of T from the global environment. This is done to save a couple of bytes of whitespace that would otherwise be needed to separate the numbers.
After this snippet, K is S from the wikipedia article (wiki), and H is Q from the wiki, and T is 2.
=gftgT/Q;1H

Now, we need to find a quadratic nonresidue mod p. We'll brute force this using the Euler criterion. /Q2 is (p-1)/2, since / is floored division, so ftgT/Q;1 finds the first integer T where T ^ ((p-1)/2) != 1, as desired. Recall that ; again pulls T from the global environment, which is still 2. This result is z from the wiki.
Next, to create c from the wiki, we need z^Q, so we wrap the above in g ... H and assign the result to T. Now T is c from the wiki.
Jg~gGHh/H2

Let's separate out this: ~gGH. ~ is like =, but returns the original value of the variable, not its new value. Thus, it returns G, which is n from the wiki.
This assigns J the value of n^((Q+1)/2), which is R from the wiki.
Now, the following takes effect:
~gGH

This assigns G the value n^Q, which is t from the wiki.
Now, we have our loop variables set up. M, c, t, R from the wiki are K, T, G, J.
The body of the loop is complicated, so I'm going to present it with the whitespace, the way I wrote it:
WtG
  =*J
    =
      gT^2
        t-
          K
          =Kfq1gG^2T1
  =%*G=^T2Q;

First, we check whether G is 1. If so, we exit the loop.
The next code that runs is:
=Kfq1gG^2T1

Here, we search for the first value of i such that G^(2^i) mod Q = 1, starting at 1. The result is saved in K.
=gT^2t-K=Kfq1gG^2T1

Here, we take the old value of K, subtract the new value of K, subtract 1, raise 2 to that power, and then raise T to that power mod Q, and then assign the result to T. This makes T equal to b from the wiki.
This is also the line which terminates the loop and fails if there is no solution, because in that case the new value of K will equal the old value of K, 2 will be raised to the -1, and the modular exponentiation will raise an error.
=*J

Next, we multiply J by the above result and store it back in J, keeping R updated.
=^T2

Then we square T and store the result back in T, setting T back to c from the wiki.
=%*G=^T2Q

Then we multiply G by that result, take it mod Q and store the result back in G.
;

And we terminate the loop.
After the loop's over, J is a square root of n mod p. To find the smallest one, we use the following code:
hS%_BJ

_BJ creates the list of J and its negation, % implicitly takes Q as its second argument, and uses the default behavior of Pyth to apply % ... Q to each member of the sequence. Then S sorts the list and h takes its first member, the minimum.

Python 2, 166 bytes
def Q(x,n,a=0):
 e=n/2
 while pow(a*a-x,e,n)<2:a+=1
 w=a*a-x;b=r=a;c=s=1
 while e:
    if e%2:r,s=(r*b+s*c*w)%n,r*c+s*b
    b,c=(b*b+c*c*w)%n,2*b*c;e/=2
 return min(r,-r%n)

%timeit Q(1267650600228229401496703204676,1267650600228229401496703205653) 100 loops, best of 3: 2.83 ms per loop  :)

What a great answer! You have restored my faith in PPCG.

Excuse the newbie question, but whats PPCG? Polish Python Coders Group?

@DaveBoltman Programming Puzzles & Code Golf.

SageMath, 93 bytes
By reduction to a much harder problem for which SageMath happens to have fast enough builtins.
def f(x,n):g=primitive_root(n);k=Zmod(n)(x).log(g);y=pow(g,k//2,n);return k%2<1and min(y,n-y)

Try it on SageMathCell

That reduction is quite funny :)

Haskell, 326 bytes
Usually I like brute force answers.. Since this is strongly discouraged by the time limit, here's the most efficient way I know of:
r p=((\r->min(mod(-r)p)r)$).f p
f p x|p==2=x|q x=f 0 0|mod p 4==3=x&div(p+1)4|let(r,s)=foldl i(p-1,0)[1..t 1o]=m$x&(d$r+1)*(b&d s)where q a=1/=a&o;m=(`mod`p);a&0=1;a&e|even e=m$a&d e^2|0<1=m$(a&(e-1))*a;b=[n|n<-[2..],q n]!!0;i(a,b)_|m(x&d a*b&d b)==p-1=(d a,d b+o)|0<1=(d a,d b);o=d p;t y x|even x=t(y+1)(d x)|0<1=y;d=(`div`2)

Try it online!
I'm sure this can be golfed down further, but this should do for now.

Could you modify the TIO code so it gives the answers as output? I just get "True" at the moment.

Try it online!

@Lembik You need to replace testCases with those from the original TIO, it barely fit into a comment even without them.

@ØrjanJohansen Thanks a lot! I adjusted my answer with your code and replaced  testCases.

Huh, I'm seeing a bizarre bug with that TIO link - if I click it it has the code but neither running nor getting the URL from the menu options works - but if I copy the URL from the address bar and paste it into a different tab, then it works.

@ØrjanJohansen Not sure.. On my machine it works as expected, have you tried other TIOs? Maybe NoScript or similar getting in your way?

I suspect some caching issue somewhere, because now it's working again.

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


text:
Find the coefficients of a rational generating function
If we write a sequence of numbers as the coefficients of a power series, then that power series is called the (ordinary) generating function (or G.f.) of that sequence. That is, if for some function F(x) and series of integers a(n) we have:
a(0) + a(1)x + a(2)x^2 + a(3)x^3 + a(4)x^4 + ... = F(x)

Then F(x) is the generating function of a. For example, the geometric series tells us that:
1 + x + x^2 + x^3 + x^4 + ... = 1/(1-x)

So the generating function of 1, 1, 1, ... is 1/(1-x). If we differentiate both sides of the equation above and multiply by x we get the following equality:
x + 2x^2 + 3x^3 + 4x^4 + ... = x/(1-x)^2

So the generating function of 1, 2, 3, ... is x/(1-x)^2. Generating functions are a very powerful tool, and you can do many useful things with them. A short introduction can be found here, but for a really thorough explanation there is the amazing book generatingfunctionology.

In this challenge you will take a rational function (the quotient of two polynomials with integer coefficients) as input as two arrays of integer coefficients, first the numerator then the denominator. For example the function f(x) = x / (1 - x - x^2) will be encoded as [0, 1], [1, -1, -1] in the input.
Given this input your program must infinitely print the coefficients of the power series that equals the generating function, one per line, starting at the coefficient of x, then x^2, etc.

Examples:
[1], [1, -1] -> 1, 1, 1, 1, 1, 1, 1, ...
[1], [2, -2] -> 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, ...
[0, 1], [1, -2, 1] -> 1, 2, 3, 4, 5, 6, 7, 8, ...
[0, 1], [1, -1, -1] -> 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
[1], [1, -2] -> 1, 2, 4, 8, 16, 32, 64, 128, ...
[0, 1, 1], [1, -3, 3, -1] -> 1, 4, 9, 16, 25, 36, ...

Crap, my language is built for sequences this, but I can't really do multidimensional array input :(

@StepHen What input would work for your language?

It's not a flaw in the challenge, it's a flaw in the language. I don't have the ability to process input of variable length yet :P

I'm really just not mathematically-minded enough for this spec, any chance you could post more of a layman's explanation for us common folk?

@Mayube I added another general example at the top of my challenge. If it's still unclear I can suggest reading the linked introduction. Generating functions are a simple concept, but may seem magic to those unfamiliar.

Is it acceptable to use a descending degree order of coefficients? e.g. x^3+2x^2+1 yields [1, 2, 0 ,1]

@KeyuGan That is fine, as long as you clearly state it in your answer.

Possible duplicate of Calculate Power Series Coefficients

@trichoplax That always forces the numerator to be 1, which is not the same. For example it cannot express my last example, the squares.

An alternative way of phrasing this is that it evaluates a general linear recurence. In that way it generalises this question, and might serve as a dupe target for future recurrence questions.

@orlp thanks for explaining the difference - makes sense now.

Is it 1-indexed or 0 indexed? If it is 1-indexed, then the output for [1], [1, -2] should be 2, 4, 8, 16, 32, 64, 128, .... If it is 0-indexed, then the output for [0, 1], [1, -2, 1] should be 0, 1, 2, 3, 4, 5, 6, 7, 8, ....

Haskell, 63 bytes
z=0:z
(a:b)%y@(c:d)=a/c:zipWith(-)(b++z)(map(a/c*)d++z)%y
_%_=z

Try it online!
Defines an operator % returning an infinite lazy list of coefficients. The list is zero-indexed, so the constant coefficient is included.

Mathematica, 64 83 90 bytes
Do[Echo@Limit[D[#/#2/i!&@@Fold[x#+#2&]/@#,{x,i}],x->0],{i,∞}]&

Thanks to @ngenisis and @Jenny_mathy !
Take input as two lists.
Need Alt+. to terminate the execution to see the result. Frontend may crash due to rapid output.
83 bytes version (@Jenny_mathy):
i=1;v=Tr[#*x^Range@Length@#]&;While[1<2,Echo@Limit[D[v@#/v@#2/i!,{x,i}],x->0];i++]&

83 bytes:   i = 1;
v = Tr[#*x^Range@Length@#] &;
While[1 < 2, Echo@Limit[D[v@#/v@#2/i!, {x, i}], x -> 0]; i++] &

@Jenny_mathy Sorry for bothering. I figure it out that there's some junk invisible Unicode characters in your first comment. Once cleaned up, the code is OK.

64 bytes: Do[Echo@Limit[D[#/#2/i!&@@Fold[x#+#2&]/@#,{x,i}],x->0],{i,∞}]&. This assumes the input is a list of two lists and the coefficients are in order of descending degree. The only built-in I know of to do what v does is Internal\FromCoefficientList`

Does running this repeatedly work? I think a couple of extra parentheses might be necessary to put i inside the lambda. (On the other hand, I'm not really sure whether the ability to run repeatedly is relevant when the goal is to print an infinite list…has there been a meta consensus on this?)

@ngenisis: What version are you using? On v10.0, your solution gives me Iterator {i,∞} does not have appropriate bounds.

@JulianWolf 11.1

x^Range@Length@#.#&  saves 4 bytes.  Also I think you can do For instead of While and save 2 more.`

@JulianWolf Do seems to support Infinity on 10.2

@KeyuGan: Thanks. I guess I'm just a couple minor versions early, then.

CJam (22 bytes)
{\{(W$(@\/_pW*f*.+1}g}

Online demo. Note that as many of the existing answers, this includes the 0th coefficient in the output.
Dissection
{           e# Define a block which takes numerator N and denominator D as arguments
  \         e# Flip to put D at the bottom, since that won't change
  {         e# Infinite loop:
    (       e#   Pop the first element of (the modified) N
    W$(     e#   Copy D and pop its first element
            e#   Stack: D N[1:] N[0] D[1:] D[0]
    @\/     e#   Bring N[0] to top, flip, divide
            e#   Stack: D N[1:] D[1:] N[0]/D[0]
    _p      e#   Print a copy
    W*f*.+  e#   Multiply by -1, multiply all, pointwise add
            e#   Stack: D N[1:]-(N[0]/D[0])*D[1:]
  1}g
}

Mathematica, 86 79 bytes
f=x^Range@Length@#.#&;For[n=1,8>3,Print@SeriesCoefficient[f@#/f@#2,{x,0,n++}]]&

Takes input as two separate lists (numerator coefficients, denominator coefficients).
If the input can be taken directly as a fraction of polynomials rather than as lists of coefficients, this can be shortened significantly.
It seems that Do can work with infinite bounds in v11.
I can't test this locally, but, if this is the case, then this solution can be shortened to 75 bytes:
f=x^Range@Length@#.#&;Do[Print@SeriesCoefficient[f@#/f@#2,{x,0,n}],{n,∞}]&

last test case doesn't begin with 0.

@Jenny_mathy: shoot, thanks for the heads up. Looks like the test cases expect starting from the first in stead of the zeroth…pretty sure this should let me save a few bytes.

@Jenny_mathy: I think the test cases might be wonky. Starting n from 1 in stead of 0, this gives the same results as your solution; both fail, though, on the second to last test case, which this solution passes when starting n from 0.

Pyth, 23 bytes
JE#
KchQhJ=t-M.t,Q*LKJ0

Try it online!
How it works
                       Q = eval(input())
JE                     J = eval(input())
  #                    infinite loop:
 chQhJ                   Q[0]/J[0]
K                        assign that to K (and print it, because of the preceding newline)
              *LKJ       K times every element of J
            ,Q           [Q, that]
          .t      0      transpose, padding with 0s
        -M               subtract each pair
       t                 remove the first element
      =                  assign that back to Q

Pari/GP, 66 bytes
p->q->for(i=0,oo,print(Pol(Polrev(p)/(Polrev(q)+O(x*x^i)))\x^i%x))

Try it online!


text:
Peaceable coexisting armies
In the game of chess, there is piece called the queen that may attack any other piece that is on the same row, column or diagonal. In chess there are typically two sides, black and white, with each piece belonging to one of the teams. Pieces may not attack pieces belong to the same team.
Your goal is to find out the largest peaceable coexisting armies for a square board. That is the largest number of black and white queens that can fit on the board such that no two queens can attack each other and the number of black queens is equal to the number of white queens.
You will receive as input the side length of a square board, and should output the number of size of the largest peaceable coexisting armies that can fit on that board.
This is code-golf so standard rules for the tag apply.
OEIS A250000
These test cases encompass all known answers. Your solution should be a generalized answer that, given enough computing power and time, can compute the solution for any input value.

1: 0
2: 0
3: 1
4: 2
5: 4
6: 5
7: 7
8: 9
9: 12
10: 14
11: 17
12: 21
13: 24

From reading the OEIS link, I'm not sure there are known solutions for arbitrary side length.

@KellyLowder You could always brute force it!

@musicman523, lol something like 3^(6^2) or 10^17 possible states for a 6x6 board.

@KellyLowder I didn't say it would be fast :P

Pruning will speed things up.

C, 476 bytes, DFS iterating white queens, O(2n2)
#define R return
#define Z(q)for(j=q;j<I;j++)
#define Q(q)memset(q,0,4*J);
#define U(q)S(w[k]/I q j,w[k]%I+j)
int*c,*w,*Y,j,k,r,I,J,m;T(i,j){R i*I+j;}S(x,y){x>=0&&x<I&&y>=0&&y<I?Y[T(x,y)]=1:0;}g(l){int i;if(l==m){Q(Y)for(k=m;k--;){Z(0)Y[T(w[k]/I,j)]=Y[T(j,w[k]%I)]=1;Z(-I)U(+),U(-);}for(r=k=J;k--;)r-=Y[k];R r>=m;}for(i=!l?0:w[l-1]+1;i<J;i++){if(!c[i]){c[i]=1;w[l]=i;if(g(l+1))R 1;c[i]=0;}}R 0;}f(s){I=s;J=I*I;int C[J],W[J],y[J];c=C;w=W;Y=y;for(m=1;;m++){Q(c)if(!g(0))R m-1;}}

518 bytes, DFS with pruning, O(2n)
#define R return
#define Z(q)for(j=q;j<I;j++)
#define Q(q)memset(q,0,4*J);
#define V(Q)t=Q;if(!Y[t]){G-=Y[t]=1;b[B++]=t;}
#define F(q)if(S(x q j,y+j)){V((x q j)*I+y+j)}
int*c,*w,*Y,j,k,r,I,J,m;S(x,y){R x>=0&&x<I&&y>=0&&y<I;}D(l,H){int i,b[J],B,t,x,y,G;if(l==m)R 1;for(i=!l?0:w[l-1]+1;i<J;i++){if(!c[i]){c[i]=1;w[l]=i;x=i/I;y=i%I;G=H;Z(B=0){V(x*I+j)V(j*I+y)}Z(-I){F(+)F(-)}if(G>=m&&D(l+1,G))R 1;for(j=B;j--;)Y[b[j]]=0;c[i]=0;}}R 0;}f(s){I=s;J=I*I;int C[J],W[J],y[J];c=C;w=W;Y=y;for(m=1;;m++){Q(c)Q(Y)if(!D(0,J))R m-1;}}

577 bytes, DFS iterating white and black queens, O(?)
#define R return
#define U(V,r,q)S(V,r[i]/I q j,r[i]%I+j)
#define W(q)for(j=q;j<I;j++)
#define Z(r,q,t,v)for(i=0;i<r;i++){t[q[i]]=1;W(0)v[T(q[i]/I,j)]=v[T(j,q[i]%I)]=1;W(-I)U(v,q,+),U(v,q,-);};
#define P(K,L,M)memcpy(v,K,4*J);for(i=0;i<J;i++)if(!v[i]){L[M++]=i;if(g(E,N,!C))R 1;M--;};
int*w,*b,m,I,J;T(i,j){R i*I+j;}Q(int*q){memset(q,0,4*J);}S(V,x,y)int*V;{x>=0&&x<I&&y>=0&&y<I?V[T(x,y)]=1:0;}g(E,N,C){int i,j,v[J],X[J],Y[J];if(E==m&&N==m)R 1;Q(X);Q(Y);Z(E,w,X,Y)Z(N,b,Y,X)if(C){P(Y,b,N)}else{P(X,w,E)}R 0;}f(q){I=q,J=I*I;int W[J],B[J];w=W,b=B;for(m=1;;m++)if(!g(0,0,0))R m-1;}

Basically, the code iterates over possibilities of white queen and check whether black queen could be placed then.
Speed reference table (in seconds):
+---+----------------------+---------------------+-----------------+--------+
| n |      DFS w & b       |        DFS w        |  DFS w/ pruning | Clingo |
+---+----------------------+---------------------+-----------------+--------+
| 3 |                 0.00 |                0.00 |            0.00 |   0.01 |
| 4 |                 0.00 |                0.00 |            0.00 |   0.02 |
| 5 |                 0.47 |                0.16 |            0.00 |   0.04 |
| 6 |                20.62 |                1.14 |            0.00 |   0.60 |
| 7 |              1125.07 |              397.88 |            0.63 |  18.14 |
| 8 |                      |                     |            1.28 | 979.35 |
| 9 |                      |                     |           23.13 |        |
+---+----------------------+---------------------+-----------------+--------+

Clingo, 90 bytes
{q(1..n,1..n)}.a(X+(-I;0;I),Y+(0;I)):-q(X,Y),I=-n..n.:~K={q(X,Y)},{a(1..n,1..n)}n*n-K.[-K]

Demo
$ clingo peaceable.lp -cn=6
clingo version 5.1.0
Reading from peaceable.lp
Solving...
Answer: 1

Optimization: 0
Answer: 2
q(6,1) a(7,1) a(7,2) a(8,1) a(8,3) a(9,1) a(9,4) a(10,1) a(10,5) a(11,1) a(11,6) a(12,1) a(6,1) a(6,2) a(6,3) a(6,4) a(6,5) a(6,6) a(5,1) a(5,2) a(4,1) a(4,3) a(3,1) a(3,4) a(2,1) a(2,5) a(1,1) a(1,6) a(0,1) a(7,0) a(8,-1) a(9,-2) a(10,-3) a(11,-4) a(12,-5) a(6,-4) a(6,-3) a(6,-2) a(6,-1) a(6,0) a(5,0) a(4,-1) a(0,7) a(1,-4) a(2,-3) a(3,-2) a(6,-5) a(6,7) a(0,-5) a(12,7)
Optimization: -1
Answer: 3
q(1,6) q(6,1) a(7,1) a(7,2) a(7,6) a(8,1) a(8,3) a(9,1) a(9,4) a(10,1) a(10,5) a(11,1) a(11,6) a(12,1) a(6,1) a(6,2) a(6,3) a(6,4) a(6,5) a(6,6) a(5,1) a(5,2) a(5,6) a(4,1) a(4,3) a(4,6) a(3,1) a(3,4) a(3,6) a(2,1) a(2,5) a(2,6) a(1,1) a(1,2) a(1,3) a(1,4) a(1,5) a(1,6) a(0,1) a(0,5) a(0,6) a(-1,4) a(-1,6) a(-2,3) a(-2,6) a(-3,2) a(-3,6) a(-4,1) a(-4,6) a(-5,6) a(7,0) a(8,-1) a(9,-2) a(10,-3) a(11,-4) a(12,-5) a(6,-4) a(6,-3) a(6,-2) a(6,-1) a(6,0) a(5,0) a(4,-1) a(0,7) a(1,7) a(2,7) a(-1,8) a(1,8) a(3,8) a(-2,9) a(1,9) a(-3,10) a(1,10) a(-4,11) a(1,11) a(-5,12) a(1,-4) a(1,0) a(2,-3) a(3,-2) a(6,-5) a(6,7) a(4,9) a(5,10) a(6,11) a(1,12) a(-5,0) a(0,-5) a(7,12) a(12,7)
Optimization: -2
Answer: 4
q(1,6) q(6,1) q(6,6) a(7,1) a(7,2) a(7,5) a(7,6) a(8,1) a(8,3) a(8,4) a(8,6) a(9,1) a(9,3) a(9,4) a(9,6) a(10,1) a(10,2) a(10,5) a(10,6) a(11,1) a(11,6) a(12,1) a(12,6) a(6,1) a(6,2) a(6,3) a(6,4) a(6,5) a(6,6) a(5,1) a(5,2) a(5,5) a(5,6) a(4,1) a(4,3) a(4,4) a(4,6) a(3,1) a(3,3) a(3,4) a(3,6) a(2,1) a(2,2) a(2,5) a(2,6) a(1,1) a(1,2) a(1,3) a(1,4) a(1,5) a(1,6) a(0,1) a(0,5) a(0,6) a(-1,4) a(-1,6) a(-2,3) a(-2,6) a(-3,2) a(-3,6) a(-4,1) a(-4,6) a(-5,6) a(7,0) a(8,-1) a(9,-2) a(10,-3) a(11,-4) a(12,-5) a(12,0) a(6,-4) a(6,-3) a(6,-2) a(6,-1) a(6,0) a(5,0) a(4,-1) a(0,7) a(1,7) a(2,7) a(5,7) a(-1,8) a(1,8) a(3,8) a(4,8) a(-2,9) a(1,9) a(3,9) a(-3,10) a(1,10) a(2,10) a(-4,11) a(1,11) a(-5,12) a(0,12) a(1,-4) a(1,0) a(2,-3) a(3,-2) a(6,-5) a(6,7) a(6,8) a(4,9) a(6,9) a(5,10) a(6,10) a(6,11) a(1,12) a(6,12) a(-5,0) a(0,-5) a(0,0) a(7,7) a(8,8) a(9,9) a(10,10) a(11,11) a(7,12) a(12,7) a(12,12)
Optimization: -3
Answer: 5
q(1,1) q(1,6) q(6,1) q(6,6) a(7,1) a(7,2) a(7,5) a(7,6) a(8,1) a(8,3) a(8,4) a(8,6) a(9,1) a(9,3) a(9,4) a(9,6) a(10,1) a(10,2) a(10,5) a(10,6) a(11,1) a(11,6) a(12,1) a(12,6) a(6,1) a(6,2) a(6,3) a(6,4) a(6,5) a(6,6) a(5,1) a(5,2) a(5,5) a(5,6) a(4,1) a(4,3) a(4,4) a(4,6) a(3,1) a(3,3) a(3,4) a(3,6) a(2,1) a(2,2) a(2,5) a(2,6) a(1,1) a(1,2) a(1,3) a(1,4) a(1,5) a(1,6) a(0,1) a(0,2) a(0,5) a(0,6) a(-1,1) a(-1,3) a(-1,4) a(-1,6) a(-2,1) a(-2,3) a(-2,4) a(-2,6) a(-3,1) a(-3,2) a(-3,5) a(-3,6) a(-4,1) a(-4,6) a(-5,1) a(-5,6) a(7,-5) a(7,0) a(8,-1) a(9,-2) a(10,-3) a(11,-4) a(12,-5) a(12,0) a(6,-4) a(6,-3) a(6,-2) a(6,-1) a(6,0) a(5,-3) a(5,0) a(4,-2) a(4,-1) a(3,-1) a(2,0) a(0,7) a(1,7) a(2,7) a(5,7) a(-1,8) a(1,8) a(3,8) a(4,8) a(-2,9) a(1,9) a(3,9) a(-3,10) a(1,10) a(2,10) a(-4,11) a(1,11) a(-5,7) a(-5,12) a(0,12) a(1,-5) a(1,-4) a(1,-3) a(1,-2) a(1,-1) a(1,0) a(2,-3) a(3,-2) a(6,-5) a(6,7) a(6,8) a(4,9) a(6,9) a(5,10) a(6,10) a(6,11) a(1,12) a(6,12) a(-5,-5) a(-5,0) a(-4,-4) a(-3,-3) a(-2,-2) a(-1,-1) a(0,-5) a(0,0) a(7,7) a(8,8) a(9,9) a(10,10) a(11,11) a(7,12) a(12,7) a(12,12)
Optimization: -4
Answer: 6
q(1,2) q(1,3) q(2,2) q(2,3) q(2,6) a(7,1) a(7,2) a(7,3) a(7,6) a(8,2) a(8,3) a(8,6) a(6,2) a(6,3) a(6,6) a(5,2) a(5,3) a(5,5) a(5,6) a(4,1) a(4,2) a(4,3) a(4,4) a(4,5) a(4,6) a(3,1) a(3,2) a(3,3) a(3,4) a(3,5) a(3,6) a(2,1) a(2,2) a(2,3) a(2,4) a(2,5) a(2,6) a(1,1) a(1,2) a(1,3) a(1,4) a(1,5) a(1,6) a(0,1) a(0,2) a(0,3) a(0,4) a(0,5) a(0,6) a(-1,1) a(-1,2) a(-1,3) a(-1,4) a(-1,5) a(-1,6) a(-2,2) a(-2,3) a(-2,5) a(-2,6) a(-3,1) a(-3,2) a(-3,3) a(-3,6) a(-4,2) a(-4,3) a(-4,6) a(-5,2) a(-5,3) a(7,-4) a(7,-3) a(7,-2) a(8,-4) a(8,-3) a(8,0) a(6,-3) a(6,-2) a(6,-1) a(5,-2) a(5,-1) a(5,0) a(4,-1) a(4,0) a(3,0) a(2,0) a(1,7) a(2,7) a(3,7) a(5,7) a(0,8) a(1,8) a(2,8) a(4,8) a(-2,7) a(-1,9) a(1,9) a(2,9) a(-3,7) a(-3,8) a(-2,10) a(2,10) a(-4,7) a(-4,8) a(-4,9) a(-3,11) a(-5,8) a(-5,9) a(-4,12) a(1,-4) a(1,-3) a(1,-2) a(1,-1) a(1,0) a(2,-4) a(2,-3) a(2,-2) a(2,-1) a(6,7) a(6,8) a(5,9) a(6,10) a(2,11) a(2,12) a(-5,-4) a(-5,-3) a(-4,-4) a(-4,-3) a(-4,-2) a(-4,0) a(-3,-3) a(-3,-2) a(-3,-1) a(-2,-2) a(-2,-1) a(-2,0) a(-1,-1) a(-1,0) a(0,0) a(7,7) a(7,8) a(8,8) a(7,9) a(8,9) a(7,11) a(8,12)
Optimization: -5
OPTIMUM FOUND

Models       : 6
  Optimum    : yes
Optimization : -5
Calls        : 1
Time         : 0.733s (Solving: 0.71s 1st Model: 0.00s Unsat: 0.71s)
CPU Time     : 0.730s

would you please write a little explanation?

Python 2 | 325 284 217 bytes
Try it online!
from itertools import*
N=input()
r=range(N*N)
for n in r:
 g=r
 for s in combinations(g,n):
    for p in s:g=filter(lambda q:all([abs(q%N-p%N)!=abs(q/N-p/N),q%N!=p%N,q/N!=p/N]),g)
    if len(g)>=n:break
    g=r
 else:exit(n-1)

Edit: Replaced tuples with integers in g and other trivial edits.
Edit2: Bytes down to 217 thanks to musicman523 and CalculatorFeline!

How it works
The program iterates over all possible positions of n queens and filters out non-peaceful points in g caused due to position of the queens. If the remaining points is greater than n then it means that it is possible to for n queen armies to stay peacefully. If for the next value of n, no peaceful situation is found, then the program exits with exit code : n-1, which is the answer.
In short, it is  brute force
The program can be made faster by changing the last two lines to
for n in range(N**2):
    if not z(n,N):print n-1;break

Tip: 1 space and 1 tab are different indentation levels in Python 2. Also, you can use from module import* to import everything from a module and save bytes.

Python 2 interpreter, 217 bytes

Haskell, 169 156 153 152 bytes
k!(a:b)=k!b++[a:c|c<-(k-1)!b]
k!x=[x|k==0]
q&l|p<-q![[x,y,x-y,x+y]|x<-l,y<-l]=or[all and$zipWith(/=)<$>b<*>w|b<-p,w<-p]
g n=last$filter(&[1..n])[0..n*n]

Defines a function g, may be further golfable.
Try it online!
On TIO, when compiled with -O2, this takes about 36 seconds for n = 4 and times out on n = 5.
The time complexity should be O(n24n2).
Explanation
We iterate over the possible values for the number of queens (q).
For each q, we generate all pairs of size-q subsets of [1..n]2, one set of black queens (b) and one of white queens (w).
Then, each element of b is checked against each element of w to see if they share a row, column, diagonal or anti-diagonal.
This also takes care of two pieces sharing the same coordinate.
The greatest value of q that admits a peaceable configuration is the final value.
The first two lines of the program define the function !, which computes the length-k subsequences of a list x.
The implementation is by a basic recursion: either choose the first element to be in the set or not and recurse to the tail, decrementing k if necessary.
Then the empty list or reached, check that k==0.
k!(a:b)=       -- ! on integer k and list with head a and tail b is
 k!b++         -- the concatenation of k!b and
 [a:c|         -- the list of lists a:c where
  c<-(k-1)!b]  -- c is drawn from (k-1)!b.
k!x=           -- If x doesn't have the form a:b (which means that it's empty),
 [x|           -- the result is a list containing x
  k==0]        -- but only if k==0.

The second auxiliary function & takes a number q (number of queens on either side) and a list l (the x-coordinates of the board, also used as the y-coordinates), and returns a Boolean value indicating if a peaceable configuration exists.
We first compute p, the list of length-q subsequences of the list of values [x,y,x-y,x+y], where x and y range over l.
They represent the row, column, diagonal and anti-diagonal of a square (x,y) on the board.
q&l               -- & on inputs q and l:
 |p<-             -- define p as
  q!              -- the q-subsequences of
  [[x,y,x-y,x+y]  -- the list of these 4-lists
   |x<-l,y<-l]    -- where x and y are drawn independently from l.

Next we have the result of q&l.
We draw two subsequences b and w from p, pair the 4-lists of them together in all possible ways, and check that they always differ in all 4 coordinates.
If some choices of b and w result in a truthy result, we return True.
=or            -- Does the following list contain a True:
 [all and$     -- every list contains only truthy values
  zipWith(/=)  -- if we zip with inequality
  <$>b<*>w     -- all elements of b and w in all possible ways,
 |b<-p,w<-p]   -- where b and w are drawn independently from p.

The last line is the main function.
Given n, it simply finds the largest possible value of q for which q&[1..n] is true.
g n=              -- g on input n is
 last$            -- the last of
 filter(&[1..n])  -- those values q for which q&[1..n] is true
 [0..n*n]         -- in this list.


text:
Quickly Prove Me Wrong!
Introduction
This is the evolution of this previous challenge which was about checking satisfieability of normal formulae in conjunctive normal form (CNF). However, this problem is NP-complete and watching algorithms finish is just boring, so we're gonna simplify the problem!
Specification
Input
You may tune the following input specification to optimally match your language as long as you don't encode additional information.
Your input will be a list of implications. Each implication has a list of variables on the left and a single variable on the right. Variables may be represented using your favorite representation (integer, strings, whatever), for the sake of this specification, characters will be used. The list on the left side may be empty and there may not be a variable on the right. The variable on the right side will not appear on the left side of the same implication.
Example input:
[A -> B; B -> A]
[A,B,C -> D; B,C -> E; -> A; B -> ]

Output
Your output will be a truthy or a falsy value.
What to do?
You need to determine whether the given formula is satisfieable and output truthy if it is satisfieable and falsy if not.
A,B -> C means that if A and B need to hold then C needs to hold as well.
-> C means that C always needs to hold (this is short-hand for True -> C).
A,B -> means that if A and B need to hold, so does falsum and thus there is a contradiction, thus if you find such an implication where A and B hold, you can immediately output falsy (this is short-hand for A,B -> False).
The list of implications all need to hold at the same time.
Because this problem is also known as HORNSAT, it is P-complete and to avoid trivial solutions to this, your solution must run in polynomial time and you must provide reasoning why your solution does so.
Who wins?
This is code-golf, thus the shortest solution in bytes wins! Standard rules apply.
Examples
with Explanation
[A,B -> C; C ->; -> A; A -> B] A needs to hold, thus B needs to hold, thus C needs to hold and thus you found a contradiction.
[A,B -> D; C ->; -> A; A -> B] A needs to hold, thus B needs to hold, thus D needs to hold, however C doesn't need to hold and thus this formula is satisfieable.
without Explanation
[A -> B; B -> A] => 1
[A,B,C -> D; B,C -> E; -> A; B -> ] => 1
[A,B -> C; C ->; -> A; A -> B] => 0
[A,B -> D; C ->; -> A; A -> B] => 1
[P -> ; -> S ; P -> R; Q -> U; R -> X; S -> Q; P,U -> ; Q,U -> W] => 1
[-> P; Q -> ; T -> R; P -> S; S -> T; T,P -> Q ] => 0

Alice, 45 bytes
/;;?dhE..';F>@.>F*.?oK
\'..zi;w!";-$"'!?n-$-/

Try it online!
Input is in the form A->B;B->A with no spaces.  Output is Jabberwocky if the formula is satisfiable, and nothing otherwise.
Explanation
This follows a standard template for programs that run entirely in ordinal mode.  Unwrapped, the program is:
';.diEw.";->".!Fn.$o;.?zh;.!';F$@'>?*-?-K

';.     Push a semicolon and duplicate it
d       Join these two semicolons into a single string and push it, without removing the originals
        This puts ";;" on top of the stack, with a ";" under it (and an irrelevant ";" under that)
i       Take input
E       Insert input between the only pair of characters in ";;"
w       Push return address (start main loop)
.       Duplicate current set of implications
";->"   Push this string
.!      Copy to tape (to get it again later with fewer bytes)
F       Check whether this string is in current set of implications
n       Negate result: "Jabberwocky" if no match, "" if match
.$o     Output this string if nonempty (no unit clauses remain)
;       Discard top of stack: if the previous command didn't output, this puts the implications back on the TOS
        If the previous command did output, this discards the implications and puts ";" on the TOS
.       Duplicate
?z      Remove everything up to and including the first ";->"
h;      Take first character of remaining string: this is the literal in the first unit clause,
        or ";" if the clause is simply "->" (or if "Jabberwocky" was output earlier)
.!      Copy to tape, since we will need it later
';F     Check whether this character contains (i.e., is) a semicolon
$@      If so, terminate
        (Replace "A" in the next two lines with the actual value of the literal in this unit clause)
'>?*-   Remove all instances of ">A"; this destroys all clauses that imply A
?-      Remove all instances of "A"
K       Return to start of main loop

Each command in the main loop takes polynomial time, and each iteration of the loop either terminates the program or destroys at least one clause.  Hence, the entire program runs in polynomial time.

Python 2, 312 244, 243 bytes
from sympy import*;s=input()
l=' ||,|&|;->|;1>>|[->|[1>>|->;|>>0;|->]|>>0]|;|)&(|->|>>|[|(|]|)|(|((|>>|)>>'.split('|')
for i in zip(l[::2],l[1::2]):s=s.replace(*i)
for i in range(65,91):y=chr(i);vars()[y]=Symbol(y)
print satisfiable(eval(s))>0

Try it online!
Some explications The input is converted to the appropriate format of sympy module, then verifying satisfiability.
Is it time-polynomial?
I performed a set of experimental tests that shows that the algorithm is linear. Randomly, I took N implications, with N in [1..1000], over a number of variables between 1 and 26. After that I do one thousand of satisfiability test for each N. Finally I plot the average in millisecond.

Does this run in polynomial time? Ie does sympy detect the horn structure and applies an appropriate polynomial time algorithm?

Some more bytes off

@ovs plz feel free to edit and update the code :)

@SEJPM It seems from the experimental tests that I performed that the algorithm is linear.

It only does so because it does unit propagation before it's starting to guess.

APL, 49 bytes
{×∧/∨/¨≢¨¨{(2⊃¨⍵/⍨0=≢¨⊃¨⍵)∘{x y←⍵⋄(x~⍺)y}¨⍵}⍣≡⊢⍵}

This function takes an array of implications, where each implication is a 2-element
array, with the first element containing the variables before the arrow and the second containing the variable after the arrow if there is one.
E.g. [A,B,C -> D; B,C -> E; -> A; B -> ] is represented as:
('ABC' 'D')('BC' 'E')('' 'A')('B' '')

The elements need not be letters but could be anything as long as they can be compared.
Explanation:

{...}⍣≡⊢⍵: run the following function on the input until a fixpoint is found

(...)∘: Find the current units:

⊃¨⍵: For each implication in the input, take the first element
0=≢¨: See which are empty
⍵/⍨: Select those implications
2⊃¨: Select the second element from each

{...}¨⍵: For each implication, given the units:

x y←⍵: unpack the implication into its first and second component
(x~⍺)y: remove the previous units from the first component and leave the second one alone

≢¨¨: find the length of each inner element. If the clause is unsatisfiable, there is at least one (0,0) element (i.e. [] -> [], True → False).
∨/¨: for each implication, find the GCD of the lengths of its parts. If unsatisfiable, this will be 0.
∧/: find the LCM of all the GCDs. If unsatisfiable, this will be 0.
×: return the sign, so a boolean value is returned (0 for unsatisfiable, 1 for satisfiable).

Polynomiality proof:
The main loop ({...}⍣≡) will run until there are no more reducible implications. Each step, all current known facts are removed from the left hand side of each implication. Because each implication can only have 0 or 1 variables on its right hand side, the size of the set of knowable facts is bounded by the amount of implications, meaning the loop will run at most n times.
The main loop further contains a number of maps over the list of implications, meaning the total running time is O(n^2).
Link to tests cases being run on tio.run.

JavaScript (Node.js), 69 bytes
f=x=>x.some(t=>t.a.every(v=>x[~v])&!x[~t.b]&&[x[~t.b]=1])?f(x):!x[~0]

Try it online!
Flow each true and check if false is true

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


text:
Find the numbers coprime to their decimal digits
Two numbers are coprime if their greatest common divisor is 1.
Given a positive integer N, your task is to compute the first N terms of OEIS A061116, which is the sequence of positive integers higher than 1 that are coprime to all their decimal digits.
Here are the first few terms of the sequence:
11, 13, 17, 19, 21, 23, 27, 29, 31, 37, 41, 43, 47, 49, 51, 53, 57, 59, 61, 67, 71

You can assume that N < 200.

Test Cases

Input -> Output

1 -> 11
3 -> 11, 13, 17
6 -> 11, 13, 17, 19, 21, 23
25 -> 11, 13, 17, 19, 21, 23, 27, 29, 31, 37, 41, 43, 47, 49, 51, 53, 57, 59, 61, 67, 71, 73, 79, 81, 83

You may output in any decent form (as a list, with a separator or whatever else). You can take input as the String representation of N or as an integer. Standard I/O rules apply.

Default Loopholes apply. This is code-golf, so the shortest code in bytes wins!

Aw. can't this be a 'check if it's part of the sequence' :P

Also, why exclude 1? :|

@Okx That would be kind of trivial.

I need to finish my builtins so I can actually compete in these

@MartinEnder Because it is not in the OEIS sequence... Do you think I should include it?

Sorry If I will respond questions very late, but I will probably be offline for quite a long time

Plain English 853 787 738 594 550 538 532 bytes
Removed 66 bytes of white space.  Removed 49 bytes by using a more generic output type.  Removed 144 bytes by abbreviating variable names, and reusing the quotient and the remainder.  Removed 44 bytes by abbreviating an interface.  Shortened Destroy the number things. to Destroy the L.  Removed 6 bytes by changing "some" to "a", and "number" to "count".
Golfed code:
To create a L number things given a c count:
Put 0 in a i count.
Loop.
Add 1 to a n count.
If the i is at least the c, exit.
If the n is g,
append the n to the L;
add 1 to the i.
Repeat.
To decide if a n count is g:
If the n is at most 10, say no.
Put 1 in a m count.
Loop.
If the m is greater than the n, say yes.
Divide the n by the m giving a q quotient and a r remainder.
Divide the q by 10 giving the q and the r.
Get a gcd given the n and the r.
If the gcd is at least 2, say no.
Multiply the m by 10.
Repeat.

Ungolfed code:
Some special numbers are some number things.

To create some special numbers given a count:
  Put 0 in another count.
  Loop.
    Add 1 to a number.
    If the other count is at least the count, exit.
    If the number is coprime with its digits,
      Append the number to the special numbers;
      Add 1 to the other count.
  Repeat.

To decide if a number is coprime with its digits:
  If the number is at most 10, say no.
  Put 1 in another number.
  Loop.
    If the other number is greater than the number, say yes.
    Divide the number by the other number giving a quotient and a remainder.
    Divide the quotient by 10 giving another quotient and another remainder.
    Get a gcd given the number and the other remainder.
    If the gcd is greater than 1, say no.
    Multiply the other number by 10.
  Repeat.

"Some number things" are a doubly-linked list of numbers.
The calling code has the responsibility to Destroy the special numbers., so I have added the corresponding bytes.
The Plain English IDE is available at github.com/Folds/english.  The IDE runs on Windows.  It compiles to 32-bit x86 code.

Jelly, 10, 8 bytes
gQỊẠ
2Ç#

Try it online!
2 bytes saved thanks to @Dennis!
Explanation:
        # Helper link: Is it in the sequence at all?
   Ạ    # All of...
g       # The GCDs of A and...
 Q      # The unique digits of A
  Ị     # Are less than or equal to 1
        #
        # Main link:
  #     # The first *n* truthy results of
 Ç      # The last link
2       # Starting at 2

Jelly is damn slick.

You can golf a byte off with the new(ish) updates: Try it online!

Perl 6, 39 bytes
{(grep {$_ gcd.comb.all==1},2..*)[^$_]}

Try it online!

Mathematica, 80 70 64 bytes
For[t=2;n=#,n>0,t++,Max[t~GCD~IntegerDigits@t]<2&&Print@t&&n--]&

Try it online!
-10 bytes thanx to @MartinEnder
-6 bytes from  @JungHwan Min

Haskell, 64 59 58 57 51 bytes
Saved a total of 6 bytes thanks to @Laikoni and @Ørjan Johansen
(`take`[x|x<-[2..],and[x`gcd`read[c]<2|c<-show x]])

Try it online!

53 bytes: Try it online!

51 bytes with @Laikoni 's improvements + an inner list comprehension: Try it online!

Thanks, I don't often think of using `...`

Haskell, 115 bytes
q n=take n(filter(\x->1==(maximum$map(x%)(d x)))[11,13..])
d 0=[]
d x=mod(x)10:(d(x`quot`10))
x%0=x
x%y=y%(x`mod`y)

Husk, 11 bytes
↑tfȯεΠṠM⌋dN

Try it online!

i. am. speed....

JavaScript (ES6), 93 bytes
f=(n,k=11,g=(a,b)=>b?g(b,a%b):a)=>n?[...''+k].some(d=>g(k,d)>1)?f(n,k+1):[k,...f(n-1,k+1)]:[]

PHP, 120 bytes
for($n=2;!$r[$argn-1];$t?:$r[]=$n,$n++)for($t=$i=0;~$s=("$n")[$i++];$t|=$d)for($d=$s?:$t|=1;$s%$d|$n%$d--;);print_r($r);

Try it online!

Japt, 10 bytes
Èì ejX}jUB

Try it

Husk, 14 bytes
↑tfλΛȯεnḊ¹Ḋd)N

Try it online!
Explanation
↑tfλΛȯεnḊ¹Ḋd)N
  fλ        )N filter all natural numbers by the following lambda:
    Λȯ     d   map each digit of the natural number, and check if all are truthy:
        Ḋ¹Ḋ    divisors of the digit and divisors of the argument
       n       set intersection
      ε        has length 1? (co primality check)
 t             remove the first element
↑              take n items from the sequence(n → input)


text:
Is it a super-prime?
Background
A super-prime is a prime number whose index in the list of all primes is also prime. The sequence looks like this:

3, 5, 11, 17, 31, 41, 59, 67, 83, 109, 127, 157, 179, 191, ...

This is sequence A006450 in the OEIS.
Challenge
Given a positive integer, determine whether it is a super-prime.
Test Cases

2: false
3: true
4: false
5: true
7: false
11: true
13: false
17: true
709: true
851: false
991: true

Scoring
This is code-golf, so the shortest answer in each language wins.

What is the index of 2? Is it 1 or 0?

@Dennis the sequence is 1-indexed; the index of 2 is 1.

First thought after reading what a super-prime is: What would you call super-super-primes? Or super^3-primes? What is bigger, the number of atoms in the universe or the 11th super^11-prime? You, dear internet person, are stealing another few hours of my hours of my prime time!

@J_F_B_M Make a challenge based on it! :D

It's a bird!  It's a plane!  It's Super-Prime!

@J_F_B_M 11 is a super-prime who's index in the super-prime list is also a super-prime (3), so the 11'th super-prime is a super-super-super-prime

435748987787 happens to be the 11th super^11-prime, for anyone interested.

Jelly, 5 bytes
ÆRÆNċ

Try it online!
How it works
ÆRÆNċ  Main link. Argument: n

ÆR     Prime range; yield the array of all primes up to n.
  ÆN   N-th prime; for each p in the result, yield the p-th prime.
    ċ  Count the occurrences of n.

Gosh darn it, you win again...

He always does...

@ETHproductions Well, solution is pretty obvious...it's just the ninja here.

Mathematica, 26 23 bytes
Thanks to user202729 for saving 3 bytes.
PrimeQ/@(#&&PrimePi@#)&

This makes use of the fact that Mathematica leaves most nonsensical expressions unevaluated (in this case, the logical And of two numbers) and Map can be applied to any expression, not just lists. So we compute the And of the input and its prime index, which just remains like that, and then we Map the primality test over this expression which turns the two operands of the And into booleans, such that the And can then be evaluated.

23 bytes: PrimeQ/@(#&&PrimePi@#)&.

@user202729 Nice, thank you. :)

Japt, 13 11 bytes
õ fj bU Ä j

Test it online!
Explanation
This is actually very straight-forward, unlike my original submission:
 õ fj bU Ä  j
Uõ fj bU +1 j    Ungolfed
                 Implicit: U = input integer
Uõ               Generate the range [1..U].
   fj            Take only the items that are prime.
      bU         Take the (0-indexed) index of U in this list (-1 if it doesn't exist).
         +1 j    Add 1 and check for primality.
                 This is true iff U is at a prime index in the infinite list of primes.
                 Implicit: output result of last expression

Jelly, 6 bytes
ÆRi³ÆP

Try it online!
Uses the same technique as my Japt answer: Generate the primes up to n, get the index of n in that list, and check that for primality. If n itself is not prime, the index is 0, which is also not prime, so 0 is returned anyway.

Regex (Perl / PCRE), 55 54 53 bytes
^(?=((?=((\2x*?|^)((?!(xx+)\5+$)))xx)x)*(x*))\6(?4)xx

Try it online! - Perl
Try it online! - PCRE
Takes its input in unary, as a string of x characters whose length represents the number. Based on Prime counting function.
^       # tail = N = input value
(?=
    # Calculate π(N) = the number of primes <= N, by counting
    # from the largest to the smallest prime.
    (       # J = 0
        (?=
            # \2 starts at zero, and on each subsequent iteration, contains the
            # difference N-P-(J-1) where P is the previously found prime, and J
            # is the running total of our prime count.
            (
                (
                    \2           # Start from the previous value of \2. This
                                 # will make tail = P-1, where P is the
                                 # previously found prime.
                    x*?          # Advance as little as necessary to make the
                                 # following match, and add this to \2, while
                                 # subtracting it from tail.
                |        # or
                    ^            # Don't advance at all on the first iteration
                                 # (when \2 is is still unset), so as to assert
                                 # that N is not composite.
                )
                ((?!(xx+)\5+$))  # Define and use subroutine (?4): Assert tail
                                 # is prime. Note that this needs to be inside
                                 # group \2 for it to work in PCRE1 and older
                                 # versions of PCRE2, which atomicize groups
                                 # that have nested backreferences.
            )
            xx                   # Assert tail is prime by eliminating the
                                 # false positives 0, 1
        )
        x   # J += 1; tail -= 1
    )*      # Iterate zero or more times, until there are no smaller primes
            # remaining.
    # At this point, head = π(N), and tail = N - π(N)
    (x*)    # \6 = tail = N - head = tool to make tail = head
)
\6          # tail = π(N)
(?4)xx      # Assert tail is prime

Alternative 55 54 53 bytes:
^(?=((?=((\2x*?|^)((?!(xx+)\5+$|x?$))))x)*(x*))\6(?4)

Try it online! - Perl
Try it online! - PCRE
This eliminates the false negatives \$0\$ and \$1\$ in the definition of the primality subroutine instead of patching its second and third individual uses.
Regex (.NET), 70 60 58 bytes
^(?=(\3*?(?!(xx+)\2+$)(x))*x)(?<-3>x){2,}(?<!\3|^\4+(x+x))

Try it online!
This uses the .NET feature of balanced groups to do the prime counting. Since .NET regex has no subroutines, this has three two copies of the primality test.
^                      # tail = N = input value
# Calculate π(N) = the number of primes <= N, by counting
# from the largest to the smallest prime.
(?=                    # Atomic lookahead - lock in this match once it completes
    (
        \3*?           # Advance as little as necessary to make the following
                       # match, but don't advance at all on the first iteration
                       # (when \3 is is still unset), so as to assert that N is
                       # not composite.
        (?!(xx+)\2+$)  # Assert tail is not composite
        (x)            # Eliminate the false primality positive of 0, and advance
                       # forward so that the next prime can be found (if we didn't
                       # do this, the regex engine would exit the loop due to a
                       # zero-width match); \3 = 1, to signal the first iteration
                       # has been done, and push a capture onto the Group 3 stack.
    )*                 # Loop as many times as can be done until its stops
                       # matching.
    x                  # Eliminate the false primality positive of 1
)
(?<-3>x){2,}           # Pop all Group 3 captures off the stack, asserting that
                       # the count is ≥ 2, and doing head += 1 for each one. Since
                       # this isn't done atomically, we need to subsequently
                       # verify that all captures were popped, due to backtracking
                       # if the following assertion fails.
(?<!\3|^\4+(x+x))      # Assert that the Group 3 capture stack is empty, and that
                       # head is not composite (and since it's already been
                       # forced to be ≥ 2, this asserts it to be prime).

Regex (Perl / Java / PCRE / .NET), 60 bytes
^(?=((?=((\2x*?|^)(?!(xx+)\4+$))xx)x)*(x*))\5(?!(xx+)\6+$)xx

Try it online! - Perl
Try it online! - Java
Try it online! - PCRE
Try it online! - .NET
This is a straight port of the Perl/PCRE version, to regex engines that lack subroutine calls but support nested backreferences. The subroutine call has been replaced with a copy of the routine.
Regex (Perl / PCRE / Pythonregex), 61 bytes
^(?=((?=((\6x*?|^)((?!(xx+)\5+$)))xx)(?=(\2))x)*(x*))\7(?4)xx

Try it online! - Perl
Try it online! - PCRE
Try it online! - Python import regex
This is a port of the Perl/PCRE version. \2 is copied into \6 using the lookahead (?=(\2)), since Python (even with import regex) lacks nested backreferences.
Regex (PCRE / Ruby), 62 bytes
^(?=((?=((\6x*?|^)((?!(xx+)\5+$)))xx)(?=(\2))x)*(x*))\7\g<4>xx

Try it online! - PCRE
Try it online! - Ruby
This is a straight port of the Pythonregex version, to Ruby's subroutine call syntax.
Regex (Perl / Java / PCRE / Pythonregex / Ruby / .NET), 68 bytes
^(?=((?=((\5x*?|^)(?!(xx+)\4+$))xx)(?=(\2))x)*(x*))\6(?!(xx+)\7+$)xx

Try it online! - Perl
Try it online! - Java
Try it online! - PCRE
Try it online! - Python import regex
Try it online! - Ruby
Try it online! - .NET
To be portable to all 6 regex engines, this uses neither nested backreferences nor subroutine calls.

Python 3, 104 97 93 bytes
p=lambda m:(m>1)*all(m%x for x in range(2,m))
f=lambda n:p(n)*p(len([*filter(p,range(n+1))]))

Returns 0/1, at most 4 bytes longer if it has to be True/False.
Try it online!

0/1 is fine. Nice answer! Since you don't ever use the value of f, you can reformat your code like this and exclude it from the byte count.

@musicman523 Thanks for the tip!

Python 2, 79 bytes
n=input()
s={2};p=i=1
while i<n:
 p*=i;i+=1
 if p*p%i:s|={i}
print{n,len(s)}<=s

Try it online!

Jelly, 7 bytes
ÆCÆPaÆP

Try it online!
ÆC counts the number of primes less than or equal to the input (so, if the input is the nth prime, it returns n). Then ÆP tests this index for primality. Finally, a does a logical AND between this result and ÆP (primality test) of the original input.

Haskell, 62 bytes
p x=2==sum[1|0<-mod x<$>[1..x]]
f x=p$sum[1|y<-[1..x],p y,p x]

Try it online! Usage: f 991 yields True.

Husk, 2 bytes
ṗṗ

Try it online!
One of the cases when the behaviours of functions returning non booleans is really helpful.
user's solution.
Husk, 4 bytes
ṗ£İp

Try it online! or Verify all test cases

2 or 3 bytes?

@user yep, 2 bytes.

@user You don't need the trailing ⁰ due to implicit input, plus, putting it on a seperate line just declares it as a new function, which doesn't affect the first line

Pyth, 12 bytes
&P_QP_smP_dS

Try it online!
Explanation
&P_QP_smP_dS
                Implicit input
       mP_dS    Primality of all numbers from 1 to N
      s         Sum of terms (equal to number of primes ≤ N)
    P_          Are both that number
&P_Q            and N prime?

Mathematica, 35 29 bytes
P=Prime;!P@P@Range@#~FreeQ~#&

-6 bytes from @MartinEnder

P@P@Range@# should save a bunch.

05AB1E, 6 bytes
ÝØ<Øså

Try it online!
Explanation
ÝØ<Øså
Ý      # Push range from 0 to input
 Ø     # Push nth prime number (vectorized over the array)
  <    # Decrement each element by one (vectorized)
   Ø   # Push nth prime number again
    s  # swap top items of stack (gets input)
     å # Is the input in the list?

Nice, almost the same as the answer I just came up with. Also, ÅP can be used instead of ÝØ (not that it saves any bytes, but hey, it's a built-in that does the trick).

Pyke, 8 bytes
sI~p>@hs

Try it here!
s        -  is_prime(input)
 I~p>@hs - if ^:
  ~p>    -    first_n_primes(input)
     @   -    ^.index(input)
      h  -   ^+1
       s -  is_prime(^)

Raku, 46 35 bytes
{$/=&is-prime;all($_∈*,$/)([grep $/,1..$_])}
grep {.is-prime&&is-prime ++$},^∞

Try it online!
Six years of golfing experience let me cut down on this solution considerably.

Python 2, 89 bytes
def a(n):
 r=[2];x=2
 while x<n:x+=1;r+=[x]*all(x%i for i in r)
 return{n,len(r)}<=set(r)

Try it online!
Constructs r, the list of primes <= n; if n is prime, then n is the len(r)'th prime. So n is a super prime iff n in r and len(r) in r.

Factor + math.primes, 51 49 36 32 bytes
Saved 13 bytes thanks to @Bubbler!
Saved 4 bytes thanks to @chunes!
[ dup nprimes index ?1+ prime? ]

Try it online!
[ dup nprimes index ?1+ prime? ]
  dup nprimes                    ! First n primes (generates extra primes)
              index              ! Find the index of the input in that
                                 ! when the index is not found, an f is outputted
                                 ! If the index exists,
                    ?1+          ! If it's a number, increment
                                 ! If it's f, output 0 (which is not prime)
                        prime?   ! Is that prime?

You can simplify it to [ dup primes-upto index ?1+ prime? ]. ?1+ increments an integer or consumes an f and gives 0.

You can save 4 bytes by using nprimes instead of primes-upto. It's less efficient of course, but small price to pay.

Vyxal g, 4 bytes
¡†"æ

Try it Online! - test cases only
This is the same as the 5 byte answer below except the minimum is taken by the g flag rather than a g element.
Vyxal, 5 bytes
¡†"æg

Try it Online!
Try it Online! - test cases only
This makes use of Prime counting function, based on Dennis's 05AB1E solution to that challenge. This is actually much faster than the other two 5 byte solutions presented below it.
¡  # Factorial
†  # Number of distinct prime factors – when applied to the factorial, this
   # gives the index of the greatest prime ≤ the input number (1-indexed).
"  # Wrap the top two items (the input number, and the above result) in a list.
æ  # Is the number prime? (Vectorized)
g  # Minimum - effectively applies a boolean AND to the list

Alternative 5 bytes:
Þpḟ›æ

Try it Online!
Try it Online! - test cases only
Þp  # An infinite list of primes
ḟ   # Index of input number in that list (0-indexed; -1 if not found)
›   # Add 1
æ   # Is the number prime?

Another alternative 5 bytes:
Þp‹ǎc

Try it Online!
Try it Online! - test cases only
Port of Datboi's 05AB1E solution. This is much slower than the primary 5 byte solution above, but much faster than its 05AB1E counterpart.
Þp # An infinite list of primes
‹  # Subtract 1 from every item on the list
ǎ  # Nth prime - vectorized to the entire list
c  # Contains - Is the input number a member of that list?

Thunno D, \$ 8 \log_{256}(96) \approx \$ 6.58 bytes
FAFLZPNP

Attempt This Online!
Port of Deadcode's Vyxal answer.
It's all uppercase letters!
Explanation
FAFLZPNP  # Implicit input
F         # Factorial
 AF       # Unique prime factors
   L      # Length
    ZP    # Pair
      N   # Is prime
       P  # Product
          # Implicit output

QBIC, 33 bytes
~µ:||\_x0]{p=p-µq|~q=a|_xµp]q=q+1

Explanation
~   |   IF   ....  THEN (do nothing)
  :         the number 'a' (read from cmd line)
 µ |        is Prime
\_x0        ELSE (non-primes) quit, printing 0
]           END IF
{           DO
            In this next bit, q is raised by 1 every loop, and tested for primality.
            p keeps track of how may primes we've seen (but does so negatively)
    µq|     test q for primality (-1 if so, 0 if not)
p=p-        and subtract that result from p (at the start of QBIC: q = 1, p = 0)
~q=a|       IF q == a
_xµp        QUIT, and print the prime-test over p (note that -3 is as prime as 3 is)
]           END IF
q=q+1       Reaise q and run again.

Haskell, 121 bytes
f=filter
p x=2==(length$f(\a->mod(x)a==0)[1..x])
s=map(\(_,x)->x)$f(\(x,_)->p x)$zip[1..]$f(p)[2..]
r x=x`elem`(take x s)

(\(_,x)->x) is snd, (\(x,_)->p x) is (p.fst). Both fst and snd are in Prelude, so no need for imports.

Don't use backticks too often: r x=elem x$take x s. However, in this case you can go pointfree (introducing backticks again) and omit the function name: elem<*>(`take`s).

Positron, 148 bytes
x=#(input@@)a=function{p=1;k=$1==2;f=2;while(f<$1)do{p=p*$1%f;k=1;f=f+1};return p*k}r=1;i=2;while(i<x)do{if(a@i)then{r=r+1}i=i+1}print@((a@x*a@r)>0)

Try it online!

Pari/GP, 31 bytes
n->(p=isprime)(n)*p(primepi(n))

Try it online!

Matlab, 36 34 bytes
Saved 2 bytes thanks to Tom Carpenter.
A very naive implementation using built-in functions:
isprime(x)&isprime(nzz(primes(x)))

For Octave only you can also save a further byte with (p=@isprime)(x)&p(nnz(primes(x)))

Julia 0.6, 61 bytes
return 1 if x is a super-prime, 0 otherwise.
without using an isprime-kind function.
x->a=[0,1];for i=3:x push!(a,0∉i%(2:i-1))end;a[sum(a)]&a[x]

Japt, 11 bytes
ÒÈj}jU bU)j

Try it

Pyth, 9 bytes
P_hx.fP_Z

Test suite
Uses a fairly different approach to the existing Pyth solution. Returns True for super-primes, False for non-super-primes, and [] (falsy) for composite numbers.

Alternate TIO test suite

Ruby, 72 bytes
Tired of all the extremely obscure golfing languages in this thread? Here's the practical language solution you're looking for! Let me know if you see a way to shave off a few bytes.
require'prime';n=gets.to_i;p n.prime?&&(Prime.take(n).index(n)+1).prime?

Try it online!

05AB1E, 6 bytes
.Ø>‚pß

Try it online! - 05AB1E
Try it online! - 05AB1E - test cases only
Try it online! - 05AB1E (legacy) - test cases only
Equal in length to Datboi's solution, but much faster on numbers that are not super-prime.
.Ø  # Get 0-indexed number of the greatest prime ≤ input number
>   # Add 1
‚   # Wrap the top two items (the input number, and the above result) in a list
p   # Is the number prime? (Vectorized)
ß   # Minimum - effectively applies a boolean AND to the list

Alternative 6 bytes:
!fg‚pß

Try it online!
Try it online! - test cases only
This makes use of Dennis's Prime counting function solution, which is equal in length to (but slower than) the ones using built-in prime-counting functions.

C89 (clang), 92 bytes
#define s for(i=e;--i&&e%i;)p+=i <3
p,r,i;m(e){s;for(p=r=i==e%2;--e;)s;e=p+1;s;return r<i<r;}

(added whitespace for readability)
Some alternatives:

i==e%2 \$\equiv\$ i==1&e
r<i<r \$\equiv\$ 1<i<r \$\equiv\$ i<2&r \$\equiv\$ i/2<r \$\equiv\$ i<r+r \$\equiv\$ i<2*r

Try it online!

J, 13 bytes
e.p:@<:@p:@i.

Same idea as 05AB1E, Vyxal, and kind of Factor. Reminder (f g) y → y f g y.
Attempt This Online!
e.p:@<:@p:@i.
           i.  NB. range 0..y
        p:@    NB. then get nth prime, vectorized
     <:@       NB. then decrement each
  p:@          NB. then get primes again
e.             NB. is y a member of

Pyt, 5 bytes
Đřᵽᵽ∈

Try it online!
Đ            implicit input; Đuplicate
 ř           řangify [1,2,...,n]
  ᵽ          get ᵽrimes with given indices
   ᵽ         get ᵽrimes with given indices
    ∈        is input in the resulting array?; implicit print

Regex (.NET), 57 bytes
^(?=((?!(xx+)\2+$)(x+?))+x$)(?<-3>x){2,}(?<!\3|^\4+(x+x))

Try it online!
This uses the .NET feature of balanced groups to do the prime counting, saving 3 bytes relative to the shortest version that doesn't use this feature and is still .NET-compatible. Since .NET regex has no subroutines, this has two copies of the primality test.
It is based on my 58 byte .NET regex answer. Shown side-by-side with it:
^(?=(\3*?(?!(xx+)\2+$)(x))*x)(?<-3>x){2,}(?<!\3|^\4+(x+x))
^(?=((?!(xx+)\2+$)(x+?))+x$)(?<-3>x){2,}(?<!\3|^\4+(x+x))

This -1 byte golf relies on a mathematical conjecture, which is extremely likely to be true, but as far I can tell has not been proven: that \$g(n)≤n\$ always, where \$g(n)\$ is the \$1\$-indexed \$n\$th prime gap, i.e. OEIS A001223. For this reason I'm posting it as a separate answer, as the existing answer is already quite long and diluted with answers for other regex engines.
For this regex to fail, there would need to be a counterexample \$g(p)>p\$ where \$p\$ is prime. This would give the regex false positives for the \$\{p+1\}\$th prime and every subsequent prime.
It is known to hold true at least up to \$n=423,731,791,997,205,041\$, with \$g(n)=1,550\$ of course being far less than \$n\$. The prime is \$p_n=18,361,375,334,787,046,697\$, which is of course far too large for any conventional regex engine to match in unary, but theoretical accuracy up to infinity is the goal here.
^                      # tail = N = input value
# Calculate π(N) = the number of primes <= N, by counting
# from the largest to the smallest prime.
(?=                    # Atomic lookahead - lock in this match once it completes
    (
        (?!(xx+)\2+$)  # Assert tail is not composite; since this is done at the
                       # beginning of the loop, it also asserts N is not composite
                       # on the first iteration.
        (x+?)          # Eliminate the false primality positive of 0, and advance
                       # forward as little as necessary to make the next iteration
                       # match the next prime; push a capture onto the Group 3
                       # stack (containing the Kth prime gap, counting down from
                       # K=π(N) to K=1, such that by the time this loop finishes,
                       # on the top of the stack will be the value 1, and below
                       # that, the first prime gap, which is also 1).
    )+                 # Loop at least once, and as many times as can be done
                       # until it stops matching.
    x                  # Assert that tail == 1, to force the above loop to keep
                       # finding subsequent smaller primes (instead of exiting
                       # after finding only one prime) until the smallest prime,
                       # 2, is reached.
)
(?<-3>x){2,}   # Pop all Group 3 captures off the stack, asserting that the count
               # is ≥ 2 (to eliminate the non-composite numbers 0 and 1 from being
               # falsely identified as prime), and doing head += 1 for each one.
               # Since this isn't done atomically, we need to subsequently verify
               # that all captures were popped, due to backtracking if the
               # following assertion fails.
(?<!
    \3         # Assert that the Group 3 capture stack is empty. Note that this
               # will only work up to infinity if the Kth prime gap is always less
               # than or equal to K, i.e. that in OEIS A001223, a(K) ≤ K up to
               # infinity. This is because if the below alternative matches, due
               # to N being prime but not super-prime, it will cause the negative
               # lookbehind to fail to match, causing the regex engine to
               # backtrack into the "(?<-3>x){2,}" loop above, which at each step
               # will subtract 1 from head, and restore a prime gap onto the top
               # of the stack, starting with the last one. This will never reach
               # the point of restoring either of the bottom two stack values
               # (which are 1, 1) due to the "{2,}" constraint, which is good
               # because the bottom-most one would compare 1 against 0, which is
               # not less than or equal and would prevent this golf from working.
               #
               # Thus if there is any counterexample where a(P) > P, such that P
               # is prime, this would cause \3 to fail to match with a non-empty
               # capture stack (whereas it's intended only to fail to match due to
               # the stack being empty and \3 being unset), and then the below
               # alternative would be tried, also failing to match due to P being
               # prime, resulting in the negative lookbehind matching, resulting
               # in a false positive for the {P+1}th prime and every subsequent
               # prime.
|
    ^\4+(x+x)  # Assert that head is not composite (and since it's already
               # been forced to be ≥ 2, this asserts it to be prime).
)

Nekomata + -e, 3 bytes
QƥQ

Attempt This Online!
QƥQ
Q       Check if the input is a prime
 ƥ      Count number of primes <= input
  Q     Check if the result is a prime