text:
Stackable sequences
You deal cards labeled 0 to 9 from a deck one a time, forming stacks that start at 0 and count up by 1.

When you deal a 0, you place it on the table to start a new stack.
When you deal any other card, you stack it atop a card that's exactly
one lower in value, covering it. If there's no such card, the deck isn't stackable.

Given a deck, determine whether it can be stacked when dealt in the order given. Equivalently, given a list of digits, decide whether it can be partitioned into disjoint subsequences each of the form 0,1,..,k
Example
Take the deck 0012312425. The first two cards are 0, so they go on the table:
Stacks: 00

  Deck: 12312425

Next, we deal a 1, which goes on a 0, doesn't matter which:
        1
Stacks: 00

  Deck: 2312425

We then deal a 2 atop the just-placed 1, and the 3 on top of it.
        3
        2
        1
Stacks: 00

  Deck: 12425

Next, the 1, 2 and placed atop the first stack and 4 atop the second one.
        4
        3
        22
        11
Stacks: 00

  Deck: 25

Now, we need to place a 2, but there's no 1 atop either stack. So, this deck was not stackable.
Input: A nonempty list of digits 0-9, or a string of them. You can't assume that 0 will always be in the input.
Output: One of two distinct consistent values, one for stackable sequences and one for non-stackable ones
Test cases:
Stackable:
0
01
01234
00011122234567890
012031
0120304511627328390

Not stackable:
1
021
0001111
0012312425
012301210
000112223

For convenience, as lists:
[0]
[0, 1]
[0, 1, 2, 3, 4]
[0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 0]
[0, 1, 2, 0, 3, 1]
[0, 1, 2, 0, 3, 0, 4, 5, 1, 1, 6, 2, 7, 3, 2, 8, 3, 9, 0]

[1]
[0, 2, 1]
[0, 0, 0, 1, 1, 1, 1]
[0, 0, 1, 2, 3, 1, 2, 4, 2, 5]
[0, 1, 2, 3, 0, 1, 2, 1, 0]
[0, 0, 0, 1, 1, 2, 2, 2, 3]

Grouped:
[[0], [0, 1], [0, 1, 2, 3, 4], [0, 0, 0, 1, 1, 1, 2, 2, 2, 3], [0, 1, 2, 0, 3, 1], [0, 1, 2, 0, 3, 0, 4, 5, 1, 1, 6, 2, 7, 3, 2, 8, 3, 9, 0]]
[[1], [0, 2, 1], [0, 0, 0, 1, 1, 1, 1], [0, 0, 1, 2, 3, 1, 2, 4, 2, 5]]

Leaderboard:

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

Can we assume a limit on the list length?

@orlp No explicit limit.

@xnor he's probably asking to justify writing int a[99] in C

@LuisMendo You may, I say "nonempty".

@xnor Ah, sorry, I didn't see that. Can the array be 1-based? That is, numbers from 1 to 10

@LuisMendo Nope, 0 through 9.

Can we assume there's a 0 in the array?

@EriktheOutgolfer No, for example the test case [1].

@xnor I'll clarify that. EDIT: done.

Python 2, 45 43 bytes
-2 bytes thanks to @TFeld

s=[]
for c in input():s+=c,-1;s.remove(c-1)

Try it online!

Husk, 9 bytes
Λ¬ḞS:o-→ø

Try it online!
Returns 1 for stackable decks and 0 for non-stackable decks.
It looks like Ørjan Johansen in his Haskell answer already came up with the same algorithm, but in Husk this is obviously much more concise.
Explanation
We takle the problem from another side: flip the deck and make descending piles. If after going through all the deck all the piles have a 0 on the top, the deck is stackable.
Λ¬ḞS:(-→)ø
         ø    Starting with the empty list (each element of this list will be the top card
              of a stack)
  ḞS          Traverse the input from right to left. For each card:
      -→        Remove the successor of this card from our list (if present)
    :           Add this card to our list
Λ¬            At the end, check if all the cards in our list are zeroes (falsy)

Haskell, 55 bytes
An anonymous function taking a list of integers and returning a Bool.
Usage: (all(<1).foldr(?)[]) [0,1,2,3,4].
all(<1).foldr(?)[]
m?l|(p,r)<-span(/=m+1)l=m:p++drop 1r

Try it online!
How it works

foldr(?)[] folds its list argument from right to left using ?, starting with an empty list. The result is the list of numbers in the list that didn't fit on top of a previous number.
all(<1) tests if the only numbers not fitting on top of a previous number are zeroes.
m?l prepends a number m to a list l of non-fitting numbers. If m+1 is already in the list, it can now be removed as it fits on top of m.

(p,r)<-span(/=m+1)l splits the list l into two parts p and r at the first instance of the number m+1. If there aren't any, the right part r will be empty.
m:p++drop 1r prepends m to the split parts. If r is nonempty, then it must start with m+1, which is removed by drop 1.

Great idea doing the stacking in reverse! I tried expanding out your ? recursively, but got the same length.

54 bytes with Data.List.delete

Jelly, 15 11 bytes
‘Ṭ€+\I>0FS¬

Try it online!

Oh very nice. Would ‘Ṭ€+\I>0FṀ work always?

@JonathanAllan Well, given the rule of 2 consistent values it should.

Retina, 42 bytes
O$#`(.)(?<=(\1.*?)*)
$#2
.
$*1,
^(,|1\1)+$

Try it online!
Explanation
O$#`(.)(?<=(\1.*?)*)
$#2

This sorts the digits, stably, by how often that same digit has occurred before. In effect, this collates the various candidate subsequences together. The resulting string will first have the first occurrence of each digit, and then the second occurrence of each digit and so on. In a stackable input, the result will look something like 0123...0123...0123..., where each of these substrings may terminate at any point.
It's easiest to determine whether the input has this kind of pattern in unary.
.
$*1,

We replace each digit n by n 1s, followed by a comma to separate individual digits.
^(,|1\1)+$

Finally we make use of a forward reference to match consecutively increasing runs of digits. We try to match the entire string either by matching a single comma (representing a 0, which starts a new run) or by matching the previous thing preceded by an additional 1, which only works if the current digit is the successor of the previous one.

JavaScript (ES6), 39 bytes
-1 thanks to @tsh
a=>a.every(k=>a[a[~k]=-~a[~k],-k]--|!k)

Try it online!

JavaScript (ES6), 61 45 40 bytes
Takes input as a list.
a=>a.every(k=>a[~k]=!k|a[-k]--&&-~a[~k])

Try it online!
How?
For each value 0...9, we keep track of the number of available stacks with the preceding card atop. These counters are stored in a[-9] to a[0], where a[] is the original input array. The only counter that collides with the input data is a[0], but we don't really care about this one because 1) cards labeled 0 are always allowed and have to be processed separately anyway and 2) the input value a[0] is processed before it has a chance to be updated.
a => a.every(k =>  // given the input array a, for each card k in a:
  a[~k] =          // the card is valid if:
    !k |           //   - it's a 0 or
    a[-k]-- &&     //   - there's at least one stack with the card k-1 atop
    -~a[~k]        // in which case we allow a new card k+1 and go on with the next card
)                  // otherwise, every() fails immediately

You're faster than me :o

a=>a.every(k=>a[a[~k]=-~a[~k],-k]--|!k)

C (gcc), 74 73 bytes
f(int*l){int s[10]={},r=1;for(;~*l;s[*l++]++)r*=!*l||s[*l-1]--;return r;}

Requires the input array to mark the end with -1. Example usage:
int main(int argc, char** argv) {
    int a[] = {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 0, -1};
    printf("%d\n",  f(a));
    return 0;
}

What's wrong with plain return r?

