text:
Unlock your Lock
You have locked your bike with a combination lock of 3 digits. Now you want to go for a ride and need to unlock it with the help of following program.
Input
1st parameter
The digit combination of your lock in locked state. It must be different from the 2nd parameter (=the combination of unlocked state). (Or else your bike could be stolen!)
Range 000..999. Leading zeros must not be omitted.
2nd parameter
The digit combination of your lock in unlocked state. This value is your goal.
Range 000..999. Leading zeros must not be omitted.
Output
A list of each state of the combination lock after each "rotation" including the initial state (which is always the 1st parameter) and the last step (which is always the 2nd paramater).
Algorithm
You start "rotating" the first digit one by one until you reach the correct digit in unlocked state. But, because you are in knowledge of the whole unlock-code, you rotate the digit in the direction in which you need the smallest amount of rotations to reach the digit in unlocked state. In case of a tie you can choose whatever direction you prefer.
When you have reached the correct first digit, you start the same procedure with the 2nd and then with the 3rd.
The order of digits is to understand as a circle:
... 9 0 1 2 3 4 5 6 7 8 9 0 1 2 ...
This means, that the smallest amount of rotations from 1 to 9 is not
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 = 8
but
1 -> 0 -> 9 = 2.
Notes

You can rely on Default I/O rules
You can change the order of the parameters.

Examples
Example 1, correct
Input: 999 001

Output:
999
099
009
000
001

Example 2, correct
Input: 000 292

Output:
000
100
200
290
291
292

Example 3, wrong output
Input: 999 121

Wrong output:
999
899 // Wrong because wrong rotation direction.
799
699
...

Correct output:
999
099
199
109
119
129
120
121

Example 4, wrong input
Input: 1 212 // Wrong because no leading zeros.

This is code-golf the shortest answer wins.

May I change the order of two parameters?

May we update the digits in any order as long as it's optimal?

@Arnauld No because I unlock my lock one by one :)

Can we print same step more than once? For example: "999 099 099 089 ..."

@Night2 No, since the program should simulate the "unlocking process" of a combination look.

Related

Do we have to print the first iteration of the lock?

@EmbodimentofIgnorance yes

You should provide an example where at least one of the digits needs to be rotated down to go the correct direction.

@GregMartin Done

Python 2, 113 107 105 99 95 bytes
a,b=input()
i=0
print a
for x in a:
 while x-b[i]:a[i]=x=(x+(x-b[i])%10/5*2-1)%10;print a
 i+=1

Try it online!
Takes input as lists of integers

Saved:

-6 bytes, thanks to Joel
-4 bytes, thanks to Jitse

99 bytes using a different way to calculate.

96 bytes - bonus: works for any array size

95 bytes - since you are using Python 2, might as wel lose the //

Jelly, 15 bytes
_æ%5ḣT$ṂṠ⁸_%⁵ðƬ

A dyadic Link accepting the start-code on the left and the target-code on the right as lists of integers (in \$[0,9]\$, lengths equal but otherwise arbitrary) which yields a list of lists of the codes from start-code to target-code.
Try it online!
How?
_æ%5ḣT$ṂṠ⁸_%⁵ðƬ - Link: list of integers, s; list of integers, t
              Ƭ - collect up values until a fixed point is reached applying:
             ð  -   the dyadic chain:  (i.e. f(x, t) where x starts off as s)
_               -     subtract (t from x) (vectorises) - i.e. [ta-xa, tb-xb, tc-xc]
   5            -     literal five
 æ%             -     symmetric modulo (vectorises) - i.e. [[-4..5][ta-xa], [-4..5][tb-xb], [-4..5][tc-xc]]
      $         -     last two links as a monad:
     T          -       truthy indices  - e.g. [0,-4,1]->[2,3]
    ḣ           -       head to index (vectorises)       [[0,-4],[0,-4,1]]
       Ṃ        -     minimum                            [0,-4]
        Ṡ       -     sign (vectorises)                  [0,-1]
         ⁸      -     chain's left argument (x)
          _     -     subtract (vectorises) - i.e. move the single spindle one in the chosen direction
            ⁵   -     literal ten
           %    -     modulo (since 9+1=10 not 0)

JavaScript (ES6),  73 72  70 bytes
Saved 2 bytes thanks to @tsh
Takes input as 2 arrays of digits in curried syntax (a)(b). Returns a string.
a=>g=b=>b.some(x=>d=x-(a[++i]%=10),i=-1)?a+`
`+g(b,a[i]+=d/5<5/d||9):b

Try it online!
Commented
a =>                  // a[] = initial combination
g = b =>              // b[] = target combination
  b.some(x =>         // for each digit x in b[]:
    d =               //   compute the difference d:
      x -             //     between x
      (a[++i] %= 10), //     and the corresponding digit in a[]
                      //     we apply a mod 10, because it may have exceed 9
                      //     during the previous iteration
    i = -1            //   start with i = -1
  ) ?                 // end of some(); if it's truthy:
    a + `\n` +        //   append a[] followed by a line feed
    g(                //   followed by the result of a recursive call:
      b,              //     pass b[] unchanged
      a[i] +=         //     add either 1 or 9 to a[i]:
        d / 5 < 5 / d //       add 1 if d / 5 < 5 / d
        || 9          //       otherwise, add 9
    )                 //   end of recursive call
  :                   // else:
    b                 //   stop recursion and return b[]

d/6&1^d>0||9 -> d/5>5/d?9:1

Jelly, 25 bytes
_æ%5+⁹⁹rḊ€%⁵J;Ɱ"$ẎṄḢ}⁺¦¥ƒ

Try it online!
Full program.

Python 2, 101 97 bytes
a,c=input()
print a
for i in 0,1,2:
 while a[i]!=c[i]:a[i]=(a[i]+(a[i]-c[i])%10/5*2-1)%10;print a

Try it online!
3 bytes thx to Joel.
Takes input as lists of ints.

98 bytes

@Joel: Thanks! Actually, since it's Python 2, // is the same as /, so there's an additonal byte gained.

This looks like the exact same approach as @TFeld's answer, but with slight modifications

@Jitse: Well, we've both been modifying our answers; for example, he started with for x,y,i in zip(a,c,[0,1,2]) if I recall...

PHP, 114 bytes
for([,$a,$b]=$argv;$i<3;($x=$a[$i]-$b[$i])?(print$a._).$a[$i]=($y=$a[$i]+(5/$x>$x/5?-1:1))<0?9:$y%10:++$i);echo$b;

Try it online!
My solution probably sucks, but that is the best I can think of for now!

Jelly, 30 bytes
_ż+¥⁵AÞḢṠxAƊ×€ʋ"JṬ€$$Ẏ;@W}+\%⁵

Try it online!
A dyadic link taking as its left argument the unlock code and its right the current locked state, both as lists of integers.
This feels far too long!

Charcoal, 48 bytes
θ≔ＥθＩιθＦ³«≔⁻﹪⁺⁻Ｉ§ηι§θι⁵χ⁵ζＦ↔ζ«§≔θι﹪⁺§θι÷ζ↔ζχ⸿⪫θω

Try it online! Link is to verbose version of code. Explanation:
θ

Print the initial position.
≔ＥθＩιθ

Change the initial position string into an array of numeric digits for calculation purposes.
Ｆ³«

Loop over each digit in turn.
≔⁻﹪⁺⁻Ｉ§ηι§θι⁵χ⁵ζ

Calculate the number of rotations needed to unlock that digit. This is a number from -5 to 4 where -5 means 5 downward rotations and 4 means 4 upward rotations.
Ｆ↔ζ«

Loop over each rotation.
§≔θι﹪⁺§θι÷ζ↔ζχ

Update the digit according to the sign of the rotation.
⸿⪫θω

Output the digits as a string on a new line.

T-SQL 2008, 170 bytes
I added some linebreaks to make it readable
DECLARE @1 char(3)='123',@2 char(3)='956'

DECLARE @r int,@s int,@ int=0
g:SET @+=1
h:SELECT @r=substring(@1,@,1)+9,@s=@r-substring(@2+'1',@,1)
IF @s=9GOTO g
PRINT @1
SET @1=stuff(@1,@,1,(@r+@s/5%2*2)%10)
IF @<4GOTO h

Try it online

This solution doesn't keep leading 0's in the output. Example: 000-999

@Matthew you are almost right, I was hoping to use this build in input option, however, if you start with 0 in input it will be removed from the input.  It is not the solution that fails though

@Matthew - it is fixed now btw. Removed the input boxes which isn't part of sql anyway

C# (Visual C# Interactive Compiler), 101 bytes
a=>b=>{for(int i=0;i<3;i++)for(;a[i]!=b[i];a[i]+=(a[i]-b[i]+10)%10<5?9:1,a[i]%=10)Print(a);Print(a);}

Try it online!