TI-Basic (83 series), 25 bytes (49 characters)
:min(seq(min(cumSum(Ans=I)≤cumSum(Ans=I-1)),I,1,9

How it works
Takes input as a list in Ans. Outputs 1 for stackable inputs, 0 otherwise.
For each I, cumSum(Ans=I) computes a list of the number of times I has occurred in each initial segment, so min(cumSum(Ans=I)≤cumSum(Ans=I-1)) is only 1 if, at every position, we've seen I-1 at least as many times as I. The overall expression is 1 whenever this holds for each I.

Nim, 133 bytes
proc s(d:seq[int]):int=
 var
  t= @[0]
  r=1
 for c in d:(t.add(0);var f=0;for i,s in t.pairs:(if s==c:(t[i]=c+1;f=1;break));r*=f)
 r

1 if it works; 0 if it doesn't.
Had to pull some funky business to deal with mutability of variables in for-loops, oh well.

You don't need .pairs, it's called automatically.

MATL, 16 bytes
0*GQ"@yQy=f1)(]a

Input is an array of numbers.
The code outputs 1 in STDOUT if input is stackable, or exits with an error and empty output in STDOUT if input is not stackable.
Try it online!

Retina, 110 bytes
+`0((.*?)1((.*?)2((.*?)3((.*?)4((.*?)5((.*?)6((.*?)7((.*?)8((.*?)9)?)?)?)?)?)?)?)?)?
$2$4$6$8$10$12$14$16$+
^$

Try it online! Link includes test cases. I don't often get to use $16...

Mathematica, 80 bytes
Catch[Fold[#~Join~{-1}/.{{p___,#2-1,q___}:>{p,#2,q},-1:>Throw[1<0]}&,{},#];1>0]&

Python 2, 69 61 55 47 46 bytes
s=[]
for c in input():s+=-1,;s[s.index(c-1)]=c

Try it online!
Output is error/ no error.

46 bytes

R, 88 bytes
function(d){s={}
for(e in d)if(!e)s=c(s,0)else{k=match(e,s+1)
if(is.na(k))T=F
s[k]=e}
T}

Try it online!
Function that takes an R vector; returns TRUE for stackable and FALSE for unstackable.
Explanation:
function(d){
 s <- {}              # initialize the stacks as empty
 for(e in d){         # iterate over the deck
  if(!e)              # if e is zero
   s <- c(s,0)        # start a new stack
  else {              # otherwise
   k <- match(e,s+1)  # find where e should go in s, NA if not there
   if(is.na(k))       # if no match (unstackable)
    T <- F            # set T to F (False)
   s[k] <- e          # set s[k] to e
  }
 T                    # return the value of T, which is TRUE by default and only gets changed in the loop to F.
}

Jelly, 6 bytes
ċṪƊƤ⁺⁼

Try it online!
A monadic link taking a list of integers and returning 1 for stackable and 0 for not. Based on my answer to @WheatWizard’s near-duplicate puzzle.

Haskell, 53 bytes
(a:b)#x=sum[1|i<-x,a==i]:b#(a:x)
y#x=y
f x=x#[]#[]==x

Attempt This Online!
Inches out the former best Haskell answer by implementing an algorithm from my challenge which turned out to be a duplicate of this.
We implement a function (#[]) which replaces each value in a list with the number of times that value has already occurred.
If applying this function twice to a list gives back the original list it is stackable.

Nekomata + -e, 5 bytes
Oᵐ{x=

Attempt This Online!
Oᵐ{x=
O       Find a set partition such that:
 ᵐ{     For each part:
   x=     The part is equal to [0,...,length(part)-1]

Haskell, 77 75 bytes
import Data.List
g[]=1<3
g(x:r)|s<-r\\[x-1]=g r&&(x<1||s/=r&&g s)
g.reverse

Try it online! Usage: g.reverse $ [0,1,2]. Returns True for stackable inputs and False otherwise.
This is a recursive solution which traverses a given list from back to front. It implements the observation that

the empty list is stackable.
a non-empty list with prefix r and last element x is stackable if r is stackable and either x is zero or both x-1 appears in r and r with x-1 removed is also stackable.

Java 8, 168 150 142 136 bytes
a->{int x[]=new int[a.length],s=0,i;A:for(int n:a){if(n<1)s++;else{for(i=s;i-->0;)if(x[i]==n-1){x[i]=n;continue A;}return 0;}}return 1;}

-6 bytes thanks to @ceilingcat.
Returns 0/1 whether it is correctly stackable or not.
Explanation:
Try it here.
a->{                        // Method with integer-array parameter & integer return-type
  int x[]=new int[a.length],//  Array for the stacks, (max) size equal to input-size
      s=0,                  //  Amount of stacks, starting at 0
      i;                    //  Index integer
  a:for(int n:a){           //  Loop A over the input
    if(n<1)                 //   If the current item is a zero:
      s++;                  //    Increase amount of stacks `s` by 1
    else{                   //   Else:
      for(i=s;i-->0;)       //    Inner loop (2) over the stacks
        if(x[i]==n-1){      //     If a top item of a stack equals the current item - 1:
          x[i]=n;           //      Set this item in the stacks-array
          continue A;}      //      And go to the next iteration of loop A
    return 0;}}             //    If we haven't encountered a `continue`, return 0
  return 1;}                //  Return 1 if we were able to correctly stack everything

C, 248 bytes
Note: To print return status, type "echo $status" into the terminal
Return status 0: Not stackable
Return status 1: Stackable
Explanation: Increments array element with the index equivalent to the current-most digit in the stack. Then, the program checks if this just-now-incremented array element is larger than the element preceding it. If so, returns 0. Else if program makes it to the end of the array returns 1.
 main(int argc, char ** argv)
{
    static int stack[10];

    while ( *++argv != 0x0 )
    {
        stack[**argv - 0x30]++;

        if ( **argv - 0x30 > 0 )
        {
            if ( stack[**argv - 0x30] > stack[**argv - 0x30 - 1] )
            {
                return 0;
            }

        }

    }

    return 1;
}

Welcome to Code Golf! Your code and your bytecount should match, so make sure to provide a fully golfed version of your code. The ungolfed version is the optional one.

Jelly, 8 bytes
‘Ṭ€+\I’Ȧ

Try it online!
Essentially a port of my other answer, but with ‘ to handle zero-indexing

Jelly, 15 bytes
œp@ŒQẎµ0rṀ⁼Qµ¿Ẹ

A monadic link taking a list of non-negative integers and returning 0 if stackable or 1 if non-stackable.
Try it online!
How?
œp@ŒQẎµ0rṀ⁼Qµ¿Ẹ - Link: list
             ¿  - while loop:
      µ     µ   - ...condition chain:
       0        -      literal zero
         Ṁ      -      maximum of current list
        r       -      inclusive range = [0,1,2,...,max(list)]
           Q    -      de-duplicate list (unique values in order of appearance)
          ⁼     -      equal?
                - ...do:
   ŒQ           -      distinct sieve (1s at first occurrences 0s elsewhere)
  @             -      use swapped arguments:
œp              -        partition (the list) at truthy values (of the distinct sieve)
     Ẏ          -      tighten (makes the list flat again ready for the next loop)
              Ẹ - any truthy? 1 if the resulting list has any non-zero integers remaining
                -           - effectively isNotEmpty for our purposes since a list of only
                -             zeros gets reduced to an empty list via the loop.

Your move :P :P

Heh, well I doubt I'd beat 11 (or 10?!) and have to get to sleep :D

Japt, 16 bytes
£=k_¥T©°T}T=0ÃUd

Test it online! Outputs false for stackable, true for non-stackable.
Explanation
 £   = k_  ¥ T© ° T}T=0Ã Ud
UmX{U=UkZ{Z==T&&++T}T=0} Ud    Ungolfed
                               Implicit: U = input array
UmX{                   }       For each item X in the array:
                    T=0          Set T to 0.
      UkZ{         }             Remove the items Z where
          Z==T&&++T              Z == T (and if so, increment T).
                                 This has the effect of removing the largest stack.
    U=                           Reset U to the result.
                               This process is repeated U.length times, which is
                               evidently enough to handle any U.
                         Ud    Return whether there are any truthy items in U.
                               Any items not part of a stack are non-zero/truthy,
                               so this works for every possible case.

05AB1E, 25 bytes
ηε[DõQ#ZƒDNåiNõ.;Dëˆ#]¯OĀ

The challenge doesn't look all that difficult, but it's quite hard in 05AB1E (for me at least..)
Outputs 0 if stackable, and 1 if not stackable.
Try it online or verify all test cases.
Explanation:
η             # Prefixes of the (implicit) input
              #  i.e. '012031' → ['0','01','012','0120','01203','012031']
              #  i.e. `021` → ['0','02','021']
 ε            # Map each to:
  [           # Start an infinite inner loop
   D          # Duplicate the current value
    õQ#       # If it's an empty String, stop the infinite loop
   Z          # Get the maximum (without popping)
              #  i.e. '01203' → 3
              #  i.e. '02' → 2
    ƒ         # Inner loop `N` in the range [0,max]
     D        # Duplicate the current value
      Nåi     # If it contains the current digit `N`
              #  i.e. '01203' and 1 → 1 (truthy)
              #  i.e. '02' and 1 → 0 (falsey)
         Nõ.; # Remove the first one (by replacing the first `N` with an empty string)
              #  i.e. '1203' and 1 → '203'
         D    # And duplicate it again for the next iteration of the inner loop
      ë       # Else (does not contain the digit `N`):
       ˆ      # Push `N` to the global stack
        #     # And break the infinite loop
 ]            # Close the if-else, inner loop, infinite loop, and mapping (short for `}}}}`)
  ¯           # Push the global stack
   O          # Take the sum
              #  i.e. [] → 0
              #  i.e. ['2'] → 2
    Ā         # And get the trutified value of that (which we implicitly output as result)
              #  i.e. 0 → 0
              #  i.e. 2 → 1

Java 8, 87 bytes
Instead of building the stacks I just calculate if an element is unstackable on the previous elements, and return 0 when an unstackable element is encountered. If I reach the end, the entire string is stackable and 1 is returned:
s->{int l[]=new int[10];for(int n:s)if(n!=0&&l[n]>=l[n-1]||l[n]++<0)return 0;return 1;}

Try it online!
Explanation:
s->{
  int l[]=new int[10];                # initialise the counts of each digit encountered prefix of element, all initialised to 0
  for(int n:s)                        # Iterate over all entries in input
    if(n!=0&&l[n]>=l[n-1]||++l[n]<0)  # Check if the element is stackable on the previous elements. Last check is always evaluated and false, but the sideeffect is to add the element to the handled, prefixed element og the next element.
      return 0;                       # Unstackable
  return 1;                           # No unstackable elements, so the result is stackable
}

J, 25 23 bytes
{{(-:\:~"1)+/\y=/i.10}}

-2 bytes thanks to Bubbler
Note: No TIO for this version as it relies on newer J feater called direct definition {{...}}
Working 24 byte TIO link
Just a port of caird's great answer to make sure I understood it.

[:(-:\:~"1)[:+/\]=/i.@10 is one byte shorter. Using J9 lambda (what is it actually called?) would save one more byte: {{(-:\:~"1)+/\y=/i.10}}

Thanks Bubbler.  It's called Direct Definition according to Nuvoc.

Uiua, 75 bytes
=0⋅⋅⋅⧻⍢⍜▽⍜⊢(□⊐⊂:)(((⊙⊙⊙⊙(⊂1)|∘).⊙⊙⊙◌⊃∊≡=:≡⊢,,⊙(-1.⊃⋅⊢↘1)|..0)=0⧻,)▽:□[¯1]⧻.

Test pad


text:
How many Wazirs can be placed on an N×N Chessboard?
Suppose a new fairy chess piece named the Wazir is introduced to chess. Wazirs can move from a position (x, y) to:
 (x+1, y)
 (x, y+1)
 (x-1, y)
 (x, y-1)
That is, they move orthogonally like the rook, but only one step at a time like the king. How many such wazirs can be placed on an N×N chessboard so that no two wazirs can attack each other?
 On a 1×1 board, there can be only 1 such piece.
 On a 2×2 board, there can be 2 such pieces.
 On a 3×3 board, there can be 5 such pieces.
Given N, return the number of wazirs that can be placed on an N×N chessboard.
This is OEIS sequence A000982.
More test cases
7 → 25
8 → 32
100 → 5000

Welcome to the site.  We do not do programming help but rather host programming competitions.  This could certainly be an on topic programming competition but it would need a scoring criterion, probably [tag:code-golf].

Related

So the Camel is to the Rook what the King is to the Queen? I.e. can only move orthogonally, and only one step at a time.

Since the answer to this question is just a formula, it is not a good fit for a competition style site.

Yeah..I was just wondering if there was some method to solve this so that I could code it myself.I'll hence remove the code generation tag.Honestly amazed at how fast people respond!!

More closely related. Or at least it would be if your description was matching the standard Camel definition.

The codes that people post for the code golf challenges..what kind of programming language is that?Again,this may be a very silly question..but am a beginner to programming,so please forgive my ignorance

@SashaR A lot of people use dedicated golfing programming languages. Languages that, while often based on commonly used programming languages, have been modified to be a succinct as possible.

See here for more information about this site.

@SashaR May I rewrite your question as a proper code golf challenge?

Sure! That way I can also see how to word coding related questions in future

@SashaR There you go.

This is A000982.

@Shaggy Thanks. Added.

As a new user of this site, you've been very lucky this time. A lot of (off-topic) programming questions on this site has been permanently closed and downvoted, not edited as a challenge and upvoted like this one. As other people already explained, this site is for programming competitions only, not for asking homework. You can use the sandbox (at https://codegolf.meta.stackexchange.com/questions/2140/sandbox-for-proposed-challenges?cb=1 ) before posting a challenge to avoid common mistakes next time; and note that most users on this site, as you have seen, use "unreadable" languages.

Related: my challenge asking a generalisation of the opposite (fewest pieces that can be arranged so no more can be placed).

@SashaR I attached a proof that this formula works to my answer.

This question is pretty confusing in that the Camel is already the standard fairy chess name for a piece like a knight that makes longer jumps and the piece you describe already has a fairy chess name: Wazir.

OTOH editing the question to the the standard name after answers have already been written using the name used in the question is also confusing.

Chess piece Queen is called "Vezir" in Turkish, I guess it is something close in Farsi and Arabic too.

Whitespace, 45 bytes

Try it online!
By the way, here is a proof that the ⌈n²/2⌉ formula is correct.

We can always place at least ⌈n²/2⌉ wazirs: just lay them out in a checkerboard pattern! Assuming the top-left tile is white, there are ⌈n²/2⌉ white tiles and ⌊n²/2⌋ black tiles on the n × n board. And if we place wazirs on the white tiles, no two of them are attacking each other, as every wazir only “sees” black tiles.
Here’s how we place 13 wazirs on a 5 × 5 board (each W is a wazir).

We can’t do any better: let’s arbitrarily tile the checkerboard with 2 × 1 domino pieces, optionally using a 1 × 1 piece for the final corner of an odd-length chessboard, like so:

We need ⌈n²/2⌉ dominoes to cover the chessboard. Clearly, putting two wazirs on one domino makes it so that they can attack one another! So each domino can only contain at most one wazir, meaning we can’t possibly place more than ⌈n²/2⌉ wazirs on the board.

You don't need the pigeonhole principle for the last part: you have exactly ⌈n²/2⌉ tiles, and at most camel per tile, so you have at most ⌈n²/2⌉ camels.

@ShreevatsaR What ensures you that you can't put x > ⌈n²/2⌉ camels in ⌈n²/2⌉ tiles? It's the pigeonhole principle...

@frarugi87 In any single tile, you can put at most one camel. You don't need the pigeonhole principle for that. In other words: the total number of camels on the chessboard = sum_(over each tile) {number of camels in that tile} ≤ sum_(over each tile) 1 = number of tiles = ⌈n²/2⌉. Invoking the pigeonhole principle, though obviously correct, is an unnecessary use of contradiction when a direct proof is possible.

Hand drawn red C's? That's a new one ;) And a nice answer!

@frarugi87 BTW, when you frame the statement like “you can't put x > ⌈n²/2⌉ camels in ⌈n²/2⌉ tiles” it obviously strongly suggests the pigeonhole principle. If you state it is “as there are ⌈n²/2⌉ tiles and at most one camel per tile, there are at most ⌈n²/2⌉ camels”, you do not need the pigeonhole principle. So it's a bit underhanded to choose a statement that inherently has the very feature (contradiction) that I'm saying is unnecessary for the claim being proved. :-)

I thought at first the code didn't load, so I refreshed the page, and it still didn't. Then I realized what language name was written at the top.

I appreciate that you went and changed your C's to W's in your proof  illustration.

I also appreciate that the W's are all on the WHITE SPACES with an answer in WHITESPACE.

For a brief moment there I wondered "where's the code" because I didn't read the language name.

Oasis, 3 bytes
k>v

Try it online!
square - increment - integer halve

Prolog (SWI), 22 19 bytes
Saved 3 bytes thanks to Kevin Cruijssen
X*Y:-Y is(X*X+1)/2.

Try it online!

X*Y:-Y is(X*X+1)/2. (19 bytes)

@KevinCruijssen: Doh! I suggested the same change to another user, but somehow I didn't take my own advice. Thank you :)

APL (Dyalog), 9 7 6 bytes
Now uses Mr. Xcoder's formula.
This is an anonymous prefix tacit function which takes N as argument.
⌈2÷⍨×⍨

Try it online!
×⍨ square N (lit. multiplication selfie, i.e. multiply by self)
2÷⍨ divide by 2
⌈ ceiling (round up)

Wow!I have no idea how you did this !!Didn't get the logic thoughsigh

Darn, someone already found out the pattern.

Huh, just realized the formula is on the OEIS page. Probably shouldn't have linked that.

JS (ES6) / C# polyglot, 11 bytes
n=>n*n+1>>1

Test cases

let f =

n=>n*n+1>>1

console.log(f(7))
console.log(f(8))
console.log(f(100))

C# polyglot

@Shaggy Thanks for noticing!

JS and C# polyglot seems extremely rare, given the differences between them. +1

05AB1E, 3 bytes
Straight implementation of the formula given by A000982
n;î

Try it online!
Explanation
n      # square
 ;     # divide by 2
  î    # round up

*;î works too

dc, 6 bytes
2^2~+p

2^: square;
2~: divide by 2, pushing the quotient then the remainder;
+p: add the remainder to the quotient & print.
Try it online!

C (gcc), 23 18 17 bytes

Saved a byte thanks to Tahg; golfing n/2+n%2 to n+1>>1.

f(n){n=n*n+1>>1;}

Try it online!
C (gcc), 22 bytes (not using undefined behavior)
f(n){return n*n+1>>1;}

Try it online!
Some people really do not like exploiting a certain compiler's undefined bahavior when using specific compiler flags. Doing so does save bytes, though.

Odd way of providing an answer IMO, but: f(n){n=n*n+1>>1;} to save a byte.

@Tahg Thanks; though in what way do you find my way of providing an answer odd?

I didn't think changing the input argument was a normal way of returning a value in C.

@Tahg It is not; though n= it is shorter than return .

In my opinion, this is a no-op function.

@YSC Yet in the compiler's opinion it is understandable and creates an executable which works.

so does f(){}. From the original post: "Given N, return the number of camels". Sorry my compiler doesn't like your definition of f: https://ideone.com/hRdzlY

@YSC mine does. It works (on x86 and x86_64) simply because eax is used as scratch register, and coincides with the register used to return a value.

@Ruslan maybe it should be C(undefined behaviour) 17 bytes then :D I don't disagree this solution works on some compiler. I just really don't like it and only see an astute no-op. Cope with it guys.

@YSC We believe here on PPCG that, if the program works on one interpreter, it is a valid submission. It works on an online interpreter, it is therefore valid without any further remarks.

Python 2, 17 bytes
1 byte thanks to @ovs.
lambda x:x*x+1>>1

Try it online!

Alternatively: lambda x:-~x**2/2

Python 3, 19 bytes
lambda x:-(-x*x//2)

Try it online!
lambda x:-(-x*x//2)  # Unnamed function
lambda x:            # Given input x:
            x*x      # Square
           -         # Negate
               //2   # Halve and Floor (equivalent of Ceil)
         -(       )  # Negate again (floor -> ceil)

-1 byte thanks to Mr. Xcoder

x**2 -> x*x

@Mr.Xcoder Facepalm thanks

What about lambda x:x*x+1>>1 ?

Or lambda x:x*x+1//2 Disclaimer: I don't know this language's syntax or order of operations, so I guessed; I'm saying add 1 before you //2 instead of negating twice.

@DanHenderson You still need parentheses otherwise it's parsed as (x*x) + (1//2), so that isn't actually shorter.

Brachylog, 6 bytes
^₂/₂⌉₁

Try it online!

x86_64 machine language (Linux), 9 8 bytes
0:       97                      xchg   %eax,%edi
1:       f7 e8                   imul   %eax
3:       ff c0                   inc    %eax
5:       d1 f8                   sar    %eax
7:       c3                      retq

To Try it online!, compile and run the following C program.
#include<stdio.h>
const char *f="\x97\xf7\xe8\xff\xc0\xd1\xf8\xc3";
int main() {
  for(int i=1; i<10; i++) {
    printf("%d\n", ((int(*)())f)(i));
  }
}

Segmentation fault on TIO

@l4m2 Fixed, thanks!

J, 8 bytes
Anonymous tacit prefix function.
2>.@%~*:

Try it online!
*: square
>. ceiling (round up)
@ after
2…%~ dividing by two

Alternate solutions: <.@-:@*: and *:<.@%2:

@ConorO'Brien 2>.@%~*:‽ Where did I get that from? I can't read that – looks like line noise to me…

>.@-:@*: gets my vote.

@Jonah If you squint, you can see a camel.

R, 22 21 bytes
cat((scan()^2+1)%/%2)

Try it online!
Square, increment, integer divide. Easy peasy.
Input from stdin; it can take space or newline separated input and it will compute the max wazirs for each input boardsize. Output to stdout.
-1 byte thanks to plannapus

@plannapus fixed, thank you.

Is the cat necessary? if you run it as an Rscript, it will auto output to stdout.

@qwr there was an older consensus that you had to explicitly write output out; we've mostly gone away from that at this point, but this answer was following that particular rule.

Actually, 3 bytes
²½K

Try it online!

Mathematica, 12 bytes
⌈#^2/2⌉&

11 bytes: ⌈#.5#⌉&

Pyth, 6 bytes
.E**.5

Try it online!

Pyke, 3 bytes
Xhe

Try it here!
How?
X   - Square.
 h  - Increment.
  e - Floor halve.

C# (.NET Core), 14 12 bytes
-2 bytes thanks to Emigna

n=>(n*n+1)/2

Try it online!

Save 2 bytes

n=>n*n+1>>1 (11 bytes)

I have noticed the javascript answer to do the same, and this change would make our answers byte to byte equivalent.

Perl 5, 16 bytes
$_=0|$_*$_/2+.5

Try it online!

$_=$_*$_+1>>1 14 bytes

MATL, 5 bytes
UH/Xk

Try it online!

or UQ2/k at the same byte count.

Cubix, 11 bytes
Iu*:^\)2,O@

Heheh, :^\)
Try it online!
Expands to the following cube:
    I u
    * :
^ \ ) 2 , O @ .
. . . . . . . .
    . .
    . .

Which is the same algorithm that many use.

^Iu : read in input as int and change directions
:*  : dup top of stack, multiply
\)  : change direction, increment
2,  : push 2, integer divide
O@  : print output as int, end program.

Pyke, 3 bytes
Xhe

Try it here!
X   -   input ** 2
 h  -  ^ + 1
  e - floor_half(^)

I ninja'd you by about 12 hours :-/

Ohm v2, 3 bytes
²½ı

Try it online!
² squares, ½ halves, ı ceils.

Jelly, 3 bytes
-1 thanks to Mr. Xcoder.
Based on my APL solution.
²HĊ

Try it online!
² Square
H Halve
Ċ Ceiling (round up)

Japt, 4 bytes
Been sitting on these since the challenge was closed.
²Ä z

Try it
Explanation: Square, add 1, floor divide by 2

Alternative
²ÄÁ1

Try it
Explanation: Square, add 1, bit-shift right by 1.

Cubically, 12 bytes
$:*FDF'+8/0%

Try it online!
Personally I don't see any point with using language features newer than the challenge to get less bytes, because you mostly compete with yourself (almost always there are at most one answer/language/challenge), but I still updated, by MDXF's suggestion. : defaults to :7 is a good idea anyway.

Explanation:
$:*7FDF'+8/0%
$                  Read input as number.
 :                 Set notepad value (face 6) to input.
  *                Multiply notepad value with itself.
   FDF'            Scramble the cube so face 8 value will be 1
                   (unsolved) and face 0 value will be 2.
       +8          Add 1 (face 8 value) to notepad value.
         /0        Divide notepad value by 2 (face 0 value),
                   get integer part.
           %       Output notepad value as number.

This program works because ceil(n^2 / 2) == floor((n^2 + 1) / 2).

Save 1 byte by replacing *7 with * as * implicitly is equivalent to *6, another byte by replacing %6 with %. Thanks for suggesting these changes!

:7 can be replaced with :, %6 can be replaced with %, and *7 can be replaced with *6 which can be replaced with *. Also, the rule about languages/interpreters needing to be older than the language was revoked, so the golfed program does not need to be non-competing.

,,,, 7 bytes
2*1+1»

Try it online!
Yay, commata works for something!
Fudge, I didn't implement ceiling...

Gaia, 3 bytes
sḥ⌉

Try it online!
s squares, ḥ halves, ⌉ ceils.

Commentator, 19 bytes
//{-//-}! {-#  -}<!

Try it online!
Who needs golfing languages? I've got confusing languages!
Ungolfed version:
5//{-8}//{5-}
print(10!= 5)
x={-1,3,4} # Smiley :-}
print(5<!=10)*/ # Weird comparision.

Try it online!
How does it work? I'll explain, with input 5
//                         - Take input.                           Tape: [5 0 0]
  {-//-}!                  - Square the input.                     Tape: [25 0 0]
  {-                         - Move one along the tape
    //                       - Copy the input to the tape.         Tape: [5 5 0]
      -}                     - Move one back along the tape
        !                    - Take the product of the tape.       Tape: [25 5 0]
         <space>           - Increment the tape head.              Tape: [26 5 0]
                 {-#  -}<! - Halve the tape head (floor division). Tape: [13 2 0]
                 {-          - Move one along the tape
                   #         - Set the tape head to 2.             Tape: [26 2 0]
                      -}     - Move one back along the tape
                        <!   - Reduce the tape by floor division.  Tape: [13 2 0]

OCaml, 19 bytes
let f n=(n*n+1)/2;;

Try it online!
I'm a bit bummed the name got changed from "camels" to "wazirs" before I managed to write this, but I figured I'd post it anyway.

TI-Basic, 7 bytes
round(Ans²/2,0

Alternatively (8 bytes):
int(Ans²/2+.5

-int(-.5Ans² also works

@Oki It sure does. I just wish they had a ceil( function.

///, 35 bytes
/I///,*/+,//+/I//**,/,A//*/A//,//,I

Try it online!
Takes input in unary using symbol *, and output in unary using symbol A. This is allowed for some specific languages, including /// (meta)
Because there is no way to take input in ///, input should be hardcoded:
/I/«put input here»//,*/+,//+/I//**,/,A//*/A//,//,I

for input = 4.

Explanation: (before reading, you need to know that the only syntax of /// are /pattern/replacement/, which replace every occurence of pattern by replacement; and \ for escaping; other characters is printed to output)
For n=4:
/I/****//,*/+,//+/I//**,/,A//*/A//,//,I    Start program.
/I/****/                                   Replace all `I` in the program by the input.

/,*/+,//+/****//**,/,A//*/A//,//,****      Remaining part of the program.
/,*/+,/                                    Use the `,` as a scanner, scan through `*` after it and convert to `+`.
       /+/****//**,/,A//*/A//,//++++,      Note that only `*` in the second group is affected.
       /+/****/                            Replace all `+` (which is just created) by `n` asterisks (from the first `I` group)

/**,/,A//*/A//,//****************,         Now at the last of the program before the `,` there are `n²` asterisks.
/**,/,A/                                   Scan the `,` to the left to perform division by 2:
                                           replace each `**` by a `A` as the scanner `,` pass through.
/*/A//,//,AAAAAAAA                         Remaining program.
/*/A/                                      If there is any `*` remaining (if `n²` is odd), replace it with `A`.
     /,//                                  Remove the scanner `,`.
          AAAAAAAA                         Output the result.

Husk, 3 bytes
⌈½□

Try it online!
The code is pretty much self-explanatory:

□ Square.
½ Halve.
⌈ Ceil.

⌈? Hust uses APL symbols :-)

Java 8, 20 11 bytes
i->i*i+1>>1

i->(i*i+1)/2 (with int instead of double as return type) is shorter (12 bytes). And i->i*i+1>>1 (11 bytes) is probably the shortest.

Convex, 5 bytes
{²½¯}

Try it online!
This is the same as CJam's {2#2./m]}.

Neim, 3 bytes
ᛦ>ᚺ

Try it online!

RProgN 2, 6 bytes
2^1+2÷

Try it online!

PocoLithp, 21 bytes
(#(N)(/(+(* N N)1)2))

Anonymous lambda taking argument N. Can be used in either of the following ways:

((#(N)(/(+(* N N)1)2))7) - call with argument 7
(begin
   (define camel (#(N)(/(+(* N N)1)2)))
   (camel 7))

Enter either of these lines into the REPL to test.
This language was created a few weeks ago, and the most recent changes a day ago are just bug fixes.

JavaScript (ES8), 16 bytes
x=>(h=x*x/2)+h%1
x=>                  // arrow function
   (h=x*x/2)         // dictionarying
            +h%1     // Math.ceil function

ARBLE, 11 bytes
ceil(n^2/2)

Try it online!

Bash, 18 bytes
echo $[$1*$1+1>>1]

Try it online

Add++, 13 bytes
+?
^2
+1
/2
O

Try it online!
Looks like I got here too late (again)

ASP, 13 bytes
a((x*x+1)/2).

Call with clingo -c x=7 or by putting #const x=7. in source.

Haskell, 18 bytes
w n=ceiling(n*n/2)
Run as:
main = print $ w n
Where n is the input number.

FALSE, 6 bytes
$*1+2/
Explanation:

$ duplicate top of stack
* multiply
1 push 1
+ add
2 push 2
/ divide

False only has 32-bit integers.

x86 machine code, 6 bytes
Takes its argument in eax register, returns also there.
f7 e0   mul eax
40      inc eax
d1 e8   shr eax,1
c3      ret

Excel, 15 bytes
=ROUND(A1^2/2,)

Because we are dividing by 2, we can safely replace CEILING with ROUND, saving 3 bytes.
=CEILING(A1^2/2,1)

MMIX, 16 bytes (4 instrs)
xxd, jelly code page
00000000: 1800 0000 2100 0001 3f00 0001 f801 0000  ð¡¡¡!¡¡¢?¡¡¢ẏ¢¡¡

disassembly
waz MUL $0,$0,$0
    ADD $0,$0,1
    SRU $0,$0,1
    POP 1,0

Uses the obvious trick of getting \$\lceil{n^2\over2}\rceil\$ by adding one and rounding down.

BRASCA, 8 bytes
igC2^}2/

Explanation
ig        - Turn charcodes into numbers, and concatenate input.
  C       - Set implicit output to output numbers
   2^     - (n**2
     }    -      +1)
      2/  -         /2
          - NOTE: BRASCA only handles whole integers, and will automatically Math.floor().
          - Implicitly output

Try it online!

Thunno 2, 3 bytes
²½ṃ

Try it online!
Same as all the other answers:

² = square
½ = halve
ṃ = ceil

source: Stack Exchange

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

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

sort: votes


text:
90% fail this challenge?
I guess I'm not the only one who have seen this kind of image on Facebook (and other sites).

The picture above was posted 16 days ago, and has accumulated 51 k comments. Some answers: 0, 4, 8, 48, 88, 120, 124 and so on.
Challenge:
The mathematics in the question doesn't make sense1, so we can't find the correct answer by looking at the equation (or whatever you'd call that mess of numbers and operators). However, there's a very large number of people who have answered, and 10% of those people are right!
Let's find the right answer!

Take an integer, percent, decimal value in 0-1, or fraction N representing how many percent of the test group who failed the question (or optionally how many answered correctly), and a list of numbers representing the answers people post.
Find the number that 100-N percent of the test group answered and output it. If there are more than one answer that matches this criterion, then you must output all of them.
If there are no answers that are represented 100-N percent of the time then you must output the number that's closest (measured in number of answers from 100-N).
To make the input rules for N clear: If 90 % fails, then you may input 90, 10, 0.9 or 0.1. You must specify which one you choose. You may assume that the percentage numbers are integers.

Test cases:
In the test cases below, N is the percentage that failed the test. You may choose to input using any of the allowed input methods.
N:  90   (meaning 90 % will fail and 10 % answer correctly)
List: 3 1 5 6 2 1 3 3 2 6
Output: 5   (because 90 % of the answers weren't 5)
---
N:  50   (50 % will answer correctly)
List: 3 6 1 6
Output: 6   (because 50 % of the answers weren't 6)
---
N:  69   (31 % will answer correctly)
List: 1 9 4 2 1 9 4 3 5 1 2 5 2 4 4 5 2 1 6 4 4 3
Output: 4    (because 31% of 22 is 6.82. There are 6 fours, which is the
              closest to 6.82)
---
N = 10   (90 % will answer correctly)
List: 1 2 3 4 5 6 7 8 9 10
Output: 1 2 3 4 5 6 7 8 9 10 (because 9/10 will answer correctly. All numbers
                              have been answered the same number of times, thus
                              all are equally likely to be correct.
---
N:  90
List: 1 1 1
Output: 1

code-golf
1 Please don't argue with me here. If you "know" the answer, join the other 10% and post it on Facebook!

Sandbox.

What will be the maximum number of items in the list, if any?

@KevinCruijssen You may not assume a maximum value. The maximum is determined by the memory / datatype. The challenge is based on a post with 51k comments, so it should preferably cover at least that many items.

What should we do if more than one answer is equally close such in the example [1,3,3,3], 0.5? Do we need to output both in that case?

@Emigna yes, output both. See the 4th test case.

May we return the result as strings rather than integers?

@Giuseppe yes..

What exactly is the "right" answer anyway....

@SocraticPhoenix feel free to share it with the rest of us after you have gone through the 54 k answers here.

I mean, it isn’t right anyways. It’s missing operators on the new lines...

MATL, 16 14 bytes
-1 byte thanks to @Giuseppe
-1 byte thanks to @LuisMendo
SY'ts/i-|tX<=)

Explanation:
        % implicit input
S       % sort
Y'      % run-length encoding
ts      % duplicate elements and sum (get number of elements)
/       % array right division (get array of probability for each answer)
i-|     % get absolute difference with second input
tX<     % duplicate and get minimum value
=)      % get each answer that match with the minimum value
        % (implicit) convert to string and display

Try it online! or verify all test cases

R, 65 bytes
function(N,A,x=table(A))names(x)[!(y=(abs(1-x/sum(x)-N)))-min(y)]

Try it online!
Takes N as a number between 0 and 1, and A as a vector (sometimes taken from STDIN in the TIO link so I don't have to turn them to R vectors). Returns a list of strings, as allowed by the OP.
function(N,A){
 x <- table(A)               # count occurrences of each value in A
 pct <- 1 - x/sum(x)         # compute percentages different from each value
 y <- abs(pct - N)           # find distances from N
 idx <- y!=min(y)            # find the indices of the minimum/minima
 names(x)[idx]               # return the names of the table (strings)
}

Jelly, 19 bytes
ĠL€÷⁸L¤e€ạÐṂ¥Tị⁸QṢ¤

Try it online!

JavaScript (ES7), 103 99 bytes
Takes input as (a, r) where a is the list of answers and r is the expected success ratio in [0...1]. Returns a Set.
(a,r,m)=>a.map(n=>(d=a.reduce((p,c)=>p-=c==n,r*a.length)**2)>m||(d==m?s:(m=d,s=new Set)).add(n))&&s

Test cases

let f =

(a,r,m)=>a.map(n=>(d=a.reduce((p,c)=>p-=c==n,r*a.length)**2)>m||(d==m?s:(m=d,s=new Set)).add(n))&&s

format = s => JSON.stringify(Array.from(s))

console.log(format(f([3, 1, 5, 6, 2, 1, 3, 3, 2, 6], 0.1))) // 5
console.log(format(f([3, 6, 1, 6], 0.5))) // 6
console.log(format(f([1, 9, 4, 2, 1, 9, 4, 3, 5, 1, 2, 5, 2, 4, 4, 5, 2, 1, 6, 4, 4, 3], 0.31))) // 4
console.log(format(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0.90))) // 1 2 3 4 5 6 7 8 9 10
console.log(format(f([1, 1, 1], 0.10))) // 1

05AB1E, 19 16 15 bytes
Takes rate of success in the form 0.31 (meaning 31% succeeds).
{γD€gDO/IαWQÏ˜Ù

Try it online!

I'm not sure if the behavior for this is correct.

@EriktheOutgolfer: Fixed :P

Python 2, 91 bytes
def f(l,p):c=[(abs(len(l)*p-l.count(a)),a)for a in l];print{v for x,v in c if x==min(c)[0]}

Try it online!
Takes P as success (0.1 = 10% correct)

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


text:
Distances to coordinates
There are n people on a 2D plane. Using distances between them we're going to find their positions. To get a unique answer you must make four assumptions:

There are at least 3 people.
The first person is at position (0, 0).
The second person is at position (x, 0) for some x > 0.
The third person is at position (x, y) for some y > 0.

So your challenge is to write a program or function that given a 2D array of distances (where D[i][j] gives the distance between person i and j) returns a list of their coordinates. Your answer must be accurate to at least 6 significant figures. Shortest solution in bytes wins.

Examples
[[0.0, 3.0, 5.0], [3.0, 0.0, 4.0], [5.0, 4.0, 0.0]]

=>

[[0.0, 0.0], [3.0, 0.0], [3.0, 4.0]]

[[0.0, 0.0513, 1.05809686, 0.53741028, 0.87113533], [0.0513, 0.0, 1.0780606,
0.58863967, 0.91899559], [1.05809686, 1.0780606, 0.0, 0.96529704,
1.37140397], [0.53741028, 0.58863967, 0.96529704, 0.0, 0.44501955],
[0.87113533, 0.91899559, 1.37140397, 0.44501955, 0.0]]

=>

[[0.0, 0.0], [0.0513, 0.0], [-0.39, 0.9836], [-0.5366, 0.0295], [-0.8094, -0.3221]]

[[0.0, 41.9519, 21.89390815, 108.37048253, 91.40006121, 49.35063671,
82.20983622, 83.69080223, 80.39436793, 86.5204431, 91.24484876, 22.32327813,
99.5351474, 72.1001264, 71.98278813, 99.8621559, 104.59071383, 108.61475753,
94.91576952, 93.20212636], [41.9519, 0.0, 24.33770482, 144.67214389,
132.28290899, 49.12079288, 85.34321428, 117.39095617, 103.60848008,
79.67795144, 69.52024038, 42.65007733, 105.60007249, 110.50120501,
89.92218111, 60.03623019, 133.61394005, 76.26668715, 130.54041305,
122.74547069], [21.89390815, 24.33770482, 0.0, 130.04213984, 112.98940283,
54.26427666, 71.35378232, 104.72088677, 81.67425703, 90.26668791,
71.13288376, 18.74250061, 109.87223765, 93.96339767, 69.46698314,
84.37362794, 124.38527485, 98.82541733, 116.43603102, 113.07526035],
[108.37048253, 144.67214389, 130.04213984, 0.0, 37.8990613, 111.2161525,
176.70411028, 28.99007398, 149.1355788, 124.17549005, 198.6298252,
126.02950495, 101.55746829, 37.24713176, 152.8114446, 189.29178553,
34.96711005, 180.83483984, 14.33728853, 35.75999058], [91.40006121,
132.28290899, 112.98940283, 37.8990613, 0.0, 111.05881157, 147.27385449,
44.12747289, 115.00173099, 134.19476383, 175.9860033, 104.1315771,
120.19673135, 27.75062658, 120.90347767, 184.88952087, 65.64187459,
183.20903265, 36.35677531, 60.34864715], [49.35063671, 49.12079288,
54.26427666, 111.2161525, 111.05881157, 0.0, 125.59451494, 82.23823276,
129.68328938, 37.23819968, 118.38443321, 68.15130552, 56.84347674,
84.29966837, 120.38742076, 78.30380948, 91.88522811, 72.15031414,
97.00421525, 82.23460459], [82.20983622, 85.34321428, 71.35378232,
176.70411028, 147.27385449, 125.59451494, 0.0, 158.1002588, 45.08950594,
161.43320938, 50.02998891, 59.93581537, 180.43028005, 139.95387244,
30.1390519, 133.42262669, 182.2085151, 158.47101132, 165.61965338,
170.96891788], [83.69080223, 117.39095617, 104.72088677, 28.99007398,
44.12747289, 82.23823276, 158.1002588, 0.0, 136.48099476, 96.57856065,
174.901291, 103.29640959, 77.53059476, 22.95598599, 137.23185588,
160.37639016, 26.14552185, 152.04872054, 14.96145727, 17.29636403],
[80.39436793, 103.60848008, 81.67425703, 149.1355788, 115.00173099,
129.68328938, 45.08950594, 136.48099476, 0.0, 166.89727482, 92.90019808,
63.53459104, 177.66159356, 115.1228903, 16.7609065, 160.79059188,
162.35278463, 179.82760993, 140.44928488, 151.9058635], [86.5204431,
79.67795144, 90.26668791, 124.17549005, 134.19476383, 37.23819968,
161.43320938, 96.57856065, 166.89727482, 0.0, 148.39351779, 105.1934756,
34.72852943, 106.44495924, 157.55442606, 83.19240274, 96.09890812,
61.77726814, 111.24915274, 89.68625779], [91.24484876, 69.52024038,
71.13288376, 198.6298252, 175.9860033, 118.38443321, 50.02998891,
174.901291, 92.90019808, 148.39351779, 0.0, 72.71434547, 175.07913091,
161.59035051, 76.3634308, 96.89392413, 195.433818, 127.21259331,
185.63246606, 184.09218079], [22.32327813, 42.65007733, 18.74250061,
126.02950495, 104.1315771, 68.15130552, 59.93581537, 103.29640959,
63.53459104, 105.1934756, 72.71434547, 0.0, 121.04924013, 88.90999601,
52.48935172, 102.51264644, 125.51831504, 117.54806623, 113.26375241,
114.12813777], [99.5351474, 105.60007249, 109.87223765, 101.55746829,
120.19673135, 56.84347674, 180.43028005, 77.53059476, 177.66159356,
34.72852943, 175.07913091, 121.04924013, 0.0, 93.63052717, 171.17130953,
117.77417844, 69.1477611, 95.81237385, 90.62801636, 65.7996984],
[72.1001264, 110.50120501, 93.96339767, 37.24713176, 27.75062658,
84.29966837, 139.95387244, 22.95598599, 115.1228903, 106.44495924,
161.59035051, 88.90999601, 93.63052717, 0.0, 117.17351252, 159.88686894,
48.89223072, 156.34374083, 25.76186961, 40.13509273], [71.98278813,
89.92218111, 69.46698314, 152.8114446, 120.90347767, 120.38742076,
30.1390519, 137.23185588, 16.7609065, 157.55442606, 76.3634308, 52.48935172,
171.17130953, 117.17351252, 0.0, 145.68608389, 162.51692098, 166.12926334,
142.8970605, 151.6440003], [99.8621559, 60.03623019, 84.37362794,
189.29178553, 184.88952087, 78.30380948, 133.42262669, 160.37639016,
160.79059188, 83.19240274, 96.89392413, 102.51264644, 117.77417844,
159.88686894, 145.68608389, 0.0, 169.4299171, 33.39882791, 175.00707479,
160.25054951], [104.59071383, 133.61394005, 124.38527485, 34.96711005,
65.64187459, 91.88522811, 182.2085151, 26.14552185, 162.35278463,
96.09890812, 195.433818, 125.51831504, 69.1477611, 48.89223072,
162.51692098, 169.4299171, 0.0, 156.08760216, 29.36259602, 11.39668734],
[108.61475753, 76.26668715, 98.82541733, 180.83483984, 183.20903265,
72.15031414, 158.47101132, 152.04872054, 179.82760993, 61.77726814,
127.21259331, 117.54806623, 95.81237385, 156.34374083, 166.12926334,
33.39882791, 156.08760216, 0.0, 167.00907734, 148.3962894], [94.91576952,
130.54041305, 116.43603102, 14.33728853, 36.35677531, 97.00421525,
165.61965338, 14.96145727, 140.44928488, 111.24915274, 185.63246606,
113.26375241, 90.62801636, 25.76186961, 142.8970605, 175.00707479,
29.36259602, 167.00907734, 0.0, 25.82164171], [93.20212636, 122.74547069,
113.07526035, 35.75999058, 60.34864715, 82.23460459, 170.96891788,
17.29636403, 151.9058635, 89.68625779, 184.09218079, 114.12813777,
65.7996984, 40.13509273, 151.6440003, 160.25054951, 11.39668734,
148.3962894, 25.82164171, 0.0]]

=>

[[0.0, 0.0], [41.9519, 0.0], [19.6294, 9.6969], [-88.505, -62.5382],
[-88.0155, -24.6423], [21.2457, -44.5433], [14.7187, 80.8815], [-59.789,
-58.5613], [-29.9331, 74.6141], [34.5297, -79.3315], [62.6017, 66.3826],
[5.2353, 21.7007], [6.1479, -99.3451], [-62.597, -35.7777], [-13.6408,
70.6785], [96.8736, -24.2478], [-61.4216, -84.6558], [92.2547, -57.3257],
[-74.7503, -58.4927], [-55.0613, -75.199]]

So basically you are looking for the inverse function of  DistanceMatrix in mathematica ;-)

In your first example, the third point could be either (3,4) or (3,-4).

@DavidC You didn't read the assumptions closely enough.

Yes. I now see.

Can there be more than one correct answer or am I doing something wrong? I'm getting +0.322 for the last coordinate of the 2nd example.

@Emigna As a sanity check, calculate the distances between every point you calculated. You should get the original distance matrix back. If I do that your solution can't be right (assuming that the only difference is the -0.322 -> +0.322). Also make sure you follow the assumptions correctly. Those are necessary to get a unique answer.

Apparently I'm doing something wrong. I checked the 3rd example as well and all values are correct, but signs are wrong in some places.

@Emigna Could it be that your third person's y-coordinate is less than zero which has an effect on the other person's coordinate's signs?

@JonathanFrech: For the 5-person example, only the 5th person gets the wrong sign on the y-coordinate (and the 3rd persons y-coordinate is positive). My current issue is that all y-coordinates are positive, but that is due to some change I've made which I can't recall as I'm pretty sure there were negative y-coordinates before in the 20-people example.

Can we return a list of x-coordinates and a list of y-coordinates instead of a single list of [x,y]?

So the third point is (x,y) for y>0 and x is unrestricted?

@Giuseppe Correct.

@Arnauld I suppose that's fine.

A matrix method is discussed in part II.B. of this paper (page 4).

APL (Dyalog Unicode), 74 59 bytes
+⍣(0>11○3⊃⊢)p÷×2⊃p←0j1⊥2↑⍉⊃⌹∘⍉⍨/1 .5*⍨2↑8415⌶.5×(⊣.+⍨-⊢)×⍨⎕

Try it online!
Lots of golfing at various places thanks to @H.PWiz and @ngn.
Uses the formula shown in the paper shared by Jonathan Allan. The formula on the paper involves EVD (eigenvalue decomposition), and fortunately Dyalog APL has its generalized version SVD(singular value decomposition). For square symmetric matrix \$M\$ as input, it exactly computes orthonormal \$U\$ and the diagonal matrix of eigenvalues \$\Lambda\$ in \$M=U\Lambda U^T\$.
Ungolfed and how it works
f←{
  m←×⍨⍵                     ⍝ square of distances
  v←1⌷m                     ⍝ first row
  G←.5×v+⍤1⍉m-⍤1⍨v          ⍝ -(m - column v - row v)÷2
            m-⍤1⍨v  ⍝ add v to -m by rows (rank 1)
           ⍉        ⍝ transpose
       v+⍤1         ⍝ add v to that by rows
    .5×             ⍝ halve

  U E←2↑8415⌶G              ⍝ singular value decomposition
        8415⌶G  ⍝ SVD built-in
                ⍝ since G is square and symmetric, it is identical to EVD
                ⍝ and gives orthonormal U, eigenvalue diagonal E,
                ⍝ transpose of V (≡ U), and a boolean indicator for success
      2↑        ⍝ we need only U and E

  pts←0j1⊥⊖(2↑E*.5)+.×⍉U    ⍝ compute pts as shown in the paper
                            ⍝ and convert to complex
           (2↑E*.5)         ⍝ first 2 rows of element-wise sqrt of E
                   +.×⍉U    ⍝ matmul with transposed U
                            ⍝ the resulting matrix is 2-row matrix where
                            ⍝ 1st row is x-coords and 2nd is y-coords
      0j1⊥⊖                 ⍝ compute x+yi for post-processing

  pts←pts×+×2⊃pts     ⍝ rotate by 2nd point's angle reversed
            2⊃pts  ⍝ the 2nd point
           ×       ⍝ signum; unit vector (representing angle)
          +        ⍝ complex conjugate (negation of angle)
      pts×         ⍝ rotate all points by that angle

  +⍣(0>11○3⊃pts)⊢pts  ⍝ mirror w.r.t. x-axis if 3rd point is below x-axis
  +⍣(          )  ⍝ conjugate all points (mirror w.r.t. x-axis) if...
          3⊃pts   ⍝ the 3rd point
       11○        ⍝ its complex part
     0>           ⍝ is negative
}

You can get rid of ⊖, and change v+⍤1⍉⍵-⍤1⍨v←1⌷⍵ to (⍉⊢-⊣⍀)⍣2⊢⍵

Although v-⍉⍵-v←⊣⍀⍵ is maybe simpler

Save another byte by changing (2↑E*.5)+.×⍉ to 2↑⍉(E*.5)⌹⍉, since U is orthonormal

If ⎕ is fair game, you can get 64 bytes: +⍣(0>11○3⊃q)⊢q←p÷×2⊃p←0j1⊥2↑⍉(E*.5)⌹⍉⊃U E←2↑8415⌶.5×(⍉⊢-⊣⍀)⍣2×⍨⎕

Another golf: +⍣(0>11○3⊃q)⊢q← -> +⍣(0>11○3⊃⊢)

v+⍤1⍉⍵-⍤1⍨v←⊣/⍵ -> ⍵-⍨⊣.+⍨⍵ @Bubbler @H.PWiz

@H.PWiz .. or (⍉⊢-⊣⍀)⍣2 -> (⊣.+⍨-⊢) in your 64 bytes

(E*.5)⌹⍉⊃U E← -> ⊃⌹∘⍉⍨/1 .5*⍨

Python 2, 183 178 166 161 160 159 158 156 bytes
Saved 1 byte thanks to @Giuseppe and 2 bytes thanks to @JonathanFrech.
def f(D):
 X=D[0][1];o=[0,X];O=[0,0];n=2
 for d in D[2:]:y=d[0]**2;x=(y-d[1]**2)/X/2+X/2;y-=x*x;o+=x,;O+=y**.5*(y>d[2]**2-(x-o[2])**2or-1),;n+=1
 return o,O

Try it online!
Uses the first 3 points to calculate the rest. Returns a pair of x-coords, y-coords as allowed in comments.

O+=[...] can be O+=..., and o+=[x] can be o+=x,.

@JonathanFrech Doesn't work. Python only allows adding lists to lists. TIO

@Pietu1998 I did not mean o+=x, but rather o+=x,.

R, 107
function(d){y=t(cmdscale(d))
y=y-y[,1]
p=cbind(c(y[3],-y[4]),y[4:3])%*%y/sum(y[,2]^2)^.5
p*c(1,sign(p[6]))}

The big head start is on line 1 where I use R's function for Multi-Dimensional Scaling (MDS). The rest is probably inefficient (thanks for making suggestions on how to improve): line 2 translates the data so that the first point is at (0, 0); line 3 rotates the points so that the second point is at (0,x); line 4 flips everything so that the third point is at y>0.

R has a built-in for this??? Dang.

JavaScript (ES7), 202 193 bytes
d=>{for(k=7;(a=d.map((r,i)=>[x=(r[0]**2-r[1]**2+a*a)/2/a,(d[0][i]**2-x*x)**.5*(k>>i&1||-1)],a=d[0][1])).some(([x,y],i)=>a.some(([X,Y],j)=>(Math.hypot(x-X,y-Y)-d[i][j])**2>1e-6));k+=8);return a}

Test cases

let f =

d=>{for(k=7;(a=d.map((r,i)=>[x=(r[0]**2-r[1]**2+a*a)/2/a,(d[0][i]**2-x*x)**.5*(k>>i&1||-1)],a=d[0][1])).some(([x,y],i)=>a.some(([X,Y],j)=>(Math.hypot(x-X,y-Y)-d[i][j])**2>1e-6));k+=8);return a}

format = a => a.map(JSON.stringify).join`\n`

console.log(format(f([[0.0,3.0,5.0],[3.0,0.0,4.0],[5.0,4.0,0.0]])))
console.log(format(f([[0.0,0.0513,1.05809686,0.53741028,0.87113533],[0.0513,0.0,1.0780606,0.58863967,0.91899559],[1.05809686,1.0780606,0.0,0.96529704,1.37140397],[0.53741028,0.58863967,0.96529704,0.0,0.44501955],[0.87113533,0.91899559,1.37140397,0.44501955,0.0]])))
console.log(format(f([[0.0,41.9519,21.89390815,108.37048253,91.40006121,49.35063671,82.20983622,83.69080223,80.39436793,86.5204431,91.24484876,22.32327813,99.5351474,72.1001264,71.98278813,99.8621559,104.59071383,108.61475753,94.91576952,93.20212636],[41.9519,0.0,24.33770482,144.67214389,132.28290899,49.12079288,85.34321428,117.39095617,103.60848008,79.67795144,69.52024038,42.65007733,105.60007249,110.50120501,89.92218111,60.03623019,133.61394005,76.26668715,130.54041305,122.74547069],[21.89390815,24.33770482,0.0,130.04213984,112.98940283,54.26427666,71.35378232,104.72088677,81.67425703,90.26668791,71.13288376,18.74250061,109.87223765,93.96339767,69.46698314,84.37362794,124.38527485,98.82541733,116.43603102,113.07526035],[108.37048253,144.67214389,130.04213984,0.0,37.8990613,111.2161525,176.70411028,28.99007398,149.1355788,124.17549005,198.6298252,126.02950495,101.55746829,37.24713176,152.8114446,189.29178553,34.96711005,180.83483984,14.33728853,35.75999058],[91.40006121,132.28290899,112.98940283,37.8990613,0.0,111.05881157,147.27385449,44.12747289,115.00173099,134.19476383,175.9860033,104.1315771,120.19673135,27.75062658,120.90347767,184.88952087,65.64187459,183.20903265,36.35677531,60.34864715],[49.35063671,49.12079288,54.26427666,111.2161525,111.05881157,0.0,125.59451494,82.23823276,129.68328938,37.23819968,118.38443321,68.15130552,56.84347674,84.29966837,120.38742076,78.30380948,91.88522811,72.15031414,97.00421525,82.23460459],[82.20983622,85.34321428,71.35378232,176.70411028,147.27385449,125.59451494,0.0,158.1002588,45.08950594,161.43320938,50.02998891,59.93581537,180.43028005,139.95387244,30.1390519,133.42262669,182.2085151,158.47101132,165.61965338,170.96891788],[83.69080223,117.39095617,104.72088677,28.99007398,44.12747289,82.23823276,158.1002588,0.0,136.48099476,96.57856065,174.901291,103.29640959,77.53059476,22.95598599,137.23185588,160.37639016,26.14552185,152.04872054,14.96145727,17.29636403],[80.39436793,103.60848008,81.67425703,149.1355788,115.00173099,129.68328938,45.08950594,136.48099476,0.0,166.89727482,92.90019808,63.53459104,177.66159356,115.1228903,16.7609065,160.79059188,162.35278463,179.82760993,140.44928488,151.9058635],[86.5204431,79.67795144,90.26668791,124.17549005,134.19476383,37.23819968,161.43320938,96.57856065,166.89727482,0.0,148.39351779,105.1934756,34.72852943,106.44495924,157.55442606,83.19240274,96.09890812,61.77726814,111.24915274,89.68625779],[91.24484876,69.52024038,71.13288376,198.6298252,175.9860033,118.38443321,50.02998891,174.901291,92.90019808,148.39351779,0.0,72.71434547,175.07913091,161.59035051,76.3634308,96.89392413,195.433818,127.21259331,185.63246606,184.09218079],[22.32327813,42.65007733,18.74250061,126.02950495,104.1315771,68.15130552,59.93581537,103.29640959,63.53459104,105.1934756,72.71434547,0.0,121.04924013,88.90999601,52.48935172,102.51264644,125.51831504,117.54806623,113.26375241,114.12813777],[99.5351474,105.60007249,109.87223765,101.55746829,120.19673135,56.84347674,180.43028005,77.53059476,177.66159356,34.72852943,175.07913091,121.04924013,0.0,93.63052717,171.17130953,117.77417844,69.1477611,95.81237385,90.62801636,65.7996984],[72.1001264,110.50120501,93.96339767,37.24713176,27.75062658,84.29966837,139.95387244,22.95598599,115.1228903,106.44495924,161.59035051,88.90999601,93.63052717,0.0,117.17351252,159.88686894,48.89223072,156.34374083,25.76186961,40.13509273],[71.98278813,89.92218111,69.46698314,152.8114446,120.90347767,120.38742076,30.1390519,137.23185588,16.7609065,157.55442606,76.3634308,52.48935172,171.17130953,117.17351252,0.0,145.68608389,162.51692098,166.12926334,142.8970605,151.6440003],[99.8621559,60.03623019,84.37362794,189.29178553,184.88952087,78.30380948,133.42262669,160.37639016,160.79059188,83.19240274,96.89392413,102.51264644,117.77417844,159.88686894,145.68608389,0.0,169.4299171,33.39882791,175.00707479,160.25054951],[104.59071383,133.61394005,124.38527485,34.96711005,65.64187459,91.88522811,182.2085151,26.14552185,162.35278463,96.09890812,195.433818,125.51831504,69.1477611,48.89223072,162.51692098,169.4299171,0.0,156.08760216,29.36259602,11.39668734],[108.61475753,76.26668715,98.82541733,180.83483984,183.20903265,72.15031414,158.47101132,152.04872054,179.82760993,61.77726814,127.21259331,117.54806623,95.81237385,156.34374083,166.12926334,33.39882791,156.08760216,0.0,167.00907734,148.3962894],[94.91576952,130.54041305,116.43603102,14.33728853,36.35677531,97.00421525,165.61965338,14.96145727,140.44928488,111.24915274,185.63246606,113.26375241,90.62801636,25.76186961,142.8970605,175.00707479,29.36259602,167.00907734,0.0,25.82164171],[93.20212636,122.74547069,113.07526035,35.75999058,60.34864715,82.23460459,170.96891788,17.29636403,151.9058635,89.68625779,184.09218079,114.12813777,65.7996984,40.13509273,151.6440003,160.25054951,11.39668734,148.3962894,25.82164171,0.0]])))

How?
Let di,j be the input and xi, yi be the expected output.
By the challenge rules, we know that:

For any pair (i, j): di,j = √((xi - xj)² + (yi - yj)²)
x0 = y0 = y1 = 0

We can immediately deduce that:

x1 = d0,1
d0,j = √((x0 - xj)² + (y0 - yj)²) = √(xj² + yj²)
d0,j² = xj² + yj²
d1,j = √((x1 - xj)² + (y1 - yj)²) = √((x1 - xj)² + yj²)
d1,j² = (x1 - xj)² + yj² = x1² + xj² + 2x1xj + yj² = d0,1² + xj² + 2d0,1xj + yj²

Computing xj
By using 2 and 3, we get:
xj² - (d0,1² + xj² - 2d0,1xj) = d0,j² - d1,j²
Which leads to:

xj = (d0,j² - d1,j² + d0,1²) / 2d0,1

Computing yj
Now that xj is known, we have:
yj² = d0,j² - xj²
Which gives:

yj = ±√(d0,j² - xj²)

We determine the sign of each yj by simply trying all possible combinations until we match the original distances. We also have to make sure that we have y2 > 0.
We do that by using the bitmask k where 1's are interpreted as positive and 0's are interpreted as negative. We start with k = 7 (111 in binary) and add 8 at each iteration. This way, positive values of yj are guaranteed to be selected for 0 ≤ j ≤ 2. (We could start with k = 4 just as well, because y0 = y1 = 0 anyway. But using 7 prevents negative zeros from appearing.)

I'm not sure whether it'd be shorter, but the correct way to calculate the sign of y (after the initial 3) for element k is to find p = (x, y) with two points, set p' = (x, -y), and take a third already-known point j and compare distance d[i][j] with dist(p, j) and dist(p', j). I don't consider negative zeroes an incorrect answer by the way.

@orlp Removing negative zeros doesn't cost any byte, so it's a purely aesthetic consideration. :-) (And you're right: this method is a rather inefficient fix on an initially non-working solution. But I thought it was still worth posting.)

R, 227 215 209 176 169 bytes
function(d){x=y=c(0,0)
x[2]=a=d[1,2]
d=d^2
i=3:nrow(d)
D=d[1,i]
x[i]=(D+a^2-d[2,i])/2/a
y[3]=e=sqrt(d[1,3]-x[3]^2)
y[i]=(D-d[3,i]+x[3]^2+e^2-2*x[3]*x[i])/2/e
Map(c,x,y)}

Try it online!
Once upon a time, I took a course in Computational Geometry. I'd like to say that helped, but I clearly learned nothing.
Input is an R matrix, with the output a list of 2-element vectors (x,y) (which is closer to the spec and saves bytes).
The problem here is, of course, the first three points. Once you fix three points, you can compute all the others based on those.
I just used a bit of algebra to simplify things and then noticed that since I'm only using the first 3 points to solve for the others, this all vectorized very neatly.
Outgolfed by flodel

JavaScript (ES7), 140 139 126 121 118 117 bytes
Saved 1 byte thanks to @Giuseppe.

/* this line for testing only */ f =
D=>D.map((d,n)=>n>1?(y=d[0]**2,D[n]=x=(y-d[1]**2)/X/2+X/2,y-=x*x,[x,y**.5*(y>d[2]**2-(x-D[2])**2||-1)]):[X=n*d[0],0])
<!-- HTML for testing only --><textarea id="i" oninput="test()">[[0.0, 0.0513, 1.05809686, 0.53741028, 0.87113533], [0.0513, 0.0, 1.0780606, 0.58863967, 0.91899559], [1.05809686, 1.0780606, 0.0, 0.96529704, 1.37140397], [0.53741028, 0.58863967, 0.96529704, 0.0, 0.44501955], [0.87113533, 0.91899559, 1.37140397, 0.44501955, 0.0]]</textarea><pre id="o"></pre><script>window.onload=test=function(){try{document.querySelector("#o").innerHTML=JSON.stringify(f(JSON.parse(document.querySelector("#i").value)))}catch(e){}}</script>

Works somewhat like my Python answer. Returning [x,y] pairs turned out much shorter than separate X and Y lists in JS. Overwrites the argument list, so don't use it as input multiple times.

@Giuseppe Actually, I can just not score the f= and fit it in one. :P

well I don't know JavaScript so I'm not surprised I missed that.

Mathematica, 160 bytes
(s=Table[0{,},n=Tr[1^#]];s[[2]]={#[[1,2]],0};f@i_:=RegionIntersection~Fold~Table[s[[j]]~Circle~#[[j,i]],{j,i-1}];s[[3]]=Last@@f@3;Do[s[[i]]=#&@@f@i,{i,4,n}];s)&

The program use built-in RegionIntersection to calculate intersection point of circles. Program requires exact coordinate to work.
This assumes RegionIntersection always make the point with higher y-coordinate the last one in its result if the x-coordinate is equal. (at least it is true on Wolfram Sandbox)
For some reason RegionIntersection doesn't work if there is too many circles in its input so I have to process each pair once by using Fold.
Demonstrate screenshot:

If I'm not mistaken, s[[2]]={#[[1,2]],0} can be replaced with s[[2,1]]=#[[1,2]].


text:
Digital Calendar
Given a date, output the X and Y position of the current day of the date on a digital calendar. The digital calendar is sort of the calendar that gets shown when you click on your computers clock (at least on windows), and it looks something like this:

If we assume that the given date is 25.09.2017, the result would be (2,5), because the 25th day of the 9th month of this year is in the second column and fifth row.
Note that if the date would be something like 29.08.2017, we couldn't use the calendar from above, but a new one for August. The gray-ish numbers are simply there  to fill the gaps until the day that the month actually starts.
Input
A date, in any reasonable format.
Output
The point or coordinates that the day of the given date lies at, in its respective calendar. These should be 1-indexed.
Rules

This is code-golf, the shortest code in any language wins.
Standard loopholes are forbidden.

Additional Notes
The first column of the calendar will always be Sunday.
Here are the digital calendars from January and September 2017:

Test Cases
Input: 06.02.2018 (DD.MM.YYYY) or 2018.02.06 (YYYY.MM.DD)
Output: (3,2)
Input: 12.11.1982 (DD.MM.YYYY) or 1982.11.12 (YYYY.MM.DD)
Output: (6,2)
Input: 01.01.2030 (DD.MM.YYYY) or 2030.01.01 (YYYY.MM.DD)
Output: (3,1)
Input: 13.06.3017 (DD.MM.YYYY) or 3017.06.13 (YYYY.MM.DD)
Output: (6,3)

Your "September 2017" calendar seems to be a bit off...

@EriktheOutgolfer My bad, fixing it.

I recommend providing your example test-cases in the yyyy-mm-dd format to account for an international audience.

Why would 2017-09-25 return (1,5) instead of (2,5) if the output is 1-indexed starting on Sunday?

You say 1-indexed coordinates, first column is Sunday. So Sunday is column 1, Monday is coumn 2. Yet your example says Monday is column 1. Please clarify. Voting to close as unclear until resolved

Could we have test cases for days distant such as year 400 or year 3017?

@LuisMendo My bad, forgot to change that. Fixed it now.

@fireflame241 Added one for 13.06.3017.

I apologise for the incorrect outputs for the test cases, it seems like i had a bug in the program i wrote to calculate them. They should be fine now.

i think that the last case should be (6,3) - becuase the 13th in that month is friday - or js date is incorrect...

@IanH. If you use the Sandbox you can fix such things before posting on main.

@EriktheOutgolfer This post was sandboxed.

@IanH. Yeah the sandbox isn't 100% great either.

@EriktheOutgolfer I always sandbox my post, simply because I'm not sure whether people will understand my challenge, although the biggest errors almost never get found in the sandbox ...

Is there any limit in the dates? More precisely - should we account for Gregorian vs. Julian Calendar?

A bit unclear, but I assume that any reasonable format means that we can chose the input format, as long as it is reasonable.

@GrzegorzOledzki No it's not neccessary. Maybe just specify which calendar you use in your code.

Mathematica, 83 bytes
New Rules:Starting on Sunday
{s=Min@Position[(d=DayName)@{6,1,#}&/@Range@7,d@DateObject@{##}],⌈(#3-s)/7⌉+1}&

-5 bytes from @Misha Lavrov
Input form

[2030, 1, 1]
   yyyy-mm-dd

Nice! Do I understand correctly that {6,1,2,3,4,10,5} are there because the years 6 AD, 1 AD, ..., 10 AD, 5 AD began with Sunday through Saturday respectively? (In a hypothetical backward extension of the Gregorian calendar.)

It was the only way to get the days of the week... Is there a better way?

Now that I think about it, DayName@{6,1,#}&/@Range@7 is a bit shorter than DayName@{#}&/@{6,1,2,3,4,10,5}. But it uses much the same idea, which I think is a neat one.

JavaScript (ES6), 64 59 bytes

f=
(s,d=new Date(s),e=d.getDay())=>[1+e,(d.getDate()-e)/7+2|0]
<input oninput=o.textContent=f(this.value)><pre id=o>

Input is any string which JavaScript recognises as a date. Save 16 bytes if a JavaScript date object is acceptable input. Edit: Saved 5 bytes thanks to @GrzegorzOledzki.

"Input is any string which JavaScript recognises as a date." <-- This varies a lot between JavaScript implementations.

@IsmaelMiguel Does it? I never noticed that in even if it were so it is obvious that it would only accept strings that your ecmascript implementation recognizes

You could call d.getDay() once. That is, extract the expression to a variable/argument e=d.getDay().

TI-Basic (84+), 27 bytes (50 characters)
:Prompt Y,M,D
:dayOfWk(Y,M,D
:{Ans,2+int(7⁻¹(D-Ans

Python 2, 109 98 bytes
The datetime module docs are 50,000 bytes, so I'm not using the datetime module yet.
def f(d,m,y):t=m<3;y-=t;Y=y%100;W=(d+(13*m+156*t-27)/5-y/100*2+y/400+Y+Y/4)%7+1;print W,(d+13-W)/7

Try it online!
My formula to compute day of week comes from https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html.
The formula is as follows (converted from image to text):

W = (k + floor(2.6*m-0.2) - 2*C + Y + floor(Y/4) + floor(C/4)) mod 7
where floor(k) denotes the integer floor function
k is day (1 to 31)
m is month (1 = March, ..., 10 = December, 11 = Jan, 12 = Feb) Treat Jan & Feb as months of the preceding year C is century (1987 has C = 19)
Y is year (1987 has Y = 87 except Y = 86 for Jan & Feb)
W is week day (0 = Sunday, ..., 6 = Saturday)
Here the century and 400 year corrections are built into the formula. The floor(2.6*m-0.2) term relates to the repetitive pattern that the 30-day months show when March is taken as the first month.

The row number can be calculated as one more than the number of Sundays in the month preceding the day.
-7 bytes thanks to @GrzegorzOledzki

Why do you +7? and then do modulo 7

@GrzegorzOledzki it is possible to get a negative in the parentheses, and a negative mod 7 would give a negative in the range [-6,0]. adding 7 and taking mod 7 again casts this from 0 to 6 inclusive.

-1%7 yields 6 in my python.

And couldn't (d+6-W)/7+1 be replaced with (d+13-W)/7?

@GrzegorzOledzki Good observation, and you were right with the modulo. Negative modulo output comes from a negative after %, not before.

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


text:
Life and Death of Trees
The Challenge
Write a program that takes an integer N as input, and outputs the stage of life or death that a tree is currently in. N will always be between 0 and 10.
The Stages of Life and Death

Life: To draw a stage of life, simply draw a base of size N, consisting of ^ characters, then move up and substract 2 from N, if the result is greater than 0, and draw a line of ^ characters again, again with the size of the new N. Repeat while N is larger than 0. To finish off, place either a single | character if the startoff value of N is odd, or two || characters if it was even.
Example: N = 5
  ^
 ^^^
^^^^^
  |

Note that if N = 0, only the stem will be drawn, without the leaves (^) on them.
Death: This is roughly the same as Life, except that the base is 10 - N, you use M instead of ^ and you add 2 to N and redraw the lines with the same procedure  as above, but this time you add 2 to N while it is smaller or equal to 10.
Example: N = 3
   M
  MMM
 MMMMM
MMMMMMM
   |

The Goal
Your program has to run in 2 different languages both have to take a input N. The first language has to output the life stage of a tree according to N, the second language has to output the death stage.
Rules

This is code-golf, the shortest code in bytes that meets all the requirements wins.
The code has to run in 2 different languages. Yes, Python 2 and Python 3 are different languages.
Standard loopholes are forbidden.
Trailing newlines or spaces are allowed.

Test Cases
Input: N = 1
First language (life):
 ^
 |

Second language (death):
    M
   MMM
  MMMMM
 MMMMMMM
MMMMMMMMM
    |

Input: N = 10
First language (life):
    ^^
   ^^^^
  ^^^^^^
 ^^^^^^^^
^^^^^^^^^^
    ||

Second language (death):
||

Good luck coding!

can there be trailing/leading newlines or trailing spaces?

@dzaima Yes, i'll edit that in.

Dyalog APL / SOGL, 70 65 63 62 bytes
0000000: 7b0d 04eb c0fd 5832 5c49 e32a 2e4c ac20  {.....X2\I.*.L.
0000010: 4d2a 5b3a 836b 6b7d 01ea 500d 9b31 a90f  M*[:.kk}..P..1..
0000020: 7b0f c285 c8c7 b932 c00e f8b1 c70f 7db0  {......2......}.
0000030: 32c2 8531 9c85 80b2 b50f aa32 f97d       2..1.......2.}

Interpreted in the classic Dyalog APL encoding: - life: (contains unprintables), expects ⎕IO←1
{' ^|⎕X2I┤z.L?pMzÅÏÏ}ûP'[1+⍵{⍵,⍨⌽⍉(2|⍺)↓⍉⍵}↑2,⍨1/⍨¨⍳⌈⍵÷2]}

TryAPL here!
{' ^|..'[1+⍵{⍵,⍨⌽⍉(2|⍺)↓⍉⍵}↑2,⍨1/⍨¨⍳⌈⍵÷2]}

         1+      add 1 to every value
 ' ^|..'[  ....] index the array getten below into " ^|.." with SOGLs code never being indexed in

⍵{..}↑2,⍨1/⍨¨⍳⌈⍵÷2

          1/⍨¨      replace each with that many 1s
              ⍳     the first ... numbers
               ⌈      ceiling of
                ⍵÷2     the right argument divided by 2
       2,⍨          append 2
      ↑             mix; convert to a 2D array, padding with zeroes
⍵{..}               execute that function with the arguments ⍵ - my right argument and the result of above

   {⍵,⍨⌽⍉(2|⍺)↓⍉⍵}  helper function
    ⍵,⍨             append the right arg to
               ⍉⍵     the right arg transposed
              ↓       without the first ... rows
         (2|⍺)          remainder of left arg ÷ 2
       ⌽⍉             transposed and reversed

Interpreted in SOGLs encoding - death:
{∑⁴╝υ”X2\I┐*.Lκ M*[:≥kk}¹╚P∑Β1Ι»{»φ√ωΩΡ2υ«⌠ΝΩ»}μ2φ√1β√↓νΟ»ι2⌡}

Try it Here!
Explanation:
{∑⁴╝υ”X                         push "{∑⁴╝υ" and pop it - noop
       2\                       push input divides by 2
         I┐*                    get that many + 1 vertical bars
            .Lκ                 push 10-input
                M*              get that many "M"s as a string
                  [    }        while ToS isn't falsy (here: isn't "")
                   :              duplicate the string
                    ≥             put the duplicate at the stacks bottom
                     kk           remove the last 2 letters (does nothing when the string is empty)
                        ¹       wrap everything in an array
                         ╚      center horizontally
                          P     print that
                           ...  execute a bunch of random nonsense which luckily does nothing

This took way too long.. Golfing tips for the APL part are welcome, everything mostly should be applicable as long as it doesn't change anything before ûP'
You can load the file (after reversing xxd) in SOGL by selecting the file in the Browse... dialog and then clicking load SOGL codepage encoded file.

Python 2 and Python 3, 119 110 109 bytes
r=p='';n=1/2>0;b=(-1)**n*int(input())+10*n
while b>0:r=p+'^M'[n]*b+'\n'+r;b-=2;p+=' '
print(r+p[1:]+'||'[b:])

Try it online! (Python 2, life)
Try it online! (Python 3, death)

b=int(input()) and then if n:b=10-b saves a byte.

Python 2 / Python 3, 121 bytes
def f(n):
 m=-1;n,c=(n,10-n,'^','M')[1/2>0::2];s=''
 while n>0:s=' '*m+c*n+'\n'+s;m+=1;n-=2
 return s+' '*m+'|'*(n%2or 2)

Try it online! (Python 2)
Try it online! (Python 3)

116 bytes

C (gcc) / Python 2, 308 bytes
#define _\
"""
main(N,n,j,k){scanf("%d",&N);j=-~!(N%2);for(n=j;n<=N;n+=2){printf("%*c",(N-n)/2+1,94);for(k=n-1;k;k--)printf("^");puts("");}printf("%*c",++N/2,124);N%2?puts("|"):0;}
#define _"""
#define/*
N=10-input();j=[1,0][N%2]
for n in range(1,-~N,2):print(N-n)/2*" "+"M"*(n+j)
print~-N/2*" "+"|"*-~j
#*/_

Try it online!
Python 2 / C (gcc), 308 bytes
#define _\
"""
main(N,n,j,k){scanf("%d",&N);j=-~!(N%2);for(n=j;n<=N;n+=2){printf("%*c",(N-n)/2+1,94);for(k=n-1;k;k--)printf("^");puts("");}printf("%*c",++N/2,124);N%2?puts("|"):0;}
#define _"""
#define/*
N=10-input();j=[1,0][N%2]
for n in range(1,-~N,2):print(N-n)/2*" "+"M"*(n+j)
print~-N/2*" "+"|"*-~j
#*/_

Try it online!

Python 3/Python 2, 128 bytes
def f(n,a=1/2>0):
 m=[n,10-n][a];k=-~m%2+1
 for j in range(k,m+1,2):print(" "*((m-j)//2)+"^M"[a]*j)
 print(" "*((m-k)//2)+"|"*k)

Try it online! (Python 3)
Try it online! (Python 2)

126 bytes

124 bytes


text:
Tic-Tac-Toe - X or O?
Background
Skip to "Task" if you are familiar with Tic-Tac-Toe (I think most are!)
Tic-Tac-Toe is a famous two-player game. It consists of a 3x3 board that is filled gradually by two players (clarifications below); The first player uses the character X and the other one uses O. The winner is the first to get 3 consecutive and identical characters (X or O), either horizontally, vertically or diagonally. In case the board is filled and none of the players managed to get three consecutive characters as decribed above, the game ends in a tie. Note that there might be empty spots at the end of the game, in case either of the players wins in less than 9 moves in total (this cannot happen in case of a tie).
Task
Given a Tic-Tac-Toe board at the end of a game (in the form of a string, a matrix, a flat list of 9 ordered values, any other decent format), determine who wins the game.

The input will consist of distinct and consistent values, one for X, one for O and another one that represents an empty spot.

Your program should be able to output 3 distinct, consistent and non-empty values: one in case X wins, another one in case O wins or another if the players are tied.
Please specify these values in your answer. You can assume that the input will be a valid Tic-Tac-Toe board.

Test Cases
X, O, _ are the input values here; X wins, O wins and Tie are for the output.
X O X
O X _
O _ X

Output: X wins.
X _ O
X O _
X O X

Output: X wins.
X O X
_ O X
_ O _

Output: O wins.
X O X
O O X
X X O

Output: Tie.

As usual, all our standard rules apply. This is code-golf, the shortest code in bytes in every language wins!

Get out of my brain! Literally just had an idea for a Noughts & Crosses challenge that I was gonna Sanbox on Monday. Then I crack open the site and see this!

@Shaggy To cite someone from the "Fast and Furious" series: Too slow! ;p

It's OK, my idea was for a playable version, assuming that hasn't been done already.

@Laikoni I don't think it's a dupe, since this has way more flexible input and output and also has empty boxes too, and this also lets you assume the input is a valid board.

Playing the game is a harder challenge, which obviously involves testing for winning and tied conditions.

@Joshua That’s about making a Tic-tac-toe game. This is about grading one.

@Joshua Apart from the very idea of Tic-Tac-Toe, this has nothing to do with that one. And that shouldn't be a problem anyway since we have a [tag:tic-tac-toe] tag :-)

@Mr.Xcoder: Read dmkee's comment. That's what I acted on.

This should be reopened—it’s different enough from the alleged duplicates

@Titus Thanks for your consideration!

Could you add a test case where either X or O wins with a diagonal from the top-right to the bottom-left? I succeeded in all test cases, but had only added a check for the top-left to bottom-right diagonal instead of both.

What if we don't know who wins? Say, the input is an empty board.

@Soaku Consider reading the Task section again. The empty board is NOT a valid board at the end of a game

@KevinCruijssen I will add one later, thanks!

@Mr.Xcoder that's true, sorry. I didn't understood what you meant by "at the end of a game", now I get it.

Jelly,  16 15  14 bytes
U,Z;ŒD$€ẎḄỊÐḟḢ

A monadic link accepting a list of lists (the rows - or columns) with the values:
X = 0.155; O = -0.155; _ = 0

Returning results:
X wins = 1.085; O wins = -1.085; Tie = 0

Note: using a value of zero for _, and equal but opposite values for X and O, this value (here 0.155) may be in the range (1/6, 1/7) (exclusive at both ends) - I only chose a value in that range that gave a precisely representable floating point result for the win cases.
Try it online!
How?
U,Z;ŒD$€ẎḄỊÐḟḢ - Link: list of lists (as described above)
U              - upend (reverse each row)
  Z            - transpose (get the columns)
 ,             - pair the two
      $€       - last two links as a monad for each of them:
    ŒD         -   diagonals (leading diagonals - notes: 1. only one is of length 3;
               -              2. the upend means we get the anti-diagonals too)
   ;           -   concatenate (with the rows/columns)
        Ẏ      - tighten (make a single list of all the rows, columns and diagonals)
         Ḅ     - from binary (vectorises) (note that [0.155, 0.155, 0.155]
               -                           converts to 4*0.155+2*0.155+1*0.155 = 1.085
               -                           and [-0.155, -0.155, -0.155]
               -                           converts to 4*-0.155+2*-0.155+1*-0.155 = -1.085
               -                           while shorter lists or those of length three
               -                           with any other mixtures of 0.155, -0.155 and 0
               -                           yield results between -1 and 1
               -                           e.g. [.155,.155,0] -> 0.93)
           Ðḟ  - filter discard if:
          Ị    -   insignificant (if abs(z) <= 1) (discards all non-winning results)
             Ḣ - head (yields the first value from the list or zero if it's empty)

Yes, I think any esoteric language answers should have an explanation (and I like to see explanations for normal languages too!)

Thanks for adding it! Very good approach, way more clever than what I've though of... Nice

Javascript (ES6), 103 87 bytes
a=>"012+345+678+036+147+258+048+246T".replace(/\d/g,n=>a[n]||!1).match(/(\d)\1\1|T/)[0]

Input

X is represented as 1
O is represented as 2
_ is represented as 0

Output

X wins is represented as "111"
O wins is represented as "000"
Tie is represented as "T"

Explanation
a=>
    "012+345+678+036+147+258+048+246" // List of indexes for each row
    .replace(/\d/g,n=>a[n]||!1)       // Replace all digits with the value of the cell
    .match(/(\d)\1\1|$/)[0]           // Find the first row filled with the same value

Test cases

f=
a=>"012+345+678+036+147+258+048+246T".replace(/\d/g,n=>a[n]||!1).match(/(\d)\1\1|T/)[0]
console.log(f([1,2,1,2,1,0,2,0,1]))
console.log(f([1,0,2,1,2,0,1,2,1]))
console.log(f([1,2,1,0,2,1,0,2,0]))
console.log(f([1,2,1,2,2,1,1,1,2]))

"Your program should be able to output 3 distinct, consistent and non-empty values", so you can't output empty string for tie.

@Soaku My bad, I missed that part of the rules.

PHP, 70 bytes
for($c=95024101938;${${$i++&7}.=$argn[$c%9]}=1<$c/=3;);echo$XXX-$OOO;

Assumes -n (interpreter defaults). Additionally requires -R (execute <code> for every line of input), counted as one.
Input is taken on a single line (exactly as in the problem description, except with all whitespace removed).
Output is the following: 1 → X Wins, -1 → O Wins, 0 → Tie .
Try it online!

You do not need to have the whole strings, you can choose your output values. 'X Wins' can be changed to 'X' (or even an integer -- say 1). The same applies to 'O wins' and Tie. That being said, 109 bytes.

@Mr.Xcoder thanks for the clarification.

Jelly, 18 bytes
UŒD;;Z;ŒDµSA⁼3µÐfḢ

Try it online!
X = 1, O = -1, _ = 0
X wins = [1, 1, 1], O wins = [-1, -1, -1], Tie = 0
Input as list of 3 lists of 3 elements in (1, -1, 0) each.

Wow Nice... When you are done golfing, please add the I/O values and an explanation :-)

Here is a similar approach with a slightly shorter test. Takes X=1, O=2, _=3, returns 1 (X wins), 2 (O wins) or 3 (tie).

@Arnauld thanks for the shortening

Perl 5, 58 bytes
56 bytes code + 2 fpr -p0.
$_=eval sprintf'/(.)(.{%s}\1){2}/s||'x4 .'0?$1:T',0,2..4

Try it online!
Outputs X and O for wins, or T for a tie. Includes a bunch of header/footer code to test all at once.

Alternative, 58 bytes
$}.="/(.)(.{$_}\\1){2}/s||"for 0,2..4;$_=eval$}.'0?$1:T'

Try it online!

Python 3, 73 bytes
lambda b:{'XXX','OOO'}&{*b.split(),b[::4],b[1::4],b[2::4],b[::5],b[2::3]}

Try it online!

Python 2, 100 95 92 87 82 77 bytes
lambda b:{'XXX','OOO'}&set(b.split()+[b[::4],b[1::4],b[2::4],b[::5],b[2::3]])

Try it online!

Takes input as a newline separated string of XO_
Outputs:

{'XXX'} for X,
{'OOO'} for O
{} for a tie

Works by slicing the string into rows columns and diagonals:
The board:
    1 2 3
    4 5 6
    7 8 9
which is '123\n456\n789' is sliced into:

['123', '456', '789', '147', '258', '369', '159', '357']
rows: b.split() -> ['123', '456', '789']
cols: [b[::4],b[1::4],b[2::4]] -> ['147', '258', '369']
diag: [b[::5],b[2::3]] -> ['159', '357']

then 'XXX' and 'OOO' are checked against the slices.
Takes input as a newline separated string of XO_
Outputs:

{'XXX'} for X,
{'OOO'} for O
{} for a tie

Works by slicing the string into rows columns and diagonals:
The board:
    1 2 3
    4 5 6
    7 8 9
which is '123\n456\n789' is sliced into:

['123', '456', '789', '147', '258', '369', '159', '357']
rows: b.split() -> ['123', '456', '789']
cols: [b[::4],b[1::4],b[2::4]] -> ['147', '258', '369']
diag: [b[::5],b[2::3]] -> ['159', '357']

then 'XXX' and 'OOO' are checked against the slices.

Python slicing FTW Anyways, 81 bytes, should work, I think.

@icrieverytim [2::2] slices to 3579, while [2:8:2] gives 357

Python 3, 73 bytes.

R, 118 116 115 bytes
Thanks to @user2390246 for two extra bytes.
function(M,b=table,u=unlist(c(apply(M,1,b),apply(M,2,b),b(diag(M)),b(M[2*1:3+1]))))`if`(any(u>2),names(u[u>2]),"T")

Slightly ungolfed:
function(M){
    u=unlist(c(apply(M,1,table), #Contingency table of the rows
             apply(M,2,table), #of the columns
             table(diag(M)), #of the diagonal
             table(M[2*1:3+1]))) #of the opposite diagonal
    `if`(any(u>2),names(u[u>2]),"T") #Give name of element that occurs more than twice in any setting
 }

Returns X if X wins, O if O wins and T in case of a tie.
Try it online!

M[c(3,5,7)] is shorter for the opposite diagonal

APL (Dyalog Extended), 26 21 bytes
⌈/1 1(∨⌿⍉∘⌽,⍉,⍉⍤⊢,⊢)⊢

Try it online!
Algorithm taken from the J answer, and verify a magic square.
-5 bytes from Adám.
Takes input as a 3x3 integer matrix where:
1 → blank,
2 → X,
3 → O.
returns the appropriate integer for X and O, 1 if it's a tie.
Explanation
{⌈/∨⌿(1 1∘⍉∘⌽,1 1∘⍉,⍉,⊢)⍵} ⍵ → input
     (                 )⍵  pass ⍵ to inner fn:
                      ⊢    return matrix containing argument,
                    ⍉,     argument transposed,
              1 1∘⍉,       it's main diagonal,
      1 1∘⍉∘⌽,             and the main diagonal of it's reverse.
   ∨⌿(                 )   take GCD of each column of the resultant matrix
 ⌈/                        take the maximum of that

⌈/1 1(∨⌿⍉∘⌽,⍉,⍉⍤⊢,⊢)⊢

@Adám that's the whole program?

Yeah, that's just a simple golf of yours.

Python 3, 173 bytes
lambda x:h(x,1)*2or+h(x,0)
h=lambda x,y:g(x,y)or g(zip(*x),y)or x[0][0]==x[1][1]==x[2][2]==y or x[0][2]==x[1][1]==x[2][0]==y
g=lambda x,y:any(all(e==y for e in r)for r in x)

Try it online!

Input as a matrix of 1 == X, 0 == O, -1 == _
Output as a single value: 2 == X, 1 == O, 0 == TIE

-8 bytes thanks to Erik the Outgolfer

You can replace the first line with lambda x:h(x,1)*2or+h(x,0) for -8 bytes and 0 == TIE (which is prettier imo).

@EriktheOutgolfer cool, thanks

Python 2, 124 118 117 115 bytes

Saved six bytes thanks to Erik the Outgolfer; using a string to avoid commata.
Saved one byte thanks to Mr. Xcoder; golfing [j*3:j*3+3] to [j*3:][:3].
Saved two bytes by using a magic number to compress the string.

def T(B):
 for j in range(8):
	a,b,c=map(int,`0x197bf3c88b2586f4bef6`[j*3:][:3])
	if B[a]==B[b]==B[c]>0:return B[a]

Try it online!
Input / Output values

X is represented as 1
O is represented as 2
_ is represented as None

[8,0,3,6,1,4,7,2,5,8,0,4,8,2,4,6] -> map(int,'8036147258048246')

@EriktheOutgolfer Thanks. I was trying to golf the integer list by using map(ord,"..."), though a nul byte in the middle of a string did not work out...

117 bytes. [j*3:j*3+3] is [j*3:][:3]. As a side note, j*3+3 is the same as -~j*3, but that is 118 bytes too.

@JonathanFrech You seem to have an extra 01234567...

@Mr.Xcoder Well, they actually were supposed to be there. The code, as it is, will not work.

@JonathanFrech Ok, sorry. Anyway, your Tio link did not have them.

@Mr.Xcoder Thanks. Learnt a new slicing golf today.

I don't believe that the >0 is necessary.

@JonathanAllan Without it, the player None could win.

Aha, yes my mistake!

Java 8, 112 108 106 104 90 102 93 bytes
b->b.replaceAll(".*(X|O)(\\1|...\\1...|.{4}\\1.{4}|..\\1..)\\1.*","$1").replaceAll("..+","T")

+12 bytes (90 → 102) due to bug-fix of only checking one diagonal instead of both..
-9 bytes (102 → 93) by using replaceAll instead of matches.
Input in the format XOX OX_ O_X, output X, O or T.
Explanation:
Try it here.
b->{                   // Method with String as both parameter and return-type
  b.replaceAll(".*(X|O)(\\1|...\\1...|.{4}\\1.{4}|..\\1..)\\1.*",
                       //  If we found a line of X or O:
     "$1")             //   Replace it with either X or O
   .replaceAll("..+",  //  If there are now more than 2 characters left:
     "T")              //   Replace it with T
                       // End of method (implicit / single-line return-statement)

Explanation regex:
.*(X|O)(\1|...\1...|.{4}\1.{4}|..\1..)\1.*
.*                                      .*# 0 or more trailing & leading chars
  (X|O)                               \1  # X or O next to those leading/trailing chars
       (\1                                # A single X or O in between (row found)
          |...\1...                       # 3 chars, X or O, 3 chars (column found)
                   |.{4}\1.{4}            # 4 chars, X or O, 4 chars (diagonal TL→BR found)
                              |..\1..)    # 2 chars, X or O, 2 chars (diagonal TR→BL found)

Retina, 51 bytes
.*(X|O)(\1|...\1...|.{4}\1.{4}|..\1..)\1.*
$1
..+
T

Port of my Java 8 answer. Input in the format XOX OX_ O_X, output X, O or T.
Explanation:
Try it here.
.*(X|O)(\1|...\1...|.{4}\1.{4}|..\1..)\1.*
.*                                      .*# 0 or more trailing & leading chars
  (X|O)                               \1  # X or O next to those leading/trailing chars
       (\1                                # A single X or O in between (row found)
          |...\1...                       # 3 chars, X or O, 3 chars (column found)
                   |.{4}\1.{4}            # 4 chars, X or O, 4 chars (diagonal TL→BR found)
                              |..\1..)    # 2 chars, X or O, 2 chars (diagonal TR→BL found)

$1                                        #  Replace match of above with either X or O

..+                                       # If there are now 2 or more characters left:
T                                         #  Replace everything with T

Retina, 127 bytes
.*(X|O)\1\1.*
$1
(X|O).. \1.. \1..
$1
.(X|O). .\1. .\1.
$1
..(X|O) ..\1 ..\1
$1
(X|O).. .\1. ..\1
$1
..(X|O) .\1. \1..
$1
..+
_

Try it online!
...I guess you could call this brute force... Thought there might be some merit to it...

Retina, 49 bytes
;
;;
.*(\w)(.)*\1(?<-2>.)*(?(2)(?!))\1.*
$1
..+
T

Try it online! Takes input as an 11-character string of 9 Xs, Os or -s in three groups of three separated by ;s, although the link includes a header which translates the given test cases to this format. Works by matching a winning line directly using a balancing group to ensure that the three matching characters are equidistant. (Suitable distances are 0 (horizontal line), 4 (reverse diagonal), 5 (vertical line), or 6 (diagonal); other distances would hit a ; or extend outside the string.)

Save 2 bytes by using $. instead of (?!).

Did you suggest a golf on your own answer? xD

@KevinCruijssen When they're that old I don't think it's worth editing. I mean, it's called Retina 0.8.2 these days for a start...

Ah ok. It just struck me as odd that you suggested a golf on your own answer. I thought you did so by accident thinking it was someone else's answer back in September.

@KevinCruijssen I'm not 100% sure but I think I noticed that a bunch of my answers could be golfed in a similar manner so I reviewed them all at the time and decided whether to edit or just comment.

@KevinCruijssen Also I messed up and I can save 3 bytes by using ^ instead.

Haha. 1.5 year reply to my previous comment, which was a halve year late reply to your comment, which was a 3 year old comment on your answer. Pretty big latency. ;p

J, 34 bytes
[:>./[:+./"1(2 1 0},:0 1 2}),(,|:)

Ungolfed:
[: >./ [: +./"1 (2 1 0} ,: 0 1 2}) , (, |:)

Explanation
Encoding:
X = 2
O = 3
_ = 1

Our high-level strategy is first to create a matrix each of whose rows is a possible win.  Row one is diagonal /, row 2 is diagonal \, the next three rows are the rows, and the final three rows are the columns.  This part is accomplished by the phrase (using Item Amend }):
(2 1 0},:0 1 2}),(,|:)

Finally we take the GCD of each row:
+./"1

Thanks to our encoding, any row with a blank will have a GCD of 1, as will any row that contains any mix of Xs and Os, because 2 and 3 are coprime.  So all we need to do next is find the maximum element: >./
If the game is a tie, it will be 1.  If a player wins, it will be that player's number.
Try it online!

JavaScript, 66 bytes
([a,b,c,d,e,f,g,h,i])=>e&(a&i|c&g|b&h|d&f)|a&(b&c|d&g)|i&(c&f|g&h)

Keeping it simple.

Input: A string, or array of numbers or strings, with 0 corresponding to a blank space, 1 an X, and 2 an O.
Output: 0 for a tie, 1 for X victory, 2 for O victory.

Expanded, lightly commented:
( [a,b,c,d,e,f,g,h,i] ) => // Break apart the input into nine variables w/ destructuring
  // Run through all possible win conditions. 1&1&1 -> 1, 2&2&2 -> 2
  e & (             // All victories involving the middle square
    a & i | c & g | // Diagonal lines
    b & h | d & f   // Vertical/horizontal through the middle
  ) |
  a & ( b & c | d & g ) | // Victories with the top-left square
  i & ( c & f | g & h )   // Victories with the bottom-right square

05AB1E, 14 bytes
ø«IÅ\ªIÅ/ª€êéн

Input as a 3x3 matrix of integers: X=1, O=-1, empty=0.
Output as: X wins: [1]; O wins: [-1]; tie: [-1,1].
Try it online or verify all test cases.
Explanation:
ø           # Zip/transpose the (implicit) input-matrix, swapping rows/columns
 «          # Merge the list to the (implicit) input-matrix, so the list of rows in the
            # input now also contains the columns
  I         # Push the input-matrix again
   Å\       # Pop and push its main diagonal
     ª      # And append this triplet to the list as well
      IÅ/ª  # Do the same for the main anti-diagonal
€           # Now map over each triplet in the list:
 ê          #  Sort and uniquify this triplet
  é         # After the map, sort all inner lists by length
   н        # And pop and push the first (thus shortest) one
            # (after which it is output implicitly as result)

Try it online with a step-by-step output.