J, 36 bytes
10|[+/\@,#:@4 2 1#~[:>&|/`]}10|-,:-~

Try it online!
Will add explanation tomorrow.

MATLAB, 100 89 bytes
A different approach (using implicit expansion to create a subtraction matrix) reduces 11 bytes:
function f(a,b);c = mod(a-b+5,10)-5;a,mod(a-cumsum(repelem(eye(3).*sign(c),abs(c),1)),10)

[Original 100 byte solution]
function f(a,b);c=mod(a-b+5,10)-5;a,for n=1:3;for r=1:abs(c(n));a(n)=mod(a(n)-sign(c(n)),10),end;end

Both called by passing the inputs as 3-element arrays, e.g. f([9 1 1], [2 3 2])

Java (JDK), 139 bytes
a->b->{for(int i;;a[i]+=(a[i]-b[i]+10)%10<5?9:1,a[i]%=10){System.out.println(""+a[i=0]+a[1]+a[2]);for(;i<3&&a[i]==b[i];i++);if(i>2)break;}}

Try it online!
Same algorithm as everyone, rolled differently because Java's System.out.println is pretty expensive!

C (clang), 125 bytes
t,*d;f(*a,*b){for(t=d=a;t?printf("%d%d%d\n",*a,a[1],a[2]):d++,t=*d-b[d-a],d-a<3;*d=(*d+=!~*d*10)%10)t?*d+=(t+10)/5&1?1:-1:0;}

Try it online!

Kotlin, 162 bytes
{s:Array<Int>,e:Array<Int>->var i=0
o@while(i<3){println(""+s[0]+s[1]+s[2])
while(s[i]==e[i]){if(i>1)break@o
i++}
s[i]=(s[i]+if((e[i]-s[i]+10)%10>5)9 else 1)%10}}

Try it online!

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


text:
Count the number of shortest paths to n
This code challenge will have you compute the number of ways to reach \$n\$ starting from \$2\$ using maps of the form \$x \mapsto x + x^j\$ (with \$j\$ a non-negative integer), and doing so in the minimum number of steps.
(Note, this is related to OEIS sequence A307092.)
Example
So for example, \$f(13) = 2\$ because three maps are required, and there are two distinct sequences of three maps that will send \$2\$ to \$13\$:
$$\begin{array}{c} x \mapsto x + x^0 \\ x \mapsto x + x^2 \\ x \mapsto x + x^0\end{array} \qquad \textrm{or} \qquad \begin{array}{c}x \mapsto x + x^2 \\ x \mapsto x + x^1 \\ x \mapsto x + x^0\end{array}$$
Resulting in \$2 \to 3 \to 12 \to 13\$ or \$2 \to 6 \to 12 \to 13\$.
Example values
f(2)   = 1 (via [])
f(3)   = 1 (via [0])
f(4)   = 1 (via [1])
f(5)   = 1 (via [1,0])
f(12)  = 2 (via [0,2] or [2,1])
f(13)  = 2 (via [0,2,0] or [2,1,0], shown above)
f(19)  = 1 (via [4,0])
f(20)  = 2 (via [1,2] or [3,1])
f(226) = 3 (via [2,0,2,1,0,1], [3,2,0,0,0,1], or [2,3,0,0,0,0])
f(372) = 4 (via [3,0,1,0,1,1,0,1,1], [1,1,0,2,0,0,0,1,1], [0,2,0,2,0,0,0,0,1], or [2,1,0,2,0,0,0,0,1])

Challenge
The challenge is to produce a program which takes an integer \$n \ge 2\$ as an input, and outputs the number of distinct paths from \$2\$ to \$n\$ via a minimal number of maps of the form \$x \mapsto x + x^j\$.
This is code-golf, so fewest bytes wins.

I think it should be explicitly noted that the ^ symbol denotes exponentiation. It could be XOR as well (for instance C uses ^ for bitwise XOR).

@Ramillies Maybe it should be changed to MathJax. I.e. $x=x+x^j$ instead of x -> x + x^j.

@KevinCruijssen: Good point, that would certainly help.

I have added this to the OEIS as A309997. (It will be a draft until approved.)

Jelly, 16 bytes
2+*¥þ³Ḷ¤F$n³Ạ$¿ċ

Try it online!
A full program taking as its argument \$n\$ and returning the number of ways to reach \$n\$ using the minimal path length. Inefficient for larger \$n\$.

JavaScript (ES6),  111 ... 84  80 bytes
Returns true rather than \$1\$ for \$n=2\$.
f=(n,j)=>(g=(i,x,e=1)=>i?e>n?g(i-1,x):g(i-1,x+e)+g(i,x,e*x):x==n)(j,2)||f(n,-~j)

Try it online!
Commented
f = (                     // f is the main recursive function taking:
  n,                      //   n = input
  j                       //   j = maximum number of steps
) => (                    //
  g = (                   // g is another recursive function taking:
    i,                    //   i = number of remaining steps
    x,                    //   x = current sum
    e = 1                 //   e = current exponentiated part
  ) =>                    //
    i ?                   // if there's still at least one step to go:
      e > n ?             //   if e is greater than n:
                          //     add the result of a recursive call with:
        g(i - 1, x)       //       i - 1, x unchanged and e = 1
      :                   //   else:
                          //     add the sum of recursive calls with:
        g(i - 1, x + e) + //       i - 1, x + e and e = 1
        g(i, x, e * x)    //       i unchanged, x unchanged and e = e * x
    :                     // else:
      x == n              //   stop recursion; return 1 if x = n
)(j, 2)                   // initial call to g with i = j and x = 2
|| f(n, -~j)              // if it fails, try again with j + 1

Haskell, 78 75 bytes
This implementation uses a breath-first-search in the "tree" of iteratively all necessary mappings x -> x + x^j.
j#x=x+x^j
f n=[sum[1|x<-l,x==n]|l<-iterate((#)<$>[0..n]<*>)[2],n`elem`l]!!0

Try it online!
Explanation
-- computes the mapping x -> x + x^j
j#x=x+x^j
--iteratively apply this function for all exponents [0,1,...,n] (for all previous values, starting with the only value [2])
                            iterate((#)<$>[0..n]<*>)[2]
-- find each iteration where our target number occurs
    [                   |l<-...........................,n`elem`l]
-- find how many times it occurs
     sum   [1|x<-l,x==n]
-- pick the first entry
f n=.............................................................!!0

05AB1E, 17 bytes
2¸[˜DIå#εIÝmy+]I¢

Try it online!

Python 2, 72 bytes
f=lambda n,l=[2]:l.count(n)or f(n,[x+x**j for x in l for j in range(n)])

Try it online!

Nice way of implementing BFS recursively.

Perl 5 (-lp), 79 bytes
$e=$_;@,=(2);@,=map{$x=$_;map$x+$x**$_,0..log($e)/log$x}@,until$_=grep$_==$e,@,

TIO

CJam (27 bytes)
qi2a{{_W$,f#f+~2}%_W$&!}ge=

Online demo
Warning: this gets very memory-intensive very fast.
Dissection:
qi            e# Read input and parse to int n (accessed from the bottom of the stack as W$)
2a            e# Start with [2]
{             e# Loop
  {           e#   Map each integer x in the current list
    _W$,f#f+~ e#     to x+x^i for 0 <= i < n
    2         e#   and add a bonus 2 for the special case
  }%          e#   Gather these in the new list
  _W$&!       e#   Until the list contains an n
}g
e=            e# Count occurrences

The bonus 2s (to handle the special case of input 2, because while loops are more expensive than do-while loops) mean that the size of the list grows very fast, and the use of exponents up to n-1 means that the values of the larger numbers in the list grow very fast.

Haskell, 65 bytes
([2]%)
l%n|elem n l=sum[1|x<-l,x==n]|1>0=[x+x^k|x<-l,k<-[0..n]]%n

Try it online!
Golfing flawr's breadth-first-search. I also tried going backwards from n, but it was longer:
73 bytes
q.pure
q l|elem 2l=sum[1|2<-l]|1>0=q[x|n<-l,x<-[0..n],i<-[0..n],x+x^i==n]

Try it online!

R, 78 77 bytes
function(n,x=2){while(!{a=sum(x==n)})x=rep(D<-x[x<n],n+1)+outer(D,0:n,'^')
a}

Try it online!
Using a simplified Breadth-first Search
Unrolled code with explanation :
function(n){                              # function taking the target value n

  x=2                                     # initialize vector of x's with 2

  while(!(a<-sum(x==n))) {                # count how many x's are equal to n and store in a
                                          # loop while a == 0

    x=rep(D<-x[x<n],n+1)+outer(D,0:n,'^') # recreate the vector of x's
                                          # with the next values: x + x^0:n
  }
a                                         # return a
}

Shorter version with huge memory allocation (failing for bigger cases) :
R, 70 69 bytes
function(n,x=2){while(!{a=sum(x==n)})x=rep(x,n+1)+outer(x,0:n,'^')
a}

Try it online!
-1 byte thanks to @RobinRyder

!(a<-sum(x==n)) could be !{a=sum(x==n)} for -1 byte in both cases.

Pyth, 24 bytes
VQIJ/mu+G^GHd2^U.lQ2NQJB

Try it online!
This should produce the correct output, but is very slow (the 372 test case times out on TIO). I could make it shorter by replacing .lQ2 with Q, but this would make the runtime horrendous.
Note: Produces no output for unreachable numbers \$(n \leq 1)\$
Explanation
VQ                        # for N in range(Q (=input)):
   J                      #   J =
     m                    #     map(lambda d:
      u                   #       reduce(lambda G,H:
       +G^GH              #         G + G^H,
            d2            #         d (list), 2 (starting value) ),
              ^U.lQ2N     #       cartesian_product(range(log(Q, 2)), N)
    /                Q    #     .count(Q)
  IJ                  JB  #   if J: print(J); break

source: Stack Exchange

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

sort: votes


text:
Bot Problem.How to solve this problem in c?
Programming problem:
In BotLand, Robots can understand all words of any combination of letters and letters with leading or trailing (not both) numeric value. Given a word W (string of alphanumeric). Write a function to check if W is Bot word. Don't use library functions/ regex.
Example:
Input: BotLand
Output: Bot word
Input: BotLand77
Output: Bot word
Input: 1Bot2Land3
Output: Non Bot word

Welcome to CGCC. This site hosts recreational programming challenges, based on an objective winning criterion. (Here, you picked code-golf: the shortest answer wins.) It is not designed to get any practical implementation or theoretical answer. So, is it really supposed to be a challenge?

Python 3, 33 bytes
lambda s:1-(s[0]+s[-1]).isdigit()

Try it online!
-8 bytes thanks to Grimy and A _

Python 3, 41 bytes
lambda s:a(s[0])+a(s[-1])>0
a=str.isalpha what is this @Jitse. what is this?

@MafujShikder it's a program answering your challenge. You can use the Try it online! link to check that it works.

36 bytes

@Jitse please solve this problem n c

33B if you use 1 for true and 0 for false. 32B by abusing predefined true/false values even further.

@MafujShikder Specific-language competitions are highly discouraged unless in very specific cases and this is not one of those cases.


text:
Is it checkmate?
Wholly surprised this hasn't been posted already, given the large number of chess puzzles on the site. While I thought of this myself, credit to Anush for posting it to the sandbox back in March. But I figured it's been long enough that I could go ahead and do so myself.
A checkmate in chess is a position in which the king is attacked and there is no move that can defend it. If you aren't familiar with how chess pieces move, you can familiarize yourself on Wikipedia.
The challenge
For this challenge, your input will be the position of a chess board in whatever notation you like. To clarify, your input will describe the pieces on a chess board, with their colors and positions, along with the possible en passant capture square, if any. (Ability to castle is irrelevant as you cannot castle out of check.) You may find FEN notation useful, but any convenient format is fine. For simplicity, you can assume it's Black to play - this means Black will always be the checkmated player. A position where White is in check, checkmate, or stalemate will be considered invalid for this challenge.
You must output a truthy value if the position is checkmate, and a falsey value if it is not. Note that stalemate is not checkmate - the king must be attacked!
Truthy test cases

1k5R/6R1/8/8/8/8/8/6K1 b - -
rn2r1k1/pp1p1pQp/3p4/1b1n4/1P2P3/2B5/P5PP/R3K2R b - -
kr5R/rB6/8/8/8/5Q2/6K1/R7 b - -
2K5/1B6/8/8/8/7N/R7/R3r2k b - - 0 1
8/4Q1R1/R7/5k2/3pP3/5K2/8/8 b - -
2K5/1B6/8/8/8/4b2N/R7/4r2k b - -

Falsey test cases

rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq -
8/8/8/8/8/1KQ5/4N3/1k6 b - -
2K5/1B6/8/8/8/7N/R7/4r2k b - -
8/8/2Q5/3k4/3Q5/8/8/7K b - -
8/4Q1R1/R7/5k2/3pP3/5K2/8/8 b - e3 (Watch that en passant!)

Code golf - shortest code in bytes wins. Good luck!

This looks like a great question :)

In the interests of being self-contained - which all challenges here should be - this needs to be fleshed out a good deal more rather than relying on external links and/or assuming an existing knowledge of the rules and notation of chess. I'd suggest taking it back to the Sandbox while it is being worked on.

@Shaggy The external links in this challenge serve for convenience only. I'm not going to list all of the rules of chess here, as most other chess challenges presume prior knowledge of them. And the lichess links only serve as a handy visual representation of the test cases; the notation is well-defined outside of lichess. I could add images but I decided not to as it felt like a lot of clutter.

Can we assume that the board has been arrived at via a valid game?

Suggested test case: 2K5/1B6/8/8/8/4b2N/R7/4r2k b - - 0 1 (truthy).

I've reopened this because while the core task is the same this challenge has a much more lax (and honestly a better) IO scheme and a slightly different (and honestly better) scoring criterion.  I think that perhaps the old one should be closed as a dupe of the new one but I am not going to hammer it.

I would add a picture of the most difficult Truthy and Falsy examples. It makes the question more fun to read.

The penultimate FEN string is invalid. 3Q5 should be 3Q4.

Another testcase: 8/2p5/Q7/Q2k4/Q7/8/8/7K b - -

JavaScript (Node.js),  499 ... 374  370 bytes
Takes input as (b)(X), where \$b\$ is an array of 64 integers describing the squares (from left to right and from top to bottom) and \$X\$ is the 0-based index of the en-passant target square, or \$-1\$ if there's none.
Below are the expected values for each square:
 0: empty square

 5: white pawn      6: black pawn
 9: white king     10: black king
17: white bishop   18: black bishop
33: white rook     34: black rook
49: white queen    50: black queen
65: white knight   66: black knight

Returns \$64\$ for checkmate, or \$0\$ for not-checkmate.
b=>e=>(g=(c,k)=>b.map((v,p,h,s=p+(p&~7),M=t=>v&-~c?c?(B=[...b],K&=g(b[t?b[T]=b[p]:b[b[e-8]=0,e]=6,p]=0),b=B):k|=V&8:0,m=([a],[x,t,...d]=Buffer(a))=>d.map(c=>(h=n=>(V=(a+=c-66)&136?3:b[T=a+a%8>>1])&v&3||t>>!V&v>>x&n>31&&h(n-4/!V,M``))(t,a=s)))=>(v=b[p],m`##123ACQRS`,m`$?13QS`,m`%?2ACR`,m`&#!#04PTac`,c?(p-e+8.5&~1||M(),m`"!QS`,p<16?m`"&R`:m`""R`):m`"!13`))|k)(1,K=g())*K

Try it online!
How?
Board representation
We use the classic 0x88 board representation, so that out-of-bounds target squares can be easily detected.
   |  a    b    c    d    e    f    g    h
---+----------------------------------------
 8 | 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07
 7 | 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17
 6 | 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27
 5 | 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37
 4 | 0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47
 3 | 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57
 2 | 0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x67
 1 | 0x70 0x71 0x72 0x73 0x74 0x75 0x76 0x77

Move encoding
Each set of moves is encoded with 5 parameters:

the type of piece
the maximum number of squares that can be visited in each direction
a flag telling if captures are allowed
a flag telling if non-captures are allowed
a list of directions

All these parameters are packed into a single string. For instance, knight moves are encoded as follows:
`&#!#04PTac`
 ||\______/
 ||    |                            +------> 0 + 1 = 1 square in each direction
 ||    |                            | +----> standard moves allowed
 ||    +---> 8 directions           | |+---> captures allowed
 ||                                / \||
 |+--------> ASCII code = 35 = 0b0100011
 |
 +---------> 1 << (ASCII code MOD 32) = 1 << 6 = 64

To decode a direction, we subtract \$66\$ from its ASCII code:
 char. | ASCII code | -66
-------+------------+-----
  '!'  |     33     | -33
  '#'  |     35     | -31
  '0'  |     48     | -18
  '4'  |     52     | -14
  'P'  |     80     | +14
  'T'  |     84     | +18
  'a'  |     97     | +31
  'c'  |     99     | +33

which gives:
 [ - ] [-33] [ - ] [-31] [ - ]
 [-18] [ - ] [ - ] [ - ] [-14]
 [ - ] [ - ] [ N ] [ - ] [ - ]
 [+14] [ - ] [ - ] [ - ] [+18]
 [ - ] [+31] [ - ] [+33] [ - ]

All sets of moves are summarized in the following table, except en-passant captures which are processed separately.
  string    | description             | N | S | C | directions
------------+-------------------------+---+---+---+----------------------------------------
 &#!#04PTac | knight                  | 1 | Y | Y | -33, -31, -18, -14, +14, +18, +31, +33
 ##123ACQRS | king                    | 1 | Y | Y | -17, -16, -15, -1, +1, +15, +16, +17
 "!13       | white pawn / captures   | 1 | N | Y | -17, -15
 "!QS       | black pawn / captures   | 1 | N | Y | +15, +17
 "&R        | black pawn / advance x2 | 2 | Y | N | +16
 ""R        | black pawn / advance x1 | 1 | Y | N | +16
 $?13QS     | bishop or queen         | 8 | Y | Y | -17, -15, +15, +17
 %?2ACR     | rook or queen           | 8 | Y | Y | -16, -1, +1, +16

Commented
b => e => (
  // generate all moves for a given side
  g = (c, k) =>
    b.map((
      v, p, h,
      // s = square index in 0x88 format
      s = p + (p & ~7),
      // process a move
      M = t =>
        // make sure that the current piece is of the expected color
        v & -~c ?
          c ?
            // Black's turn: play the move
            ( // board backup
              B = [...b],
              // generate all White moves ...
              K &= g(
                // ... after the board has been updated
                b[
                  t ?
                    // standard move
                    b[T] = b[p]
                  :
                    // en-passant capture
                    b[b[e - 8] = 0, e] = 6,
                  p
                ] = 0
              ),
              // restore the board
              b = B
            )
          :
            // White's turn: just update the king's capture flag
            k |= V & 8
        :
          0,
      // generate all moves of a given type for a given piece
      m = ([a], [x, t, ...d] = Buffer(a)) =>
        d.map(c =>
          ( h = n =>
            ( // advance to the next target square
              V = (a += c - 66) & 136 ? 3 : b[T = a + a % 8 >> 1]
            )
            // abort if it's a border or a friendly piece
            & v & 3 ||
            // otherwise: if this kind of move is allowed
            t >> !V &
            // and the current piece is of the expected type
            v >> x &
            // and we haven't reached the maximum number of squares,
            n > 31 &&
            // process this move (if it's a capture, force n to
            // -Infinity so that the recursion stops)
            h(n - 4 / !V, M``)
          )(t, a = s)
        )
    ) =>
      (
        v = b[p],
        // king
        m`##123ACQRS`,
        // bishop or queen
        m`$?13QS`,
        // rook or queen
        m`%?2ACR`,
        // knight
        m`&#!#04PTac`,
        c ?
          // black pawn
          ( // en-passant capture
            p - e + 8.5 & ~1 || M(),
            // standard captures
            m`"!QS`,
            // standard moves
            p < 16 ? m`"&R` : m`""R`
          )
        :
          // white pawn (standard captures only)
          m`"!13`
      )
    ) | k
// is the black king in check if the Black don't move?
// is it still in check after each possible move?
)(1, K = g()) * K

8/1ppp4/1pkp4/8/2Q5/8/8/7K b - -

@tsh A much more serious bug. Fixed at the cost of 6 bytes for now.

How does work without a representation telling you if en passant is possible?

@Anush The $X$ parameter holds this information.

This is an amazing answer. I hope it was nominated for a prize.

Haskell, 1165 1065 1053 bytes
Bytes saved thanks to Leo Tenenbaum
n=Nothing
x?y=Just(x,y)
o(x,y)=x<0||y<0||x>7||y>7
m#k@(x,y)|o k=n|1>0=m!!x!!y
z(x,y)m p(a,b)|o(x+a,y+b)=1<0|Just g<-m#(x+a,y+b)=elem g[(p,0),(5,0)]|1>0=z(x+a,y+b)m p(a,b)
t(x,y)p(a,b)m|o(x+a,y+b)=[]|g<-(x+a,y+b)=(g%p)m++do[0|m#g==n];t g p(a,b)m
c m|(x,y):_<-[(a,b)|a<-u,b<-u,m#(a,b)==6?1],k<-z(x,y)m=or$[m#(x+a,y+b)==6?0|a<-0:s,b<-0:s]++do a<-s;[k 3(a,b)|b<-s]++(k 2<$>[(a,0),(0,a)])++[m#l==4?0|b<-[2,-2],l<-[(x+a,y+b),(x+b,y+a)]]++[m#(x-1,y+a)==p?0|p<-[0,1]]
c m=1>0
(k%p)m=[[[([p|a==k]++[m#a])!!0|a<-(,)b<$>u]|b<-u]|not$o k]
w(Just(_,1))=1<0
w x=1>0
m!u@(x,y)|g<-m#u,Just(q,1)<-g,v<-((u%n)m>>=),r<-v.t u g,k<-(do[0|n==m#(x+1,y)];(u%n)m>>=(x+1,y)%g)++(do a<-s;[0|n<m#(x+1,y+a)];v$(x+1,y+a)%g)++(do[0|(x,n,n)==(1,m#(x+1,y),m#(x+2,y))];v$(x+2,y)%g)++(do a<-s;[0|1?0==m#(x,y+a)];v((x,y+a)%n)>>=(x+1,y+a)%g)=[k,k,do a<-s;[(a,0),(0,a)]>>=r,do a<-s;b<-s;r(a,b),do a<-s;b<-[2,-2];l<-[(x+a,y+b),(x+b,y+a)];v$l%g,do a<-0:s;b<-[0|a/=0]++s;r(a,b),do a<-[x-1..x+1];b<-[y-1..y+1];[0|w$m#(a,b)];v$(a,b)%g]!!q
m!u=[]
u=[0..7]
s=[1,-1]
q m=all c$m:do a<-u;b<-u;m!(a,b)

Try it online!
This is not exactly well golfed as of now, but it is a start.  With some help along the way I've now golfed this down pretty aggressively (and fixed an error along the way).
The one perhaps questionable thing this does is that it assumes that, other than by a king or a pawn en passant, you can never get out of check by capturing one of your own pieces.  In chess you are not allowed to make this move but my program considers these moves to save bytes under the assumption that if you are in check this can never get you out of it.
This assumption is valid because such moves

Cannot capture the piece that is attacking the king, since the piece they capture is black.
Cannot block the path of the piece that is attacking the king, since the captured black piece would have already been doing that.

We also add the additional stipulation that if you have no king you are in check.
This program also makes the assumption that if there is a pawn that can be captured en passant, then the pawn was the last piece to move and that move was a legal move.  This is because the program does not check if the square it moves the black pawn to is empty so if there is a piece there things can get a little screwy.  However this cannot be obtained if the last move was a legal move and furthermore cannot be represented in FEN.  So this assumption seems rather solid.
Here is my "ungolfed" version for reference:
import Control.Monad
out(x,y)=x<0||y<0||x>7||y>7
at b (x,y)
  |out(x,y)=Nothing
  |otherwise=(b!!x)!!y
inLine (x,y) ps m (a,b)
  | out (x+a,y+b) = False
  | elem (m `at` (x+a,y+b)) $ Just <$> ps = True
  | m `at` (x+a,y+b) == Nothing = inLine (x+a,y+b) ps m (a,b)
  | otherwise = False
goLine (x,y) p (a,b)m
  | out (x+a,y+b) = []
  | otherwise = case m `at` (x+a,y+b) of
--    Just (n,1) -> []
    Just (n,_) -> set(x+a,y+b)p m
    Nothing    -> set(x+a,y+b)p m ++ goLine(x+a,y+b)p(a,b)m
checkBishop (x,y) m=or[inLine(x,y)[(3,0),(5,0)]m(a,b)|a<-[1,-1],b<-[1,-1]]
checkRook   (x,y) m=or$do
  a<-[1,-1]
  inLine(x,y)[(2,0),(5,0)]m<$>[(a,0),(0,a)]
checkKnight (x,y) m=any((==Just(4,0)).(at m))$do
  a<-[1,-1]
  b<-[2,-2]
  [(x+a,y+b),(x+b,y+a)]
checkPawn (x,y) m=or[at m a==Just(p,0)|a<-[(x-1,y+1),(x-1,y-1)],p<-[0,1]]
checkKing (x,y) m=or[at m(a,b)==Just(6,0)|a<-[x-1..x+1],b<-[y-1..y+1]]
check m
  | u:_<-[(a,b)|a<-[0..7],b<-[0..7],(m!!a)!!b==Just(6,1)] =
    checkBishop u m ||
    checkRook   u m ||
    checkKnight u m ||
    checkPawn   u m ||
    checkKing   u m
  | otherwise = True
set (x,y) p m=[[[head$[p|(a,b)==(y,x)]++[(m!!b)!!a]|a<-[0..7]]|b<-[0..7]]|not$out(x,y)]
white(Just(n,0))=True
white x=False
moves m (x,y)
 |g<-m `at` (x,y)=case g of
  Just(2,1) -> do
    a<-[1,-1]
    b<-[(a,0),(0,a)]
    set(x,y)Nothing m>>=goLine (x,y) g b
  Just(3,1) -> do
    a<-[1,-1]
    b<-[1,-1]
    set(x,y)Nothing m>>=goLine (x,y) g(a,b)
  Just(4,1) -> do
    n<-set(x,y)Nothing m
    a<-[1,-1]
    b<-[2,-2]
    l<-[(x+a,y+b),(x+b,y+a)]
    -- guard$white$n `at` l
    set l g n
  Just(5,1) -> do
    a<-[1,-1]
    c<-[(a,0),(0,a),(a,1),(a,-1)]
    set(x,y)Nothing m>>=goLine (x,y) g c
  Just(6,1) -> do
    a<-[x-1..y+1]
    b<-[x-1..y+1]
    guard$white(m `at`(a,b))||Nothing==m`at`(a,b)
    set(x,y)Nothing m>>=set(a,b)g
  Just(n,1) -> (do
    guard$Nothing==m `at` (x+1,y)
    set(x,y)Nothing m>>=set(x+1,y)g) ++ (do
      a<-[1,-1]
      guard$white$m`at`(x+1,y+a)
      set(x,y)Nothing m>>=set(x+1,y+a)g) ++ (do
        guard$(x,Nothing,Nothing)==(1,m`at`(x+1,y),m`at`(x+1,y))
        set(x,y)Nothing m>>=set(x+2,y)g) ++ (do
          a<-[1,-1]
          guard$Just(1,0)==m`at`(x,y+a)
          set(x,y)Nothing m>>=set(x,y+a)Nothing>>=set(x+1,y+a)g)
  _ -> []
checkmate m=all check$m:do
  a<-[0..7]
  b<-[0..7]
  moves m(a,b)

Try it online!

1252 bytes with a bit of golfing (the TIO link was too long to fit in this comment...)

@LeoTenenbaum Thanks a bunch I will incorporate this shortly unfortunately there were two accidental errors in the version you were golfing from which I have now fixed.  There is certainly room to improve in a lot of ways with a program this long.

@tsh yep, I forgot to add the kings location to where it was going. fixed now

For lists, guard x = [0|x], and you can also use x?y=Just(x,y) to save a few more bytes: 1129 bytes

Python 3 (PyPy), 729 bytes
F=lambda a,b:a<'^'<=b or a>'^'>=b
def m(b,P,A=0):
 yield b
 for(r,f),p in b.items():
  if F(P,p):continue
  *d,n,k={'R':[(0,1),8,4],'N':[(1,2),(2,1),2,4],'B':[(1,1),8,4],'Q':[(0,1),(1,1),8,4],'K':[(0,1),(1,1),2,4],'P':[(2,0),(1,0),(1,1),(1,-1),2,1],'p':[(-2,0),(-1,0),(-1,1),(-1,-1),2,1]}[p if p=='p'else p.upper()]
  if p in'pP':d=d[d!=[2,7][p=='p']+A:]
  for u,v in d:
   for j in range(k):
    for i in range(1,n):
     U=r+u*i;V=f+v*i;t=b.get((U,V),'^')
     if U<1or U>8or V<1 or V>8:break
     if F(p,t):
      B=dict(b);B[(U,V)]=B.pop((r,f))
      if t in'eE':B.pop(([U+1,U-1][t=='e'],V))
      yield B
     if t not in'^eE':break
    u,v=v,-u
M=lambda b:all(any('k'not in C.values()for C in m(B,'W',1))for B in m(b,'b'))

Try it online!

This currently fails for 8/2p5/Q7/Q2k4/Q7/8/8/7K b - - (not checkmate).


text:
Nothing like a good ol' game of ModTen
Disclaimer: ModTen is a fictional card game which was created for the sole purpose of this challenge.
The rules of ModTen
ModTen is played with a standard 52-card deck. Because the full rules are yet to be invented, we're going to focus on the hand ranking exclusively.

A winning hand in ModTen. Graphics from Wikipedia.
Card values
The cards have the following values:

2 to 9: worth their face value
Ten: 0 point
Jack: 3 points
Queen or King: 8 points
Ace: 9 points

Hand values

A ModTen hand is made of two cards. The base value of a hand is obtained by multiplying the value of both cards together and keeping the last digit only (i.e. applying a modulo 10).
For instance, the value of 7♥ - Q♣ is "\$6\$", because \$(7\times8)\bmod 10=6\$.
The only other rule in ModTen is that suited cards are worth more than unsuited ones. By convention, we are going to append a "s" to the value if both cards are of the same suit.
For instance, the value of 9♠ - 5♠ will be noted as "\$5\text{s}\$", because \$(9\times5)\bmod 10=5\$ and the cards are suited.

Hand ranking and winner
The above rules result in 18 distinct hand ranks which are summarized in the following table, from strongest to lowest (or rarest to most common). The probabilities are given for information only.
Given two hands, the hand with the lowest rank wins. If both hands are of the same rank, then it's a draw (there's no tie breaker).
 hand rank | hand value(s) | deal probability
-----------+---------------+------------------
     1     | 9s            | 0.30%
     2     | 3s            | 0.60%
     3     | 1s            | 0.90%
     4     | 7s            | 1.21%
     5     | 5s            | 1.51%
     6     | 3             | 1.81%
     7     | 9             | 2.26%
     8     | 8s            | 2.71%
     9     | 6s            | 3.02%
    10     | 1 or 7        | 3.62% each
    11     | 2s or 4s      | 3.92% each
    12     | 5             | 4.98%
    13     | 0s            | 5.43%
    14     | 8             | 8.14%
    15     | 6             | 9.95%
    16     | 2             | 11.76%
    17     | 4             | 13.57%
    18     | 0             | 16.74%

The challenge
Given two ModTen hands, output one of three consistent values of your choice to tell whether:

the first player wins
the second player wins
it's a draw

The following rules apply:

A card must be described by its rank in upper case (2, 3, ..., 9, T, J, Q, K or A) followed by its suit in lower case (c, d, h or s, for clubs, diamonds, hearts and spades).
You may use "10" instead of "T" but any other substitution is prohibited.
As long as the above rules are followed, you may take the hands in any reasonable and unambiguous format. You are allowed to take the rank and the suit as two distinct characters rather than a single string.
Some valid input formats are:

"7c Qh 8s Ks"
[["7c","Qh"], ["8s","Ks"]]
[[['7','c'], ['Q','h']], [['8','s'], ['K','s']]]
etc.

Instead of using 3 consistent distinct values, your output may also be negative, positive or zero. Please specify the output format used in your answer.
This is code-golf.

Test cases
Player 1 wins
["Js","3s"], ["Ks","Kh"]
["7h","9h"], ["9s","7c"]
["Ah","5s"], ["Ts","8s"]
["Ts","8s"], ["Jh","2s"]
["4h","8s"], ["Qh","Ks"]

Player 2 wins
["Th","8d"], ["6s","Kd"]
["Jc","5c"], ["3s","9s"]
["Jc","Jd"], ["9h","Ah"]
["2d","4d"], ["3h","3s"]
["5c","4c"], ["3c","2c"]

Draw
["Js","3s"], ["3d","Jd"]
["Ah","Ac"], ["3d","9s"]
["Qc","Kc"], ["6d","4d"]
["2d","3d"], ["3s","2s"]
["Ts","9c"], ["4h","5d"]

What about taking enums as input? Haskell has a pretty powerful type system; I'm fairly sure something like this could be made directly in it.

This isn't Haskell, but would {{J, s}, {3, s}} be okay?

@wizzwizz4 Yes, that's fine.

This might be clearer with "hands of cards with matching suits" instead of "suited cards".

Python 3, 114 110 bytes
lambda m,n:p(*n)-p(*m)
R=b"T 2J45UNK9RL<3SLM;QAK:O>=/678"
v=R.find
p=lambda i,s,j,t:R[s==t::2][v(j)*v(i)%10+3]

Try it online!
@Arnauld proposed the idea of merging the card value and rank table strings. After some attempts I managed to craft a merged string R="T 2J45UNK9RL<3SLM;QAK:O>=/678", which has the same length as the original card value string. The substring R[6:25]="UNK9RL<3SLM;QAK:O>=/" serves as the rank table as well as a card value lookup table for 3, 9, A, K, and Q. The ASCII-value decoding of the new rank table has the same ranking effect as the previous rank table.
Using byte strings as input saves 4 bytes.
Using cmp in Python 2 can reduce the solution to 102 bytes, as shown by @xnor's solution.

Python 3, 165 142 130 129 bytes
lambda m,n:p(*n)-p(*m)
v="T 23456789   J    QA        K".find
p=lambda i,s,j,t:ord("HC92FA51GAB4E893D760"[s==t::2][v(j)*v(i)%10])

Try it online!
-23 bytes thanks to @Jonathan Allan
-2 bytes thanks to @ovs
-1 byte thanks to @mypetlion
Ungolfed:
f = lambda hand1, hand2: get_rank(*hand2) - get_rank(*hand1)
def get_rank(v1, suit1, v2, suit2):
    get_card_value = "T 23456789   J    QA        K".find
    # rank_table = [[17,9,15,5,16,11,14,9,13,6],[12,2,10,1,10,4,8,3,7,0]]
    # rank_table = ("H9F5GBE9D6","C2A1A48370") # Base-18 encoding of ranks
    rank_table = "HC92FA51GAB4E893D760" # Interleaved base-18 encoding

    # ASCII-value decoding has the same ranking effect as base-18 decoding
    return ord(rank_table[suit1 == suit2::2][get_card_value(v2) * get_card_value(v1) % 10])

The function f takes two arguments representing the hand of player 1 and player 2. It returns a positive, negative, or zero value in the case of a player 1 win, a player 2 win, or a draw, correspondingly. Each hand is encoded as a single string, e.g. "7cQh".

Hi Joel, welcome to CGCC! Very clever idea splitting the hand rank array in two! Keep 'em coming!

Save 19 bytes by casting some characters to ordinals :)

...and two more using a slightly different input format

@Jonathan Allan Thanks. I've incorporated your idea using slightly different approaches.

You can save 2 bytes by storing the rank table in a single string: "HC92FA51GAB4E893D760"[s==t::2]

And another 4 bytes shorter if you're willing to switch to Python 2. (cmp is not available in Python 3)

@ovs Thanks. I've incorporated your first idea. I also improved the solution so that using cmp no longer has advantages.

You can use str.find instead of str.index to save one byte. The only behaviour difference between the two methods is that index throws an error when the element isn't found, while find returns -1. So it won't be an issue for your code.

126 bytes by using a common string. (But there's probably a better way of merging them together.)

@Arnauld Thank you. I've incorporated the idea and updated the answer.

@ovs You can save quite a bit in Python 2 using cmp: Try it online! (with the new solution).

Some of these templates for the difference of parallel expressions might be of interest.

@xnor That's a clever use of cmp. Unfortunately the difference trick cannot be easily applied in this case because an unpacking is needed before evaluating the expression.

x86-16 machine code, 87 83 bytes
Binary:
00000000: e807 0050 e803 005a 3ac2 ad2c 3092 ad2c  ...P...Z:..,0..,
00000010: 30bb 3501 3af4 7503 bb3f 01e8 0a00 92e8  0.5.:.u..?......
00000020: 0600 f6e2 d40a d7c3 b106 bf49 01f2 aee3  ...........I....
00000030: 038a 4504 c312 0a10 0611 0c0f 0a0e 070d  ..E.............
00000040: 030b 020b 0509 0408 0124 1a21 1b11 0003  .........$.!....
00000050: 0808 09                                  ...

Unassembled:
E8 010A         CALL GET_HAND           ; score first hand, ranked score into AL
50              PUSH AX                 ; save score
E8 010A         CALL GET_HAND           ; score second hand
5A              POP  DX                 ; restore first hand into DL
3A C2           CMP  AL, DL             ; compare scores - result in CF, OF and ZF
            GET_HAND:                   ; 4 char string to ranked score ("9s7c" -> 6)
AD              LODSW                   ; load first card string
2C 30           SUB  AL, '0'            ; ASCII convert
92              XCHG DX, AX             ; store in DX
AD              LODSW                   ; load second card string
2C 30           SUB  AL, '0'            ; ASCII convert
BB 0139         MOV  BX, OFFSET R       ; first, point to non-suited table
3A F4           CMP  DH, AH             ; is it suited?
75 03           JNZ  NO_SUIT
BB 0143         MOV  BX, OFFSET RS      ; point to suited table
            NO_SUIT:
E8 012C         CALL GET_VALUE          ; get face card value in AL
92              XCHG DX, AX             ; swap first and second cards
E8 012C         CALL GET_VALUE          ; get face card value in AL
F6 E2           MUL  DL                 ; multiply values of two cards
D4 A0           AAM                     ; AL = AL mod 10
D7              XLAT                    ; lookup value in rank score table
C3              RET                     ; return to caller
            GET_VALUE:                  ; get value of a card (2 -> 2, J -> 3, A -> 9)
B1 06           MOV  CL, 6              ; loop counter for scan
BF 014D         MOV  DI, OFFSET V       ; load lookup table
F2/ AE          REPNZ SCASB             ; scan until match is found
E3 03           JCXZ NOT_FOUND          ; if not found, keep original numeric value
8A 45 04        MOV  AL, BYTE PTR[DI+4] ; if found, get corresponding value
            NOT_FOUND:
C3              RET                     ; return to program

R    DB   18, 10, 16, 6, 17, 12, 15, 10, 14, 7     ; unsuited score table
RS   DB   13, 3, 11, 2, 11, 5, 9, 4, 8, 1          ; suited score table
V    DB   'J'-'0','Q'-'0','K'-'0','A'-'0','T'-'0'  ; face card score table
     DB   3, 8, 8, 9, 0

Input is as a string such as Js3sKsKh, at pointer in SI.  Output is ZF = 0 and SF = OF (test with JG) if player 1 wins, SF ≠ OF (test with JL) if player 2 wins or ZF (test with JE) if a draw.
Output using DOS test program:

05AB1E, 41 37 bytes
•V›{₆Ÿ&∊WÍj¸•19вyεø`Ës‘ßŒQ‘ŽćS‡Pθ«}èÆ

-4 bytes thanks to @Grimy.
Input as a list of list of list of characters, like the third example input format in the challenge description. I.e. P1 7c Qh & P2 8s Ks would be input as [[["7","c"],["Q","h"]],[["8","s"],["K","s"]]]. (And uses "10" for 10.)
Outputs a negative integer if player 1 wins; a positive integer if player 2 wins; or 0 if it's a draw.
Try it online or verify all test cases.
Explanation:
•V›{₆Ÿ&∊WÍj¸•  # Push compressed integer 36742512464916394906012008
 19в           # Convert it to base-19 as list:
               #   [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
Iε             # Push the input, and map each of its hands to:
  ø            #  Zip/transpose the hand; swapping rows/columns
               #   i.e. [["8","s"],["K","s"]] → [[["8","K"],["s","s"]]
   `           #  Push them separated to the stack
    Ë          #  Check if the two suits in the top list are equal (1/0 for truthy/falsey)
    s          #  Swap to get the list with the two values
     ‘ßŒQ‘     #  Push dictionary string "JAKEQ"
     ŽćS       #  Push compressed integer 39808
     ‡         #  Transliterate these characters to these digits
      P        #  Now take the product of the two values in the list
       θ       #  Only leave the last digit (basically modulo-10)
    «          #  And merge it to the 1/0
               #  (now we have the hand values of both players,
               #   where instead of a trailing "s" we have a leading 1)
 }è            # After the map: index each value into the earlier created integer-list
               # (now we have the hand rank of both players)
   Æ           # And then reduce the resulting integers by subtracting
               # (after which the result is output implicitly)

See this 05AB1E tip of mine (sections How to use the dictionary? How to compress large integers? and How to compress integer lists?) to understand why •V›{₆Ÿ&∊WÍj¸• is 36742512464916394906012008, •V›{₆Ÿ&∊WÍj¸•19в is [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1], ‘ßŒQ‘ is "JAKEQ", and ŽćS is 39808.

The question explicitly allows taking input T as 10, so you can just drop the T from JTQKA (and use compressed integer 3889 instead of 30889). Also, T* ... + could be ... «.

@Grimy Ah, I indeed knew 10 instead of T is allowed, but didn't think about $10n\bmod 10 = 0$! And T*...+ being ...« is obvious now that I see it.. >.> Thanks!

37 (now actually works!)

@Grimy Ah, nice use of the dictionary like that!

Nibbles, 31 27  bytes
`/.$=+*`*.`'$`r:`#$10$~,`$$`D22-859ff1e2379fa8205a46a3

Thats 32 nibbles of code followed by a number that is stored as 22 hex digits. Making 54 half byte instructions in the binary form. (Nibbles isn't on TIO yet).
I found this to be a pretty cool problem. My first instinct was rather than hardcode the hand orders, calculate it! By finding how common each is, but this turned out to be longer surprisingly.
It works by converting each hand to an integer 1-20 and then looking it up it up in a table to find its relative goodness. Finally those goodnesses are subtracted so that equal hands are 0, player 1 wins positive, and player 2 wins negative.
Let's break down the code:
`D 22 859ff1e2379fa8205a46a3

becomes that data in base 22, which is
[5,0,18,8,7,2,19,12,7,1,14,6,9,3,15,8,10,4,20,11]

This code just maps on each hand and does a fold on the result
`/      special fold
  .$    map on input (for each hand)
    ...
  -     subtract (the type of special fold)

Now for the code that converts hand to a unique number for that suitedness and mod10. Multiply the product by 2 to make space for the suitedness value of 1 or 2 without conflict (this is similar to other solutions).
+
 * [product mod 10]
  ~     2
, `$ $  length of the unique suites

To calculate the hand value mod 10:
`*             product
  .            map
   `' $        transpose of input hand [("J",'c'), ("10",'d')] becomes
               (["J","10"],"cd") and since this is a tuple, it returns
               the first value, setting $ to be "cd" (used later)
   `r          read a number from a string in base 10
     :         list concat of
      `# $ 10  hash of the hand value mod 10 (this is to convert JQKA)
      $        the hand value string

Finally this is looked up in the table by just looking up the value at an index with =
There's a couple of cool tricks here. One is how the hash value becomes the right answer mod 10. It uses the data as salt, but the data is also being used to extract our table. This is why the table was in base 22 when we only needed base 20. It gave us some degrees of freedom to brute for search for different representations that will still give the right answer. On average we need about 10000 degrees of freedom. Since JQKA all have to go to the correct number (1/10 chance each).
This was found with brute force search using this code:
.| . | `*.,4`,21 ==\$`<@  # n-b=18
    `@ 22
    ..%"13,18,3,10,11,16,2,6,11,17,5,12,9,15,4,10,8,14,1,7" ',' - 18`r$
    +- 5 ?:@0~ +-@$1 $

 ==."JQKA"
  `#~ : o$ @ 10
:3:8:8 9
hex$

Another cool trick is how the card value is parsed. Essentially what we want to do is say if it is an integer than use its value, otherwise the hash value. But it is shorter to just always put the hash in front of the value and parse the result. Like so: "J" -> "3J", "5" becomes "[something]5". In the first case the J is ignored because it isn't a digit. In the second case the [something] doesn't matter because the complete value is still 5 mod 10.
Also note that we don't actually ever need to do mod 10 on the product because the size of the table we are looking is size 20 and wraps (and we've multiplied by 2).
To invoke it pass the hands as command line args. List of List of tuple of Str, Char.
For example:
nibbles hardcode.nbl "[[(\"7\",'c'),(\"Q\",'h')],[(\"8\",'s'),(\"K\",'s')]]"

This problem shows off the power of a deterministic hash function already, but there's a cool idea that could improve it further but it would be computationally intractable unless the hash function can be reversed without using brute force!
The idea is rather than look up the hand in a list of goodnesses, take the hash of it. You just need to find salt that happens to give the right ordering (it doesn't have to use values 0-17).
This would be shorter because the current encoding takes
log(18)*20=83 bits but the new one would be
log(18!)+log(n)*2+log2(n^18*(n-18)!/n!)

Where n is the base to use in the hash mod. The higher it is the less likely you'll have collisions, but also the less likely you'll manage to get those two hands that are equivalent to map to the same value. This value is maximized by n being 117, giving 68 bits (but really n is another degree of freedom in the search so it could be fewer bits).
This would lead to a 2 byte savings on average! (In data alone, not counting the degrees of freedom for n, you also wouldn't need the * ~ and = instructions).
The ultimate reason less information is needed is because a list stores exact values but all we really need is an order.
This problem has inspired me to try to design a hash function that can be reversed so that a solution like this (and others for other problems) can be realized without brute force. It has gotten pretty mathy, especially when the base we are talking about isn't a prime number, but it is something I intend to revisit and hopefully write a paper and add it into nibbles!

Nice! Computing the hand orders rather than storing it is actually the approach that I was expecting when I wrote this challenge -- at least in some languages.

PHP, 212 185 178 149 bytes
while($p=$argv[++$x])$$x=ord(rjpfqlojngmckbkeidha[(($v=[J=>3,Q=>8,K=>8,A=>9])[$p[0]]?:$p[0])*($v[$p[2]]?:$p[2])%10+($p[1]==$p[3])*10]);echo${1}-${2};

Try it online!

-7 bytes thanks to @Night2!
-29 bytes by ASCII encoding the table instead of array

Input is via command line.  Output to STDOUT is negative if player 1 wins, positive if player 2 wins, 0 if tie.  Example:
$ php modten.php Js3s KsKh
-1

@Night2 I suppose if I was willing to give us the spaceship operator (I mean, how often do you get to use that?), I could -2 bytes and just return negative, positive or zero, instead of -1, 1 or 0.

I was amazed (in a good way) to see the spaceship operator in previous answer.

C (gcc), 172 167 165 164 162 bytes
char*v="T 23456789   J    QA        K";p(char*l){return"A<92?:51@:;4>893=760"[(l[1]==l[3])+(index(v,l[2])-v)*(index(v,*l)-v)%10*2];}f(char*s){return p(s+5)-p(s);}

Try it online!
4 bytes shaved off thanks to the amazing @ceilingcat!
Basically a port of @Joel's Python3 solution, but without the base18 encoding. Expects the input as one string with a space separating the hands of the two players, and outputs an integer that is positive, negative or zero to indicate player 1 wins, player 2 wins or if it's a draw.

Perl 6, 101 100 94 88 bytes
-1 byte thanks to Jo King
{[-] .map:{'HC92FA51GAB4E893D76'.ords[[*](.[*;0]>>.&{TR/JQKA/3889/})%10*2+[eq] .[*;1]]}}

Try it online!
Takes input as f(((<J ♠>, <3 ♠>), (<10 ♠>, <K ♥>))) using 10 for Ten. Returns a value < 0 if player 1 wins, > 0 if player 2 wins, 0 if it's a draw.
Explanation
{
  [-]  # subtract values
  .map:{  # map both hands
    'HC92FA51GAB4E893D76'.ords[  # lookup rank in code point array
      [*](  # multiply
        .[*;0]  # card ranks
        >>.&{TR/JQKA/3889/}  # translate J,Q,K,A to 3,8,8,9
      )
      %10*2  # mod 10 times 2
      +[eq] .[*;1]  # plus 1 if suited
    ]
  }
}

Jelly, 46 bytes
“T0J3Q8K8A9”yⱮZV€P$Eƭ€)%⁵UḌị“©N¿!Æßvṅ?żṀ’b18¤I

Try it online!
A full program taking as its argument for example ["7h","Ks"],["4s","Ts"] and printing zero if both players draw, positive if player 1 wins and negative if player 2 wins.

Charcoal, 97 bytes
≔”)¶＆sＮψU↓”ζＦ¹³Ｆ¹³Ｆ⁻⁴⁼ικ⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ≔”A↘τ[⁵ＰkxτG”ε≔⁰δＦ⟦θη⟧≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδＩδ

Try it online! Link is to verbose version of code. Takes input as two strings of 4 characters e.g. QcKc 6d4d and outputs a signed integer. Explanation:
≔”)¶＆sＮψU↓”ζ

Compressed string 2345678903889 represents the card values.
Ｆ¹³Ｆ¹³

Loop over each possible pair of values.
Ｆ⁻⁴⁼ικ

Loop over each possible second card suit. Without loss of generality we can assume that the first card has suit 3, so the second card suit can range from 0 to 3 unless the values are the same in which case it can only range from 0 to 2.
⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ

Compute the modified score of the hand, which is the value of the hand doubled, plus 1 if the suits are the same (i.e. the second card has suit 3).
≔”A↘τ[⁵ＰkxτG”ε

Compressed string 23456789TJQKA represents the card characters. The input cards are looked up in this string and then the position is used to index into the first string to get the card's value.
≔⁰δ

Initialise the result to 0.
Ｆ⟦θη⟧

Loop over the two hands.
≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδ

Calculate the modified score of the hand, and thus its frequency, and subtract the result from this.
Ｉδ

Output the frequency difference.

C# (Visual C# Interactive Compiler), 139 bytes
x=>x.Sum(n=>(i++%2*2-1)*(n[1]==n[3]?"":" ")[n.Aggregate(1,(a,b)=>a*(b>85?1:b>83?0:b>74?8:b>73?3:b>64?9:b-48))%10]);int i

Try it online!

Perl 5 -p, 107 bytes
$a=A;y/ATJQK/90388/;${$a++}=substr"IAG6HCFAE7D3B2B59481",($1eq$3).$&*$2%10,1while/.(.) (.)(.)/g;$_=$A cmp$B

Try it online!
Input:
As 4d,Th 8c

(Actually, the comma can be any character.)
Output:
-1  Player one wins
 0  Draw
 1  Player two wins


text:
The Knight's estate
And then the King said: You fought bravely, Knight, and your deed will not be forgotten for centuries. For your valor I grant you this castle and the lands around it. Things rush me, and I can not take you to the castle. Therefore, I will give you the way from this place to the castle. Now go and come back after the deadline. - as it is written in the Green Book of Years.
In addition, it is known from the Green Book of Years that the lands with which the castle was granted were in the shape of a circle. The king was very wise and, in order to avoid unnecessary proceedings regarding the right to land, always granted only areas of land on the map that have a convex shape.
Recently, historians have had information about where the castle was located and where this historical conversation took place. They want to know how much land did the Knight get on the assumption that the road to the castle was perfectly straight.
Explanation
The following figure shows in light gray the territory originally granted to the knight, and in dark gray, the one that came to him as a result of the king giving him the way.

Input
The first line of the input contains two floating-point numbers: xk and yk - the coordinates of the place where the dialogue took place. The second line contains three floating-point numbers: xc, yc and rc - the coordinates of the castle and the radius of the circle that bounds the land granted with it.
Output
Print one floating-point number - the area of the land obtained by the Knight, with an accuracy of at least three characters after the decimal point.
Tests
Input    Output
2 5       5.69646

2 1 1

3 9       80.7130

2 3 5

1 3       3.141

1 2 1

Note: A triangle may not include the entire semicircle if it is too close to the center, as in the test I have given.

Hi there! Please consider using The Sandbox for your challenges. I've read this several times and I'm not sure what area we're supposed to find. The dark grey? The light grey? The sum of those regions?

Please also avoid excessively long backstories. In this case, because the challenge refers back to the backstory, it actually hinders your challenge. :-(

@Giuseppe The sum of those regions.

@Giuseppe A triangle may not include the entire semicircle if it is too close to the center (as in the test I have given).

Can you please provide examples with a radius unequal to 1?

Can you also please provide examples where the traveled distance lies within the circle?

Also, the triangle will never, ever include the entire semicircle, unless the radius is infinite, which it cannot be.

Why is the outcome of the third test case not 3.141?

Also, your challenge should be understandable if you deleted the backstory, as people normally skip the backstory

@Joel Oh, I'm sorry, thanks for mentioning.

@MilkyWay90 I cut off unnecessary parts of the backstory, leaving only the needed ones.

A note about trying to use "real numbers" for input.  It is not possible to have a program that can accept a real number, this is because there are more real numbers than there are finite binary strings.  You likely mean something other than a real number and it would be good if you said what.  It seems like most people have taken this to mean floats.

I'm more worried about the "decimals". Are the last three values supposed to be integers?

@G.Sliepen No. I edited to make it more clear.

@SriotchilismO'Zaic Edited.

Wolfram Language (Mathematica), 51 bytes
Area@ConvexHullMesh[CirclePoints[##2,7!]~Append~#]&

Try it online!
                    CirclePoints[##2,7!]            (* generate 5040 points on the perimeter of the circle *)
                                        ~Append~#   (* append the point at the end of the way, *)
Area@ConvexHullMesh[                             ]& (* and find the area of the convex hull of those points *)

JavaScript (ES7), 76 bytes
Port of Jitse's answer.
with(Math)f=(X,Y,x,y,r,h=hypot(X-x,Y-y))=>r*(r*(PI-acos(r/h))+(h*h-r*r)**.5)

Try it online!

I borrowed your argument names for clarity

@Jitse Sounds fair enough since I borrowed your entire logic. :p

Friendly reminder that I made a mistake in the calcualtion of the triangle's area. It worked because the radius in the example is 1.

It's been a while but +1 for with - always +1 for with!

Python 3, 107 bytes
from math import*
def f(X,Y,x,y,r):d=hypot(X-x,Y-y);return(r>d)*pi*r*r or(pi-acos(r/d))*r*r+(d*d-r*r)**.5*r

Try it online!
-3 bytes thanks to Arnauld
-4 bytes thanks to squid
-5 bytes thanks to Greg Martin
Explanation
First, we calculate the traveled distance between both coordinates using the Pythagorean theorem. Let's call it d.
Then, we construct a rectangular triangle between coordinate 1, coordinate 2 and the point on the circle where it meets with the straight line. Using the Pythaogrean theorem again, the area of this triangle is given by $$\frac{1}{2}\times\sqrt{d^2-r^2}\times r$$
where d is the distance between the coordinates and r is the radius of the circle. Since we have two of those triangles, this area is resembled in the code by (d*d-r*r)**.5*r
Next, we need to calculate the remaining area of the circle. A circle's area is given by $$ a = \pi\times r^2$$
However, part of the circle is already taken into account. The angular fraction of the circle that is already described by the triangles is given as $$\cos^{-1}(r/d)$$
so that the remaining area in the circle can be described by (pi-acos(r/d))*r*r.
And then some code juggle to make it as short as possible.
Except...
when the traveled distance lies within the circle. Then just return the circle area.

I think you forgot the case, when X-x and Y-y are 0. In this case, there is division by zero.

@VerNick Ah yes, you're right. It fails if the traveled distance lies within the circle. Fixed now.

BTW, a very good explanation, might be useful for those code golfers, that are not very good with geometry ;-)

Shouldn't it be r*r>d rather than r>d?

If you change acos(r/d**.5) to acos(max(1,r/d**.5)) (if that's the right syntax), then you don't need to or the return computation at all ... this saves 8 bytes or so. I don't know whether this works when d=0; if there's an arcsecant function, it can be applied to d**.5/r to get around this.

Also, hypot(X-x,Y-y) should calculate d**.5 directly, saving some additional bytes.

@GregMartin I need some sort of evaluation to avoid a ZeroDivisionError, so max( ... ) will not work, sadly. I'll try to find a solution with arcesant. Not sure if it is readily available though. Thanks for the hypot( ... ) suggestion!

@Joel you're right. Fixed by using hypot.

Ok, let's try this: use the fact that $$\cos^{-1}(r/d) = \tan^{-1}(\sqrt{d^2-r^2}/r).$$ So you could set $$e=\max{0,\sqrt{d^2-r^2}}$$and replace the acos(r/d) with atan(e/r) and the last summand with +e*r. This should allow deletion of (r>d)*pi*r*r or while avoiding division by 0. (Can we assume that r is never zero...?) And then d is never called other than in the definition of e, so that can be golfed as well.

@Greg Martin See my solution

Jelly, 33 bytes
½÷@ÆAØP_×²}
I²SḢ_²}½×ʋ+çɗṛ²×ØPʋ>?

Try it online!
Port of @jitse’s Python answer so be sure to upvote that one! A full program taking as its arguments [[xk, xc], [yk, yx]] and r.

Python 3, 96 bytes
from math import*
def f(X,Y,x,y,r):t=max(hypot(X-x,Y-y)**2/r/r-1,0)**.5;return(t-atan(t)+pi)*r*r

Try it online!
In Python 3.8, the solution can be further improved using assignment expressions:
Python 3.8 (pre-release), 91 bytes
lambda X,Y,x,y,r:((t:=max(hypot(X-x,Y-y)**2/r/r-1,0)**.5)-atan(t)+pi)*r*r
from math import*

Try it online!
-2 bytes thanks to @Jitse
This solution is based on a bit more math manipulation of the formula. Let \$\theta\$ be the size of common angle of each triangle and its corresponding sector. The area of each triangle equals to \$\frac{1}{2}\times r\tan{\theta}\times r\$ and the area of the common sector of the triangles and the circle equals to \$\theta\times r\times r\$. Hence, the total area $$S=\tan{\theta}\cdot r^2 +\pi r^2-\theta r^2=(\pi+\tan{\theta}-\theta)r^2$$
We define \$t\$ to be $$t=\tan{\theta}=\frac{\sqrt{d^2-r^2}}{r}=\sqrt{\frac{d^2}{r^2}-1}$$
Here, \$d\$ is the distance between the two given coordinate pairs. Then we have $$S=(\pi+t-\arctan{t})r^2$$

Welcome to Codegolf! You have a nice approach to this problem. It is very clear and consise. Since your lambda function is not recursive, you can make it anonymous and save 2 bytes like so: Try it online!

@Jitse Thanks for the suggestion. The rules here are unclear to me and I cannot find the answer about this in other posts. I understand that one-line solutions using lambdas are accepted because the whole code block returns a function that can be applied to the arguments (i.e. (#code#)(arg1, ...)). However, when the program has multiple lines, the whole code block can no longer be used as a single function. In this case, do the returned functions need to be named (for later reuse) or not?

As long as you make the import statement before defining your function, it can still be called using (lambda s: [do something])(s). Therefore, the consensus is that it is still valid to leave it anonymous, so long as you don't need to refer to it from within your core code. In this case, you only need to name it to demonstrate its functionality. Due to the way that TiO counts characters, the easiest approach is to define the funtion name in the header and import other stuff afterwards. For demonstration purposes, it doesn't really matter.

You can find more basic golfing rules for Python here and in other meta threads.

Thanks much for the clarification. I've updated the answer.

C (clang), 111 103 93 bytes
float f(X,x,r)_Complex X,x,r;{X=cabs(X-x)/r;return(4*atan(1)-atan(X=csqrt(X*X-1))+X)*r*r;}

Try it online!
It's 90 bytes for the code, but +3 bytes because we need to pass -lm to the compiler.
Thanks to @ceilingcat for shaving off 12 bytes, and the brilliant use of csqrt() inspired me to take the coordinates as complex numbers, to shave off another 10 bytes.


text:
Church Subtraction
Church Subtraction
Lambda calculus has always been a fascination of mine and the emergent behaviors of passing functions into each other is delightfully complex. Church numerals are representations of natural numbers contructed from the repeated application of a function (normally the unary addition of a constant). For example, the number zero returns x and "ignores" the input function, one is f(x), two is f(f(x)) and so on:
ident = lambda x: x
zero = lambda f: ident
succ = lambda n: lambda f: lambda x: f(n(f)(x))
one = succ(zero)
add1 = lambda x: x + 1
to_int = lambda f: f(add1)(0)
print(to_int(one))
>>> 1

From this we can easily see that addition is accomplished by applying the first function to x then applying the second function to x:
add = lambda m: lambda n: lambda f: lambda x: n(f)(m(f)(x))
print(to_int(add(one)(two)))
>>> 3

Addition is relatively easy to understand. However, to a newcomer it might be inconceivable to think of what subtraction looks like in a Church encoded number system. What could it possibly mean to un-apply a function?
Challenge
Implement the subtraction function in a Church encoded numeral system. Where subtraction performs the monus operation and unapplies a function n times if the result will be greater than zero or zero otherwise. This is code-golf so shortest code wins.
Input
Two Church numerals that have been encoded in your choice of language. The input can be positional or curried. To prove these are true Church numerals they will have to take in any function and apply them repeatedly (add1 is given in the examples but it could be add25, mult7, or any other unary function.)
Output
A Church numeral. It should be noted that if m < n then m - n is always the same as the identity function.
Examples:
minus(two)(one) = one
minus(one)(two) = zero
...

also acceptable:
minus(two, one) = one
minus(one, two) = zero

Credit:
This github gist for giving me a python implementation of Church Numerals.

(The comment in the gist is wrong; exp(m, n) calculates m^n of course.)

I'm not sure what you mean that "the input can be positional or curried". Is it OK to define the main function as lambda m,n,f:apply f m-n times (or even lambda m,n,f,x:apply f m-n times to x) instead of lambda m,n:lambda f:...? Or does this just apply to the two inputs m and n?

Also, may we take the arguments m and n in the other order? This would help with currying.

@xnor as long as you can prove it subtracts two church numerals then you can take the inputs anyway you want.

Haskell, 35 bytes
(r%s)f x=s(x:)(iterate f x)!!r(+1)0

Try it online!
Say that r and s are the church encodings of m and n. We want r%s to apply f m-n times to some initial value x. We first generate the infinite list
iterate f x = [x, f x, f (f x), f (f (f x)), ...]

then use s(x:) to prepend n copies of x, that is, shift each value n indices right:
s(x:)(iterate f x) = [x, x, x, ...,  x, f x, f (f x), f (f (f x)), ...]

We then compute m directly as r(+1)0, and take the m'th element of that list as !!r(+1)0. An indexing-free solution could instead do head$r tail$..., that is drop the first element m times and then take the first element, but the indexing syntax is much shorter.
Note that the classic solution doesn't work in Haskell without extensions because its strong typing can't represent the predecessor operation.

Python 2, 82 80 bytes
eval('!u:!v:v(!n:!f:!x:n(!g:!h:h(g(f)))(!u:x)(!u:u))(u)'.replace('!','lambda '))

Try it online!
2 bytes thx to Nick Kennedy noting an un-needed pair of parens.
Anonymous function that implements minus.
Mostly this is just compressing the definition found at the Wikipedia page; not like I truly understand the code yet. But interesting!

Based on the gist the OP mentioned, !u:!v:v(!n:!f:!x:n(!g:!h:h(g(f)))(!y:x)(!x:x))(u) seems to save 2 bytes, but I don’t really understand the code!

@NickKennedy http://gettingsharper.de/2012/08/30/lambda-calculus-subtraction-is-hard/#Why_is_this_hard if you are interested

@Ryan Schaefer: Nice "Trick"!

Python 2, 77 bytes
lambda r,s:s(lambda r:lambda f:lambda x:r(lambda(_,x):(x,f(x)))((x,x))[0])(r)

Try it online!
We do Church decrement by tracking the previous value for each iteration and outputting that at the end. 39% of the code length is "lambda"'s...

nice! I was waiting for a golfed python answer that didn't just look at the gists implementation. Have you thought about using eval like the other answer to further golf this?

@RyanSchaefer I did check eval/replace thing when I saw the other answer, but it's actually 2 bytes longer here with 5 lambdas to replace. Python is unfortunately really wordy at both defining functions and string manipulation. And it lacks a built-in "compose", which would save a layer of lambdas.

C++ (clang), 112 bytes
#define L(x,y)[&](auto x){return y;}
auto m=L(u,L(v,v(L(n,L(f,L(x,n(L(g,L(h,h(g(f)))))(L(u,x))(L(u,u))))))(u)));

Try it online!
This is by far the most incomprehensible C++ code I've ever written. That said, I think that ungolfing this code will only make it worse.

JavaScript (Node.js), 87 85 81 76 74 bytes
f=>g=>h=>x=>f(([x,[g,a]])=>[g(x),a])([x,g(a=>[x=>x,a])(f(a=>[h,a])())])[0]

Try it online! Not going to win any awards, but I thought I'd try a different approach.
a=>[h,a] is a stage that applies h, while a=>[x=>x,a] is a stage that doesn't apply h. We apply the first function f times and the second function g times. We then apply the inverse function ([f,[g,a]])=>[g(x),a] f times. This skips over the g second stages and performs f-g first stages as desired. It then remains to extract the final value.
The tuples can of course be converted to lambda functions which results in the following expression:
f=>g=>h=>x=>f(e=>e(x=>d=>d(g=>a=>e=>e(g(x))(a))))(e=>e(x)(g(a=>e=>e(x=>x)(a))(f(a=>e=>e(h)(a))())))(x=>a=>x)

Underload, 37 bytes
(~(((!())~):*^(~!:(:)~*(*)*)~^^!)~^^)

Try it online!
The inner (((!())~):*^(~!:(:)~*(*)*)~^^!) is the pred function, implemented via pairs:
(               ( start pred function )!
  (
    (!())~      ( push zero below argument )!
  ):*^          ( do that twice )!

  (             ( start pair-increasing function )!
    ~!          ( remove second argument)!
    :           ( duplicate first argument )!
    (:)~*(*)*   ( increment first return value )!
  )
  ~^^           ( run pair-increasing function n times )
  !             ( remove first in returned pair )!
)

R, 86 bytes
eval(parse(t=gsub("!(.)","function(\\1)","!u!vv(!n!f!xn(!g!hh(g(f)))(!ux)(!uu))(u)")))

Try it online!
R port of @ChasBrown’s Python answer so be sure to upvote that one too.

J, 56 bytes
c=:3 :0
t=.^:y
5!:1<'t'
)
m=.2 :'c 0>.(>:u 5!:0->:v 5!:0)0'

Try it online!
Note: -3 bytes off TIO count for m=.
Higher order functions in J are achieved using adverbs and conjunctions.  Here a church numeral is the gerund form of the adverb formed by combining the "power of" conjunction (which repeatedly applies a verb) and an integer.  The following verb c (for "create") uses J's Atomic Representation to transform an integer into such a gerund:
c=:3 :0
t=.^:y
5!:1<'t'
)

Our "minus" operator (which is a conjunction) subtracts the right gerund church numeral from the left.  It does not, however, assume any particular implementation of church numerals, including the one from our c verb.  Instead, it relies on the general definition and turns each gerund church numeral back into an adverb by inverting it with 5!:0, and then applying that adverb to the increment verb >:, and then applying that to 0.
It then subtracts and takes the maximum with 0, and applies c to get the final result: a new gerund church numeral.

Wolfram Language (Mathematica), 55 48 47 39 bytes (33 characters)
#2[(fx#[g#@g@f&][x&][#&])&]@#&

Try it online!
The  symbol is 0xF4A1, a special Mathematica code point that denotes a rightward arrow for \[Function]. See here for more explanations. This is what the code looks like in the Mathematica front end:

We can do it in 40 bytes / 32 characters, which may be shorter depending on the measurement scheme: #2[n⟼f⟼x⟼n[g⟼#@g@f&][x&][#&]]@#&
The un-golfed version is a literal translation of the classical definition of pred:
pred = n \[Function] f \[Function] x \[Function] n[g \[Function] h \[Function] h[g[f]]][u \[Function] x][u \[Function] u];
subtract[m_, n_] := n[pred][m]

which looks like this in the Mathematica front end:

This subtraction function works with the Church numerals defined with
c@0=#& &;c@n_=#@*c[n-1][#]&

(un-golfed: c[0] = Identity &; c[n_] = Function[a, a@*c[n-1][a]])
so that we have
Table[c[n][f][x], {n, 0, 6}]
(*    {x, f[x], f[f[x]], f[f[f[x]]], f[f[f[f[x]]]], f[f[f[f[f[x]]]]], f[f[f[f[f[f[x]]]]]]}    *)

and
subtract[c[7],c[5]][f][x]
(*    f[f[x]]    *)


text:
Tex Quotes(UVa 272)
Given a string, replace all left-double-quotes into two backticks and all right-double-quotes into two single-quotes.
Left-quotes means the quotes that starts a quote. Right-quotes means the quotes that ends a quote. Quotes cannot be nested. You may assume that there are an even number of double-quotes in the string.
Examples
Input:
"To be or not to be," quoth the Bard, "that
is the question".
The programming contestant replied: "I must disagree.
To `C' or not to `C', that is The Question!"

Output:
``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!''

What are left double quotes and right double quotes?

@someone Left double quotes are the quotes that begins a quote. Right double quotes are the quotes that ends a quote.

Can quotes be nested?

@someone  Nope. They can't.

Is the number of double quotes in the input guaranteed to be even?

Yes, it is supposed to be. @RobinRyder

May we assume only printable characters will be present?

Can we assume there are no nested double quotes "foo \foo "foo" foo' foo"`?

@LegionMammal978 "Can quotes be nested?" ... "@someone Nope. They can't."

Unreadable, 789 777 bytes
-12 bytes by using variable X34 rather than X6.

'""""""'""'"""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'"""'""""""'""'""'""'""'"""'""'""'""'""'""'"""""""'""'"""'"""""'""'""""""'"""'""""""""""'""""'""""""'""'""'""'"""'"""""""'""'"""'""""'""""""'""'""'"""'"""""""'"""'""""'"""""'"""""""'""'""'""'"""'""""'""""""'""'""'""'"""'""""""""'"""""""'""'""'""'"""'""""""'""'""'"""'""""""""'"""""""'""'""'"""'"""""""""'"""""""'""'""'"""'"'"""""""'"""'"'"""""""""'"""""""'"""""""'""'"""'""""'""""""'"""""""'""'"""'""""""""'"""'"'"""""""'""'""'""'""'"""'""""'""""""'"""""""'""'"""'"""'"'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'"""""""'""'""'""'""'"""

Try it online!
Displayed in variable-width font, per the traditional tribute to the language name.
I learnt Unreadable for this challenge, because it is obviously the best tool for the job. The only characters allowed in Unreadable are ' and ", so surely it is perfectly suited to a challenge which involves changing " into ''. Isn't it?
Explanation:
'""""""'""'""" assign to X2
'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""" 34 (double quote sign)
'""""""'""'""'""'""'""" assign to X5
'""'""'""'""'""'"""""""'""'""" X2+5 (apostrophe sign)
'"""""'""'""""""'"""'"""""""""" while (1+ (assign to X1 a value read from stdin, or -1 if stdin is empty) != 0)
 '"""" do 2 things
 '""""""'""'""'""'""" assign to X4
 '"""""""'""'""" the value of X2
 AND
 '"""" do 2 things
 '""""""'""'""'""" assign to X3
 '"""""""'""" the value of X1
 AND
 '"""" do 2 things
 '"""""'"""""""'""'""'""'""" while(X4 != 0)
  '"""" do 2 things
  '""""""'""'""'""'""" assign to X4
  '""""""""'"""""""'""'""'""'""" X4-1
  AND
  '""""""'""'""'""" assign to X3
  '""""""""'"""""""'""'""'""" X3-1
 end while
 AND
 '"""""""""'"""""""'""'""'""" if(X3 != 0)
  '"'"""""""'""" print X1
 else
  '" print the output of
  '"""""""""'"""""""'"""""""'""'""" if(X34 !=0)
   '"""" do 2 things
   '""""""'"""""""'""'"""'""""""""'""" assign X34=0
   AND
   '"'"""""""'""'""'""'""'""" print X5
  else
   '"""" do 2 things
   '""""""'"""""""'""'"""'""" assign X34=1
   AND
   '"'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'"""""""'""'""'""'""'""" print X5+57
 end if
end while

(Calls to X34 are actually calls to X(X5), since X5=34.)

A quoty language in a quoty challenge LOL

TeX, 54 32 bytes
For a TeX quotes replacement challenge we also need a TeX version of course!
\catcode`"13\def"#1"{``#1''}...\bye

... is the input string, so it doesn't add to the byte count.

Why not the simpler \def"#1"{``#1''}? (or \long\def if you expect a quote to cross a paragraph boundary)

For the obvious reason that I didn't think of that :-)

JavaScript (ES9), 34 bytes
Working on quoted blocks:
s=>s.replace(/"(.*?)"/gs,"``$1''")

Try it online!

JavaScript (ES6), 38 bytes
Working on each double-quote separately:
s=>s.replace(/"/g,_=>(c="'`"[s^=1])+c)

Try it online!

dotAll flag for RegExp is new feature of ECMAScript 2018, not included in ES6.

@tsh Good catch. Updated.

Retina, 13 bytes
Learning Retina quickly because for some reason I don't like Japt winning and feel like a C# solution would use regular expressions anyway. I know there is a Retina answer, but I haven't used it when creating this, and I found it (exactly) too anyway.
#2$`"
``
"
''

Try it online!

Why the hate for Japt?! :p

Jelly, 15 13 bytes
⁾``⁾''2ƭ”"Ƒ¡€

Try it online!
Full program.

Japt, 12 bytes
Would be 11 only for a limitation of (or maybe it's a bug in) Japt.
r'"È²îT°g"`'

Try it
r'"È²îT°g"`'     :Implicit input of string
r'"              :Replace double quotes
   È             :Pass each match through a function
    ²            :  Duplicate
     î           :  Replace each character with
      T°         :    Postfix increment T (initially 0)
        g"`'     :    Index into "`'" with wrapping

It's too bad you can't use Q here :\

@Oliver, I can (and I originally did); I'd just need a , too.

I mean it's too bad you couldn't simply use Q in place of '"

Python 3, 65 bytes
f=lambda s:s and(s[0],"`'"[s.count('"')%2]*2)[s[0]=='"']+f(s[1:])

Try it online!
-8 bytes thanks to Erik the Outgolfer

As for the second function, you can remove 8 bytes (it's not as different as it may seem, I just replaced the s[0].replace with an explicit s[0]=='"' check, along with some other modifications).

@EriktheOutgolfer Nice finds, thanks!

!@#$%^&*()_+, 22 21 bytes
`'("_*("+@"_*)+$!!@@)

Try it online!
Terminates with an error. 21 looks like an impressive score, beating quite a few languages including Charcoal. Inspired by this.

R, 40 bytes
cat(scan(,"",,,'"',""),sep=c("``","''"))

Try it online!
Reads string input, separating at each ", giving a vector of strings. Then pastes those strings, alternating between the double backticks and the double apostrophes as separators, recycling them as needed.
Someone will probably post a shorter R answer based on a regex... Still, this answer is more typical of R, I think.
Explanation of the scan(,"",,,'"',"") part:
scan(, # empty first parameter: read from STDIN
  "",  # type of input is a string
  ,    # default 3rd parameter nmax
  ,    # default 4th parameter n
  '"', # separate on character "
  "")  # do not treat any characters as quotations marks (necessary to handle ' in the input)

Charcoal, 23 bytes
ＷＳ⊞υι⭆⪪⪫υ¶¦"⎇κ⁺×²§'`κιι

Try it online! Link is to verbose version of code. Includes 8 bytes to avoid a cumbersome input format. Explanation:
ＷＳ⊞υι

Collect input lines until an empty line is reached.
⪫υ¶¦

Join the lines on newline characters.
⪪..."

Split the input on quotes.
⭆...

Map over each part and concatenate the results for implicit print.
⎇κ...ι

Leave the first part unchanged.
⁺×²§'`κι

Prefix the appropriate quote, doubled.

I was waiting for a Charcoal solution. Nice!

Jelly, 13 bytes
ṣ”"µJḊ⁾`'ṁḤż@

A full program.
Try it online!
How?
ṣ”"µJḊ⁾`'ṁḤż@ - Main Link: list of characters, T   e.g. ..."hi" - she "said"...
 ”"           - character '"'                           '"'
ṣ             - split (T) at ('"')                      ["...","hi"," - she ","said","..."]
   µ          - (call that X) start a new monadic chain
    J         - range of length (of X)                  [1,2,3,4,5]
     Ḋ        - dequeue                                 [2,3,4,5]
      ⁾`'     - list of characters                      ["`","'"]
         ṁ    - mould like                              ["`","'","`","'"]
          Ḥ   - double                                  ["``","''","``","''"]
           ż@ - (with reversed @rguments) zip (with X)  [["...","``"],["hi","''"],[" - she ","``"],["said","''"],["..."]]
              - implicit (smashing) print               ...``hi'' - she ``said''...

Perl 6, 23 bytes
{S:g/\"(.*?)\"/``$0''/}

Try it online!
Darn, the obvious solution is shorter. Replaces each quoted portion with a version with the appropriate quotes.
Perl 6, 24 bytes
{S:g{\"}=<`` ''>[$++%2]}

Try it online!
Replaces each double quote, alternating between the two sets of characters.

Labyrinth, (43?) 53 bytes
396"
 } "",)@
  ~"  (
 "~ 3_:
""" 4
" .;-
=   ;
..::;

Try it online!
A golfed version of this, much simpler, 92 byte program:
3 """
9 " ",)@
}96 " (
    " :_34-;;
    "     ; :
   """"""". :
   "        .
   """"""""=.

If we don't need to handle input containing the zero byte then 43 bytes:
39}9
@  6
`,""
`  "
: ."=..
_ ;   "
34-;;::

Red, 79 bytes
func[s][q:"^""parse s[any[to change[q copy t to q q](rejoin["``"t"''"])skip]]s]

Try it online!

Retina, 15 bytes
"
""
Y`"`\`\`''

Try it online! Edges out the boring Retina 0.8.2 answer by 1 byte. Explanation:
"
""

Duplicate all of the quotes.
Y`"`\`\`''

Cyclically replace the quotes with pairs of backticks and single quotes.
Boring 16-byte Retina 0.8.2 answer for completeness:
s`"(.*?)"
``$1''

Try it online!

PHP, 62 bytes
Non-RegEx solution:
for(;''<$l=$argv[1][$i++];)echo$l=='"'?["''","``"][++$j%2]:$l;

Try it online!

PHP, 48 bytes
Port of Arnauld's RegEx solution:
<?=preg_replace('/"(.*?)"/s',"``$1''",$argv[1]);

Try it online!

C (gcc), 69 68 bytes
t=39,z;f(char*s){z=*s-34?*s:257*(t^=71);printf("%s",&z);*++s&&f(s);}

Try it online!
One byte shaved off by @ceilingcat!

Haskell, 67 60 58 bytes
(#0)
('"':x)#n=["``","''"]!!n++x#(1-n)
(a:b)#n=a:b#n
x#n=x

Try it online!
The relevant function is (#0).
Since I originally thought the question also required us to convert single quotes here is a version that handles both:
Haskell, 125 bytes
(#(1<0,1<0))
('"':x)#(m,n)=last("``":["\""|m])++x#(not m,n)
('\'':x)#(m,n)=last('`':['\''|n]):x#(m,not n)
(a:x)#n=a:x#n
x#n=x

Try it online!

"\"" should be "''" (two apostrophes)

@siracusa Thanks, I assumed since you can use " in tex you could use it here.

Python 2, 57 bytes
lambda s:re.sub('"(.*?)"',r"``\1''",s,flags=16)
import re

Try it online!
Although I really like Jitse's answer.

-4 Bytes if you use inline flags instead of the flags argument: r'(?s)"(.*?)"'

(GNU) sed, 38 33 30 bytes
-4 by removing the -n flag and implicitly printing on n, -1 by reusing previous /expression/, thanks @Cowsquack. -3 by using implicit branch-to-end.
:a
s/"/``/;T
:b
s//''/;ta
n;bb

Try it online!
Try it online!
Try it online!
Some pretty basic label jumping. This can probably be golfed by a byte or two.
:a          # label a
s/"/``/;T   # replace " -> ``. If unsuccessful, move to next line
:b          # label b
s//''/;ta   # replace " (implicit) -> ''. If successful, jump to a (w/o reading new line)
n;bb        # read in the next line, but jump to label b.

Btw typically the flags used are specified in the header. You can golf a byte using https://codegolf.stackexchange.com/a/167295/41805, in addition some of the branching logic can be removed. Then making the solution work without the -n flag should save a bit more. (And of course there is the trivial sed -z solution which I presume you to have intentionally avoided)

Alright, I dug back into man sed for a bit and got to 30. Feel free to let me know anything I missed, you've got the golf experience on this lang. (Oh, -z is new to me, but I agree. I'll stay without it.)

Nicely done, I am always glad to see a sed answer

Stax, 11 bytes
û╩↕H£ñ╟Uzay

Run and debug it
Procedure:

Take all input, newlines and all.
Regex replace '"' with a block that produces alternating outputs of pairs of backticks and foreticks(?)

-1 if you take a triple quoted string?

05AB1E, 15 bytes
'"¡ā¨„'`sè2×.ιJ

Try it online!
No regexes in 05AB1E, so we split on ", make a list of alternating `` and '', then interleave the two.

Ok, looks like I don't have to fix and undelete my answer. ;)

QuadR, 14 bytes
"(.*?)"
``\1''

Try it online!
Simple find/replace using @Adám's wrapper for Dyalog APL's ⎕Replace function.
How:
"(.*?)" ⍝ PCRE, finding anything between two double quotes and assigning it to group 1
``\1''  ⍝ Transformation string, replacing the match with ``group_1''.

GolfScript, 35 34 bytes
1:c;{.34={;c)2%:c'""'"``"if}""if}%

Try it online!
Explanation
1:c;                                # Set 1 to the current item counter

    {                            }% # Map for every character in the input:
     .34=                      if   #     If the character isn't the quote,
                             ""     #         Just leave it alone
         {                  }       #     Otherwise:
          ;                         #         Remove the copy of the input
           c):c                     #         Increment the counter
                2%        if        #         If the counter isn't divisible by 2,
                  '""'              #             Output the double-quote
                      "``"          #         Otherwise: Output the double backtick

Vyxal Ṡs, 18 bytes
\"Ẇƛ\"=[&›¥₂[\'|\`

Try it Online!
\"Ẇ                # Split on ", keeping delimiter
   ƛ               # Map...
    \"=[           # If a "
        &›         # Increment the register
          ¥₂[      # If even...
             \'    # Single quote,
               |\` # Else backtick.

Lua, 36 bytes
print((...):gsub('"(.-)"',"``%1''"))

Try it online!
Wow, only two chars longer than js solution.

Perl 5 -p0, 19 bytes
s/"(.*?)"/``$1''/gs

Try it online!

Java 8, 40 bytes
s->s.replaceAll("\"([^\"]+)\"","``$1''")

Try it online.
Explanation:
s->                             // Method with String as both parameter and return-type
  s.replaceAll("\"([^\"]+)\"",  //  Replace all these matches,
               "``$1''")        //  with this replacement

Regex explanation:
 "([^"]+)"                      // MATCH:
 "                             "//  A literal "
   [^"]+                       "//  Followed by 1 or more non-" characters
  (     )                       //  (captured in capture group 1)
         "                     "//  Followed by a literal " again

``$1''                          // REPLACEMENT:
``                              //  Literal ``
  $1                            //  Followed by the match of capture group 1
    ''                          //  Followed by a literal ''

Wren, 91 bytes
Fn.new{|n|
var c=1
for(i in n.split("\"")[1..-1])System.write(((c=-~c)%2==0?"``":"''")+i)
}

Try it online!
Explanation
Fn.new{|n| // New anonymous function
var c=1    // Set the index counter as 1
for(i in n.split("\"")                                                 // For each over n splitted with quotes
                      [1..-1])                                         // Get rid of the first quote
                              System.write(                          ) // Output this to the console
                                           (
                                            (c=-~c)                    // Increment the counter
                                                   %2==0?"``"          // If that's divisible by 2, output a backquote
                                                             :"''"     // Otherwise, output a frontquote
                                                                  )+i  // Join the result with i
}