text:
Split a byte array into a bit array
Write a function that when given a buffer b (1 - 104857600 bytes long) and a number of bits n (1 <= n <= 64), splits the buffer into chunks of n bits. Right-pad the last chunk with 0s up to n bits.
e.g.
Given the buffer b = "f0oBaR" or equivalently [102,48,111,66,97,82] and n = 5, return
[12, 24, 24, 6, 30, 16, 19, 1, 10, 8]

This is because the above buffer, when represented as binary looks like:
01100110 00110000 01101111 01000010 01100001 01010010

And when re-grouped into 5s looks like:
01100 11000 11000 00110 11110 10000 10011 00001 01010 010[00]

Which when converted back into decimal gives the answer.
Notes

You may use whatever data type makes the most sense in your language to represent the buffer. In PHP you'd probably use a string, in Node you might want to use a Buffer

If you use  a string to represent the buffer, assume it's ASCII for the char -> int conversion
You may use an array of ints (0-255) for input if you prefer

Return value must be an array or list of ints

Test Cases
> b = "Hello World", n = 50
318401791769729, 412278856237056

> b = [1,2,3,4,5], n = 1
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1

> b = "codegolf", n = 32
1668244581, 1735355494

> b = "codegolf" n = 64
7165055918859578470

> b = "codegolf" n = 7
49, 91, 108, 70, 43, 29, 94, 108, 51, 0

> b = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vel est eu velit lacinia iaculis. Nulla facilisi. Mauris vitae elit sapien. Nullam odio nulla, laoreet at lorem eu, elementum ultricies libero. Praesent orci elit, sodales consectetur magna eget, pulvinar eleifend mi. Ut euismod leo ut tortor ultrices blandit. Praesent dapibus tincidunt velit vitae viverra. Nam posuere dui quis ipsum iaculis, quis tristique nisl tincidunt. Aliquam ac ligula a diam congue tempus sit amet quis nisl. Nam lacinia ante vitae leo efficitur, eu tincidunt metus condimentum. Cras euismod quis quam vitae imperdiet. Ut at est turpis.", n = 16
19567, 29285, 27936, 26992, 29557, 27936, 25711, 27759, 29216, 29545, 29728, 24941, 25972, 11296, 25455, 28275, 25955, 29797, 29813, 29216, 24932, 26992, 26995, 25449, 28263, 8293, 27753, 29742, 8272, 25964, 27749, 28276, 25971, 29045, 25888, 30309, 27680, 25971, 29728, 25973, 8310, 25964, 26996, 8300, 24931, 26990, 26977, 8297, 24931, 30060, 26995, 11808, 20085, 27756, 24864, 26209, 25449, 27753, 29545, 11808, 19809, 30066, 26995, 8310, 26996, 24933, 8293, 27753, 29728, 29537, 28777, 25966, 11808, 20085, 27756, 24941, 8303, 25705, 28448, 28277, 27756, 24876, 8300, 24943, 29285, 25972, 8289, 29728, 27759, 29285, 27936, 25973, 11296, 25964, 25965, 25966, 29813, 27936, 30060, 29810, 26979, 26981, 29472, 27753, 25189, 29295, 11808, 20594, 24933, 29541, 28276, 8303, 29283, 26912, 25964, 26996, 11296, 29551, 25697, 27749, 29472, 25455, 28275, 25955, 29797, 29813, 29216, 28001, 26478, 24864, 25959, 25972, 11296, 28789, 27766, 26990, 24946, 8293, 27749, 26982, 25966, 25632, 28009, 11808, 21876, 8293, 30057, 29549, 28516, 8300, 25967, 8309, 29728, 29807, 29300, 28530, 8309, 27764, 29289, 25445, 29472, 25196, 24942, 25705, 29742, 8272, 29281, 25971, 25966, 29728, 25697, 28777, 25205, 29472, 29801, 28259, 26980, 30062, 29728, 30309, 27753, 29728, 30313, 29793, 25888, 30313, 30309, 29298, 24878, 8270, 24941, 8304, 28531, 30053, 29285, 8292, 30057, 8305, 30057, 29472, 26992, 29557, 27936, 26977, 25461, 27753, 29484, 8305, 30057, 29472, 29810, 26995, 29801, 29045, 25888, 28265, 29548, 8308, 26990, 25449, 25717, 28276, 11808, 16748, 26993, 30049, 27936, 24931, 8300, 26983, 30060, 24864, 24864, 25705, 24941, 8291, 28526, 26485, 25888, 29797, 28016, 30067, 8307, 26996, 8289, 28005, 29728, 29045, 26995, 8302, 26995, 27694, 8270, 24941, 8300, 24931, 26990, 26977, 8289, 28276, 25888, 30313, 29793, 25888, 27749, 28448, 25958, 26217, 25449, 29813, 29228, 8293, 29984, 29801, 28259, 26980, 30062, 29728, 28005, 29813, 29472, 25455, 28260, 26989, 25966, 29813, 27950, 8259, 29281, 29472, 25973, 26995, 28015, 25632, 29045, 26995, 8305, 30049, 27936, 30313, 29793, 25888, 26989, 28773, 29284, 26981, 29742, 8277, 29728, 24948, 8293, 29556, 8308, 30066, 28777, 29486

> b = [2,31,73,127,179,233], n = 8
2, 31, 73, 127, 179, 233

Is it supposed to work for values of n greater than 8? If so, what about values of n greater than 64, which is larger than most language's integer precision.

Why does the return value have to be ints?

can you add some additional test cases pls ?

@speedplane Yes, it should work for values of n greater than 8, but we can restrict it to values <= 64 if that makes it easier.

@wizzwizz4 What would you prefer for the return value?

@mpen It just seems too... arbitrary...

@wizzwizz4 I don't think so. They can't be bytes because they don't have 8 bits. Bitwise operators normally work on ints and not much else. If you have a better suggestion then I'm listening, but otherwise ints it is.

@mpen I just don't think forcing it is a good idea. If it doesn't matter for the challenge, why enforce it?

@wizzwizz4 Because I don't want people to be able to skip a step. I don't want answers like "the first 5 bits of this byte contain the answer" -- the result should not contain any superfluous information, and it should be easily converted back to ASCII or some character mapping (a real-life use-case). Also, given the number of answers so far, it doesn't appear to be a problem.

@mpen Surely if people want to use a char or a long, they should be allowed to. What's the problem with doing that?

@wizzwizz4 I've already explained the problem with char. It's a full byte. What do the remaining bits mean? long is fine because it's an integer.

@mpen I see the confusion. char is an integer that happens to be one byte long.

@wizzwizz4 Sure, but I've defined n to be 1-64 so technically the ints in your return value should have >= 64 bits. 8 will not suffice. If you come up with a solution the results in chars, please do post it.

Pyth, 18 17 bytes
iR2c.[t.B+C1z\0QQ

Thanks to @lirtosiast for a byte!
            z      get input
         +C1       prepend a 0x01 to prevent leading zeroes from disappearing
       .B          convert to binary string
      t            remove the leading 1 from ^^
    .[       \0Q   pad right with zeroes to multiple of second input
   c            Q  get chunks/slices of length second input
iR2                map(x: int(x, 2))

Jelly, 13 bytes
1;ḅ256æ«BḊsḄṖ

This takes the input as a list of integers. Try it online!
How it works
1;ḅ256æ«BḊsḄṖ  Main link. Arguments: A (list), n (integer)

1;             Prepend 1 to A.
  ḅ256         Convert from base 256 to integer.
      æ«       Bitshift the result n units to the left.
        B      Convert to binary.
         Ḋ     Discard the first binary digit (corresponds to prepended 1).
          s    Split into chunks of length n.
           Ḅ   Convert each chunk from binary to integer.
            Ṗ  Discard the last integer (corresponds to bitshift/padding).

Julia, 117 bytes
f(x,n,b=join(map(i->bin(i,8),x)),d=endof,z=rpad(b,d(b)+d(b)%n,0))=map(i->parse(Int,i,2),[z[i:i+n-1]for i=1:n:d(z)-n])

This is a function that accepts an integer array and an integer and returns an integer array. It's an exercise in function argument abuse.
Ungolfed:
function f(x::Array{Int,1},                  # Input array
           n::Int,                           # Input integer
           b = join(map(i -> bin(i, 8), x)), # `x` joined as a binary string
           d = endof,                        # Store the `endof` function
           z = rpad(b, d(b) + d(b) % n, 0))  # `b` padded to a multiple of n

    # Parse out the integers in base 2
    map(i -> parse(Int, i, 2), [z[i:i+n-1] for i = 1:n:d(z)-n])
end

Why did you temporarily delete it?

@CatsAreFluffy I realized I had done something wrong initially such that it worked for the test case but wouldn't necessarily in general. Should be all good now though. :)

JavaScript (ES6), 120 bytes
f=(a,n,b=0,t=0,r=[])=>b<n?a.length?f(a.slice(1),n,b+8,t*256+a[0],r):b?[...r,t<<n-b]:r:f(a,n,b-=n,t&(1<>b])

Recursive bit twiddling on integer arrays. Ungolfed:
function bits(array, nbits) {
    var count = 0;
    var total = 0;
    var result = [];
    for (;;) {
        if (nbits <= count) {
            // We have enough bits to be able to add to the result
            count -= nbits;
            result.push(total >> count);
            total &= (1 << count) - 1;
        } else if (array.length) {
            // Grab the next 8 bits from the array element
            count += 8;
            total <<= 8;
            total += array.shift();
        } else {
            // Deal with any leftover bits
            if (count) result.push(total << nbits - count);
            return result;
        }
    }
}

@WashingtonGuedes I managed to golf another 9 bytes off my own golf of your solution, but it's still 129 bytes, sorry: "(s,n)=>(s.replace(/./g,x=>(256+x.charCodeAt()).toString(2).slice(1))+'0'.repeat(n-1)).match(eval(`/.{${n}}/g`)).map(x=>+`0b${x}`)".length

You sure this one runs? The ungolfed version is crashing Chrome.

@mpen The golfed version definitely runs on Firefox. The ungolfed version may have errors in it.

Aha! And so it does. I thought Chrome's JS engine was ahead FF's but I guess not.

@mpen Fixed a couple of subtle bugs in my ungolfed code for you.

Python 3, 102 bytes
j=''.join
lambda s,n:[int(j(k),2)for k in zip(*[iter(j([bin(i)[2:].zfill(8)for i in s+[0]]))]*n)][:-1]

use iter trick to group string

s: the input string/buffer
n: the number of bits in each splitted chunk

Results
>>> f([102,48,111,66,97,82],4)
[6, 6, 3, 0, 6, 15, 4, 2, 6, 1, 5, 2, 0]

>>> f([102,48,111,66,97,82],5)
[12, 24, 24, 6, 30, 16, 19, 1, 10, 8]

>>> f([102,48,111,66,97,82],6)
[25, 35, 1, 47, 16, 38, 5, 18]

>>> f([102,48,111,66,97,82],8)
[102, 48, 111, 66, 97, 82]

You should've documented your code to explain what does the 'n' param do?

@nullptr n have the same meaning than the question : splits the buffer into chunks of n bits

Ruby, 114 bytes
->s,n{a=s.bytes.map{|b|b.to_s(2).rjust 8,?0}.join.split""
r=[]
r< str, num {
    arr = str.bytes.map {|byte|
        byte.to_s(2).rjust(8, "0")
    }.join.split("")
    result = []
    while arr.size > 0
        result << arr.shift(num).join.ljust(num, "0").to_i(2)
    end
    result
}

puts f["f0oBaR", 5]

Perl 6, 93 68 bytes
{@^a».&{sprintf "%08b",$_}.join.comb($^b)».&{:2($_~0 x$b-.chars)}}

PHP, 262 217 189 bytes
function f($b,$n){$M='array_map';return$M('bindec',$M(function($x)use($n){return str_pad($x,$n,0);},str_split(implode('',$M(function($s){return str_pad($s,8,0,0);},$M('decbin',$b))),$n)));}

(updated with tips from Ismael Miguel)
Formatted for readability:
function f($b, $n) {
    $M = 'array_map';
    return $M('bindec', $M(function ($x) use ($n) {
        return str_pad($x, $n, 0);
    }, str_split(implode('', $M(function ($s) {
        return str_pad($s, 8, 0, 0);
    }, $M('decbin', $b))), $n)));
}

Example:
> implode(', ',f(array_map('ord',str_split('f0oBaR')),5));
"12, 24, 24, 6, 30, 16, 19, 1, 10, 8"

Instead of str_pad($s,8,'0',STR_PAD_LEFT), you can use str_pad($s,8,0,0). You can remove the quotes on bindec and decbin to save 4 bytes. To save more, you can store array_map in a variable and pass it instead. Here you go: function f($b,$n){$M=array_map;return$M(bindec,$M(function($x)use($n){return str_pad($x,$n,0);},str_split($M('',array_map(function($s){return str_pad($s,8,0,0);},$M(decbin,$b))),5)));} (184 bytes).

Thanks @IsmaelMiguel I think you replaced the implode with $M too though.

If I did, it was by mistake. I'm really sorry. But I'm glad you liked my variation of your code.

JavaScript (ES6) 104
Iterative bit by bit fiddling,
Edit 5 bytes save thx @Neil
(s,g,c=g,t=0)=>(s.map(x=>{for(i=8;i--;--c||(s.push(t),c=g,t=0))t+=t+(x>>i)%2},s=[]),c-g&&s.push(t<<c),s)

Less golfed
(
 // parameters
 s, // byte source array
 g, // output bit group size
 // default parameters used as locals
 c = g, // output bit counter
 t = 0  // temp bit accumulator
) => (
  s.map(x =>
    { // for each byte in s
      for(i = 8; // loop for 8 bits
        i--;
        )
        // loop body
        t += t + (x>>i) % 2, // shift t to left and add next bit
        --c // decrement c,if c==0 add bit group to output and reset count and accumulator
          ||(s.push(t), c=g, t=0)
    },
    s=[] // init output, reusing s to avoid wasting another global
  ),
  c-g && s.push(t<<c), // add remaining bits, if any
  s // return result
)

Test

f=(s,g,c=g,t=0)=>(s.map(x=>{for(i=8;i--;--c||(s.push(t),c=g,t=0))t+=t+(x>>i)%2},s=[]),c-g&&s.push(t<<c),s)

function test()
{
  var a = A.value.match(/\d+/g)||[]
  var g = +G.value
  var r = f(a,g)

  O.textContent = r
  K.innerHTML = a.map(x=>`<i>${(256- -x).toString(2).slice(-8)}</i>`).join``
  + '\n'+ r.map(x=>`<i>${(256*256*256*256+x).toString(2).slice(-g)}</i>`).join``
}

test()
#A { width: 50% }
#G { width: 5% }
i:nth-child(even) { color: #00c }
i:nth-child(odd) { color: #c00 }
Input array <input id=A value="102,48,111,66,97,82">
Group by bits <input id=G value=5> (up to 32)

Output <button onclick="test()">-></button>

Instead of doubling x each time, why not shift x right i bits?

@Neil uh...why...idiocy?

I just noticed that c-g?[...s,t<<c]:s might save you a couple more bytes.

@Neil this requires some thoughts

CJam, 30 bytes
{_@{2b8 0e[}%e_0a@*+/-1<{2b}%}

Try it online!
This is an unnamed block which expects the int buffer and the amount of chunks on the stack and leaves the result on the stack.
Decided to give CJam a try. Only took me 2 hours to get it done ^^ This is probably too long, suggestions are very welcome!
Explanation

_         e# duplicate the chunk count
@         e# rotate stack, array now on top and chunk counts on the bottom
{         e# start a new block
 2b       e# convert to binary
 8 0e[    e# add zeros on the left, so the binary is 8 bits
}         e# end previous block
%         e# apply this block to each array-element (map)
e_        e# flatten array
0a        e# push an array with a single zero to the stack
@         e# rotate stack, stack contain now n [array] [0] n
*         e# repeat the array [0] n times
+         e# concat the two array
/         e# split into chunks of length n, now the stacks only contains the array
-1<       e# discard the last chunk
{2b}%     e# convert every chunk back to decimal

You can write 2b8T rather than 2b8 0 to save a byte (the variable T is preinitialized to 0) 2. Discarding the last chunk can be done with W< (the variable W is initialized to -1) or ); (take out the last element and discard it).

Got it down to 25.

Ruby, 66 bytes
->s,n{(s.unpack('B*')[0]+?0*~-n).scan(/.{#{n}}/).map{|x|x.to_i 2}}

Try it online!
Takes input buffer as a string, so that a few test strings were constructed directly in the footer to avoid unprintables.

Java, 313 306 322 bytes
I hope this beats PHP...
And nope. Stupid long function names.
-7 thanks to @quartata for getting rid of public
+16 to fix an error when the split was exact, thanks to @TheCoder for catching it
int[] f(String b,int s){int i=0,o[]=new int[(int)Math.ceil(b.length()*8.0/s)],a=0;String x="",t;for(char c:b.toCharArray()){t=Integer.toString(c,2);while(t.length()<8)t="0"+t;x+=t;a+=8;while(a>=s){o[i++]=Integer.parseInt(x.substring(0,s),2);x=x.substring(s,a);a-=s;}}while(a++<s)x+="0";o[i]=Integer.parseInt(x,2);return o;}

I don't think you have to make the function public.

What version of Java did you run this in? It doesn't seem to compile: https://ideone.com/3tonJt

@mpen Ah, whoops. I forgot, I changed it on my computer before posting. Will fix.

@JackAmmo yup, sure did. Stupid tiny phone keyboard.

o[]=new int[b.length()*8/s+1] - This will assign wrong size If (b.length()*8)%s==0

@TheCoder should I use math.ceil, then?

@Blue, yes.. o[]=new int[Math.ceil((b.length()*8)/s)]

Space is not needed after array declaration, int[] f -> int[]f. If you defined variables as class variables instead of method variables, types like int will default to 0, so you dont have to initialise it as 0 like done in method variable.

J, 24 bytes
[:#.-@[>\;@(_8:{."1#:@])

This is an anonymous function, which takes n as its left argument and b as numbers as its right argument.
Test:
      5 ([:#.-@[>\;@(_8:{."1#:@])) 102 48 111 66 97 82
12 24 24 6 30 16 19 1 10 8

Explanation:
[:#.-@[>\;@(_8:{."1#:@])

                   #:@]   NB. Convert each number in `b` to bits
            _8:{."1       NB. Take the last 8 items for each
                          NB.    (padding with zeroes at the front)
         ;@               NB. Make a list of all the bits
    -@[                   NB. Negate `n`
                          NB. (\ gives non-overlapping infixes if [<0)
       >\                 NB. Get non-overlapping n-sized infixes
 [:#.                     NB. Convert those back to decimal

Haskell, 112 109 bytes
import Data.Digits
import Data.Lists
n#x=unDigits 2.take n.(++[0,0..])<$>chunksOf n(tail.digits 2.(+256)=<<x)

Usage example: 5 # [102,48,111,66,97,82] -> [12,24,24,6,30,16,19,1,10,8].
How it works
import Data.Digits                  -- needed for base 2 conversion
import Data.Lists                   -- needed for "chunksOf", i.e. splitting in
                                    -- sublists of length n

           (                  =<<x) -- map over the input list and combine the
                                    -- results into a single list:
            tail.digits 2.(+256)    -- convert to base two with exactly 8 digits
         chunksOf n                 -- split into chunks of length n
       <$>                          -- convert every chunk (<$> is map)
    take n.(++[0,0..])              -- pad with 0s
unDigits 2                          -- convert from base 2

MATL, 9 bytes
8&B!we!XB

Try it online!
Takes input b as a string delimited by '' or as an array of comma-separated values like [102, 48, 111], then n.
8           # push 8
&B          # implicitly take input b, and use 2-element convert to binary
            # to push a binary matrix of 8 bits
!           # transpose, so each column represents an input
w           # implicitly take input n and swap it with binary matrix to top of stack
e           # reshape into n rows, padding with zeros at end
            # this matrix will have each column as an n-bit integer
!           # transpose, so each row is now the n-bit integer
XB          # convert each row to decimal
            # implicit output

Perl 5 -nl -MData::Dump=pp , 96 bytes
$}=$_;pp map{$_=sprintf"%-$}s",$_;y/ /0/;oct"0b$_"}(join'',map{sprintf"%08b",$_}<>)=~m/.{1,$_}/g

Try it online!
Requires the Data::Dump module.
Takes n on the first line of input and the numbers on each line after that.
Outputs to STDERR (the Debug field on TIO).
Deparsed and tidied:
BEGIN { $/ = "\n"; $\ = "\n"; }
use Data::Dump ( split( /,/, 'pp', 0 ) );
LINE: while ( defined( $_ = readline ARGV ) ) {
    chomp $_;
    $} = $_;
    pp(
        map( {
                $_ = sprintf( "%-$}s", $_ );
                tr/ /0/;
                oct "0b$_";
            } join( '', map( { sprintf '%08b', $_; } readline ARGV ) ) =~
              /.{1,$_}/g )
    );
}

Powershell 146 bytes
param([int[]][char[]]$b,$n)-join($b|%{[convert]::ToString($_,2).PadLeft(8,"0")})-split"(.{$n})"|?{$_}|%{[convert]::ToInt32($_.PadRight($n,"0"),2)}

Take in the buffer and convert it to a char array and then an integer array. For each of those convert to binary, pad the entries with 0's where needed, and join as one large string. Split that string on n characters and drop the blanks that are created. Each element from the split is padded (only the last element really would need it) and converted back into an integer. Output is an array

Python 3.5 - 312 292 bytes:
def d(a, b):
    o=[];o+=([str(bin(g)).lstrip('0b')if str(type(g))=="<class 'int'>"else str(bin(ord(g))).lstrip('0b')for g in a]);n=[''.join(o)[i:i+b]for i in range(0,len(''.join(o)),b)];v=[]
    for t in n:
        if len(t)!=b:n[n.index(t)]=str(t)+'0'*(b-len(t))
    v+=([int(str(f),2)for f in n])
    return v

Although this may be long, this is, in my knowledge, is the shortest way to accept both functions and arrays without errors, and still being able to retain some accuracy in Python 3.5.

Java, 253 247 bytes
Golfed
int i,l,a[];Integer I;String f="";int[]c(String s,int n){for(char c:s.toCharArray())f+=f.format("%08d",I.parseInt(I.toString(c, 2)));while(((l=f.length())%n)>0)f+="0";for(a=new int[l=l/n];i<l;)a[i]=I.parseInt(f.substring(i*n,i++*n+n),2);return a;}

UnGolfed
int i,l,a[];
Integer I;
String f="";
int[]c(String s,int n) {
    for(char c:s.toCharArray())
        f+=f.format("%08d",I.parseInt(I.toString(c,2)));
    while(((l=f.length())%n)>0)
        f+="0";
    for(a=new int[l=l/n];i<l;)
        a[i]=I.parseInt(f.substring(i*n,i++*n+n),2);
    return a;
}

c, 2 => c,2; ((l=f.length())%n)>0 => (l=f.length())%n>0;

Jelly, 13 bytes
+256BḊ€Ẏsz0ZḄ

Try it online!
Different from Dennis's answer.
Note: The input is actually a list of non-negative integers, but the TIO link eases the pain for you, and accepts either such a list or a string.

Stax, 12 bytes
è■àåk┘K¥xk└╣

Run and debug it
This isn't a function as specified in the challenge, but a program, since stax doesn't support functions.  It supports input of strings or array literals.

Python 2, 101 bytes
lambda a,n:[int(''.join(bin(x+256)[3:]for x in a+[0]*n)[n*i:][:n],2)for i in range((len(a)*8-1)/n+1)]

Try it online!

Dyalog APL, 36 bytes
{2∘⊥¨↓A⍴(×/A←⍺,⍨⌈⍺÷⍨8×≢⍵)↑∊↓⍉⍵⊤⍨8/2}

Try it online!
This probably could be golfed down more.

Elixir, 63 60 bytes
&(s=&2-1)&&for<<x::size(&2)<-<<"#{&1}",0::size(s)>> >>,do: x

Try it online!
Takes input as Elixir binary, outputs a list of integers.
This code makes use of Elixir bitstring generator comprehension to chunk input binary &1 into bit blocks of size provided as argument &2. To account for any leftover bits at the end, we pad the binary with &2 - 1 zero bits. Here is also the place where some unwanted verbosity kicks in: Elixir complains if we don't explicitly declare &1 as bitstring, and it also doesn't support expressions in size(...), hence the need for an extra variable assignment.
Easter egg: in the footer, replace IO.inspect with IO.puts, and our function magically "translates" Lorem ipsum from Latin to Chinese - Try it online!

PHP, 135 129 124 bytes
function($b,$n){foreach($b as$c)$a.=sprintf('%08b',$c);foreach(str_split($a,$n)as$s)$d[]=bindec(str_pad($s,$n,0));return$d;}

Try it online!
Implemented as a function, input buffer is an array of ints and returns an array of ints.
Output
> b = "f0oBaR", n = 5
[12,24,24,6,30,16,19,1,10,8]

> b = "Hello World", n = 50
[318401791769729,412278856237056]

> b = [1,2,3,4,5], n = 1
[0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1]

Verify all test cases

Nice! Quite a bit shorter than mine.

Japt, 16 bytes
After a long day of meetings, it feels like I've forgotten how to golf! Will play around with this on the train home later, see if I can improve on it.
c_¤ùT8ÃòV úTV mÍ

Try it

Are you saying it's 16 bytes if you encode it with IEC 8859-1? Is that even legal? Did you find a loophole? Did they not specify it has to be UTF-8? Because it's 22 bytes of UTF-8.

@mpen 1. Each language is free to use it's own encoding/codepage. 2. ISO-8859-1 is a fairly standard encoding used by many languages and not particular to Japt, or this specific solution. 3. Your spec doesn't state that we must count in UTF-8. 4. If it did, you would have been strongly discouraged from it.

I'm not trying to impose anything, I just wanted to know if this was generally accepted, and it appears you're quite right https://codegolf.meta.stackexchange.com/a/17800/23090 TIO scores Japt the same way, that might be an easier way to qualify it https://tio.run/##y0osKPn/Pzn@0JLDO0MsDjcf3hSmcHhXSJhC7uHe//8B edit 3: oh your link is pretty much TIO.

APL(NARS), 471 chars, 942 bytes
TH←{v←↑⍴⍴⍵⋄v>2:64⋄v=2:32⋄(v=1)∧''≡0↑⍵:20⋄''≡0↑⍵:4⋄v=1:16⋄⍵≢+⍵:8⋄⍵=⌈⍵:2⋄1}
TV←{x←TH¨⍵⋄k←↑x⋄t←↑⍴⍵⋄t=+/x=2:2⋄t=+/x≤2:1⋄(k≤8)∧⍬≡x∼k:k⋄0}
T←{v←↑⍴⍴⍵⋄v>2:64+TV⍵⋄v=2:32+TV⍵⋄(v=1)∧''≡0↑⍵:20⋄''≡0↑⍵:4⋄v=1:16+TV⍵⋄⍵≢+⍵:8⋄⍵=⌈⍵:2⋄1}
RI←{t←T⍵⋄(t≠1)∧(t≠2)∧(t≠17)∧(t≠18):0⋄∧/((1⊃⍺)≤⍵)∧⍵≤(2⊃⍺)}
B←{(8⍴2)⊤⍵}⋄C←{¯1+⎕AV⍳⍵}⋄f←{t←T⍵⋄(0 255 RI⍵)∧18=t:∊B¨⍵⋄(0 255 RI x←C¨⍵)∧20=t:∊B¨x⋄,¯1}⋄W←{((↑⍴⍵)⍴2)⊥⍵}
q←{(∼1 64 RI,⍺)∨2≠T⍺:,¯1⋄x←f⍵⋄¯1=↑x:,¯1⋄t←↑⍴x⋄k←(⍺-m)×0≠m←⍺∣t⋄W⍉((t+k)÷⍺)⍺⍴(((t⍴1),k⍴0)\x)}

commented code and test:
  ⍝TH⍵ return type its argument
  TH←{v←↑⍴⍴⍵⋄v>2:64⋄v=2:32⋄(v=1)∧''≡0↑⍵:20⋄''≡0↑⍵:4⋄v=1:16⋄⍵≢+⍵:8⋄⍵=⌈⍵:2⋄1}
  ⍝ TV⍵ check if type each element of array ⍵ is the same and basic
  ⍝ (float(int and float too),int,char,complex) and return its number (or 0 if it is not basic)
  TV←{x←TH¨⍵⋄k←↑x⋄t←↑⍴⍵⋄t=+/x=2:2⋄t=+/x≤2:1⋄(k≤8)∧⍬≡x∼k:k⋄0}
  ⍝ T⍵ return the type of ⍵ [it would be ok if ⍵ is not a function]
  ⍝|1 Float|2 Int|4 Char|8 Complex,Quaternion or Oction|16 List|32 Matrix|64 Tensor
  ⍝|17 List Float|18 List Int|20 List Char=string|etc
  T←{v←↑⍴⍴⍵⋄v>2:64+TV⍵⋄v=2:32+TV⍵⋄(v=1)∧''≡0↑⍵:20⋄''≡0↑⍵:4⋄v=1:16+TV⍵⋄⍵≢+⍵:8⋄⍵=⌈⍵:2⋄1}
  ⍝ ⍺RI⍵ check if the numeric array ⍵ has elements in [1⊃⍺ 2⊃⍺]; if type is not ok return 0(false)
  RI←{t←T⍵⋄(t≠1)∧(t≠2)∧(t≠17)∧(t≠18):0⋄∧/((1⊃⍺)≤⍵)∧⍵≤(2⊃⍺)}

  B←{(8⍴2)⊤⍵}   ⍝ from decimal to binary of element 0..255
  C←{¯1+⎕AV⍳⍵}   ⍝ return the number of char that is in array AV seems the ascii number
  ⍝ f⍵ with ⍵ List int element in 0..255 or String with numeric element 0..255
  ⍝ return the corrispondence disclosed binary array
  f←{t←T⍵⋄(0 255 RI⍵)∧18=t:∊B¨⍵⋄(0 255 RI x←C¨⍵)∧20=t:∊B¨x⋄,¯1}
  W←{((↑⍴⍵)⍴2)⊥⍵} ⍝ from list of binary digit to decimal
  ⍝ the function for the exercise
  q←{(∼1 64 RI,⍺)∨2≠T⍺:,¯1⋄x←f⍵⋄¯1=↑x:,¯1⋄t←↑⍴x⋄k←(⍺-m)×0≠m←⍺∣t⋄W⍉((t+k)÷⍺)⍺⍴(((t⍴1),k⍴0)\x)}

  5 q    'f0oBaR'
12 24 24 6 30 16 19 1 10 8
  50 q "Hello World"
318401791769729 412278856237056
  1  q 1 2 3 4 5
0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1
  32 q "codegolf"
1668244581 1735355494
  7 q "codegolf"
49 91 108 70 43 29 94 108 51 0
  8 q 2 31 73 127 179 233
2 31 73 127 179 233
  64 q 2 31 73 127 179 233
1.529217252E17
  65 q 2 31 73 127 179 233
¯1
  0 q 2 31 73 127 179 233
¯1
  23 q '123'
1612057 4194304
  23 q '123∞'
¯1
  23 q '1' 2 3
¯1
  23 q 2 3.3
¯1
  23 q 2
¯1
  23 q '1'
¯1
  23 q ,2
65536
  23 q ,'1'
1605632


text:
Sort items based on dependency
Goal
Sort a list of items ensuring that each item is listed after its specified dependencies.
Input
An array of arrays of integers, where each integer specifies the 0-based or 1-based index of another item that this item must come after.  The input may be an array or string or anything else human readable.
For example, a 0-based input:
[
  [ 2 ],    // item 0 comes after item 2
  [ 0, 3 ], // item 1 comes after item 0 and 3
  [ ],      // item 2 comes anywhere
  [ 2 ]     // item 3 comes after item 2
]

Assume there are no circular dependencies, there is always at least one valid order.
Output
The numbers in order of dependency.  An ambiguous order does not have to be deterministic.  The output may be an array or text or anything else human readable.
Only one order should be given in the output, even where there are multiple valid orders.
Possible outputs for the above input include:
[ 2, 3, 0, 1 ]
[ 2, 0, 3, 1 ]

Scoring
A function or program that completes this in the least number of bytes wins the glory of acceptance.  The deadline is in 6 days.

This is called Topological Sorting for the curious.

The input may be an array or string or anything else human readable Just to make sure: can it be a 2D array with zeros and ones, where one indicates dependency and zero indicates no dependency?

@DonMuesli, sorry for the late reply, but no.  The idea came from code dependencies.  If you added another code module, it would be irresponsible to have to modify irrelevant code modules to declare they were not dependant on this new module.

That totally makes sense. Shouldn't Dennis be the winner?

Yes, he is. Sorry, late stressful night and rushing based on assumptions.

Jelly, 8 bytes
ịÐL³ŒḊ€Ụ

This is based on the (unimplemented) depth approach from @xnor's Python answer.
Try it online!
How it works
ịÐL³ŒḊ€Ụ  Main link. Input: A (list of dependencies)

 ÐL       Apply the atom to the left until a loop is reached, updating the left
          argument with the last result, and the right argument with the previous
          left argument.
ị         For each number in the left argument, replace it with the item at that
          index in the right argument.
   ³      Call the loop with left arg. A (implicit) and right arg. A (³).
    ŒḊ€   Compute the depth of each resulting, nested list.
       Ụ  Sort the indices of the list according to their values.

Would these 8 characters actually be 19 bytes?

@Hand-E-Food Jelly uses a custom encoding (not UTF 8), so each character is a byte

@Hand-E-Food Don Muesli is correct. Jelly uses this code page by default, which encodes all characters it understands as one byte each.

Pyth, 21 bytes
hf.A.e!f>xYTxkTbQ.plQ

                    Q  input
                   l   length of input array
                 .p    all permutations of [0, 1, ..., lQ-2, lQ-1]
hf                     find the first permutation for which...
    .e          Q        map over the input array with indices...
       f       b           find all elements in each input subarray where...
        >xYT                 index of dependency is greater than...
            xkT              index of item
      !                    check whether resulting array is falsy (empty)
  .A                     is the not-found check true for [.A]ll elements?

Test:
llama@llama:~$ echo '[[2],[0,3],[],[2]]' | pyth -c 'hf.A.e!f>xYTxkTbQ.plQ'
[2, 0, 3, 1]

Python 2, 73 bytes
l=input()
f=lambda n:1+sum(map(f,l[n]))
print sorted(range(len(l)),key=f)

Sorts the vertices by their descendant count, which f computes recursively. If a vertex points to another vertex, its descendants include the pointed vertex and all of that vertex's descendants, so it has strictly more descendants. So, it is placed later than the pointed vertex in the ordering, as desired.
The descendant count of a vertex is one for itself, plus the descendant counts of each of its children. Note that a descendant can be counted multiple times if there are multiple paths leading to it.
It would have also worked to used depth rather than descendant count
f=lambda n:1+max(map(f,l[n]))

except the max would need to give 0 on an empty list.

Beautiful algorithm. This would score 12 bytes in both Pyth and Jelly.

Pyth, 19 bytes
hf!s-V@LQT+k._T.plQ

Try it online: Demonstration
Explanation:
hf!s-V@LQT+k._T.plQ   implicit: Q = input list
               .plQ   all permutations of [0, 1, ..., len(Q)-1]
 f                    filter for permutations T, which satisfy:
      @LQT               apply the permutation T to Q
                         (this are the dependencies)
            ._T          prefixes of T
          +k             insert a dummy object at the beginning
                         (these are the already used elements)
    -V                   vectorized subtraction of these lists
   s                     take all dependencies that survived
  !                      and check if none of them survived
h                    print the first filtered permutation

Bash + perl, 35 bytes
perl -pe's/^$/ /;s/\s/ $. /g'|tsort

Example run
I/O is 1-indexed. Each array goes on a separate line, with whitespace as item separator.
$ echo $'4\n1\n\n3\n1 3 2' # [[4], [1], [], [3], [1, 3, 2]]
4
1

3
1 3 2
$ bash tsort <<< $'4\n1\n\n3\n1 3 2'
3
4
1
2
5

How it works
tsort – which I learned about in @DigitalTrauma's answer – reads pairs of tokens, separated by whitespace, that indicate a partial ordering, and prints a total ordering (in form of a sorted list of all unique tokens) that extends the aforementioned partial ordering.
All numbers on a specific line are followed by either a space or a linefeed. The s/\s/ $. /g part of the Perl command replaces those whitespace characters with a space, the line number, and another space, thus making sure that each n on line k precedes k.
Finally, if the line is empty (i.e., consists only of a linefeed), s/^$/ / prepends a space to it. This way, the second substitution turns an empty line k into k  k, making sure that each integer occurs at least once in the string that is piped to tsort.

Right, ok.  I think you groked tsort better/faster than I did :)  Thanks for the extra explanation.

Bash + coreutils, 20 80
nl -v0 -ba|sed -r ':;s/(\S+\s+)(\S+) /\1\2\n\1 /;t;s/^\s*\S+\s*$/& &/'|tsort|tac

Input as space-separated lines, e.g.:
2
0 3

2

nl adds zero-based indices to all lines
sed splits depedency lists into simple dependency pairs, and makes incomplete dependencies dependent on themselves.
tsort does the required topological sort
tac puts the output reverse order

Ideone.
Ideone with @Dennis' testcase

Python 2, 143 118 116 bytes
A slightly more random approach.
from random import*
l=input()
R=range(len(l))
a=R[:]
while any(set(l[a[i]])-set(a[:i])for i in R):shuffle(a)
print a

Edits:

fixed it, and actually saved some bytes too.
Saved 2 bytes (thanks @Dennis)

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:
Make a Snake Parser!
Snakes look like this:
      >>>v
@     ^  v
^  >>>^  v
^        v
^<<<<<<<<<

The snake can cross over itself as in this case:
 @
 ^
>^>v
 ^<<

For a crossover to be valid, the characters on either side must be moving the same direction. The case of
 @
>^v
 ^<

can be considered unclear and invalid.
The output is a string of WASD representing going from the head to the tail  (@).
Given a snake that doesn't backtrack and isn't ambiguous, can you write a program that will output the string of moves that the snake takes?
This is code-golf, so shortest answer wins!
Test cases:
(Note: The @ can be replaced with any character not in v^<>)
Input:
>>>>v
    v
  v<<  @
  v    ^
  >>>>>^

Output: ddddssaassdddddww

Input:
@>>v
^  v
^  v
^<<<

Output: dddsssaaawww

Input:
>>>v
   v       @
   v       ^
   >>>>v   ^
       >>>>^

Output: dddsssddddsddddwww

Input:
@<< v
  ^ v
v<^<<
v ^
>>^

Output: ssaaaassddwwwwaa

Input:
@v<v
^v^v
^v^<
^<

Output: ssawwasssawww

Does the input have to be a single String or can we take a String[]? Is each line of the input padded to be the same length or do we have to deal with irregular line length?

This is giving me horrible flash backs to the path of an Ant on a rubiks cube question.

Will the beginning segment always be on line 0, char 0, or will we have to find it?

@SpeedyNinja test cases 2 and 4 both have starts not at (0,0), and test case 0 (snakes look like) doesn't start OR end at (0,0).

@CAD97 Oh, that's devlish ;)

Can two 4-way intersections in a row be next to each other?  e.g., ddddsawwass

@CAD97 Okay, does this look better?

Let us continue this discussion in chat.

Java, 626 539 536 529 bytes
-87 bytes by saving a few in a lot of places. Thanks goes to Mr Public for pointing some out.
-3 bytes because I can't manage to remove all the spaces first try (thanks mbomb007)
+8 bytes to fix for this case:
@v<v
^v^v
^v^<
^<

-15 bytes by front-loading variable declaration
s->{String o="",t;String[]p=s.split("\n");int h=p.length,w=p[0].length(),y=0,x,b=0,a,n,m;char[][]d=new char[h][w];for(;y<h;y++)for(x=0;x<w;x++){d[y][x]=p[y].charAt(x);if(d[y][x]=='@')d[y][x]=' ';}for(;b<h;b++)for(a=0;a<w;a++){t="";x=a;y=b;n=0;m=0;while(!(y<0|y>h|x<0|x>w||d[y][x]==' ')){if(y+m>=0&y+m<h&x+n>=0&x+n<w&&d[y+m][x+n]==d[y-m][x-n])d[y][x]=d[y-m][x-n];n=m=0;switch(d[y][x]){case'^':t+="W";m--;break;case'<':t+="A";n--;break;case'v':t+="S";m++;break;case'>':t+="D";n++;}x+=n;y+=m;}o=t.length()>o.length()?t:o;}return o;}

Readable version:
static Function<String,String> parser = snake -> {
    // declare all variables in one place to minimize declaration overhead
    String output = "", path;
    String[] split = snake.split("\n");
    int h=split.length, w=split[0].length(), y=0, x, startY=0, startX, dx, dy;
    char[][] board = new char[h][w];
    // setup char[][] board
    for (; y<h; y++)
        for (x=0; x<w; x++) {
            board[y][x]=split[y].charAt(x);
            if(board[y][x]=='@')board[y][x]=' ';
        }
    // find the longest possible path
    for (; startY<h; startY++)
        for (startX=0; startX<w; startX++) {
            path = "";
            x=startX; y=startY; dx=0; dy=0;
            while (!(y<0 | y>h | x<0 | x>w || board[y][x] == ' ')) {
                if (y + dy >= 0 & y + dy < h & x + dx >= 0 & x + dx < w
                        && board[y + dy][x + dx] == board[y - dy][x - dx]) {
                    board[y][x] = board[y - dy][x - dx];
                } dx = dy = 0;
                switch(board[y][x]) {
                    case '^':path+="W";dy--;break;
                    case '<':path+="A";dx--;break;
                    case 'v':path+="S";dy++;break;
                    case '>':path+="D";dx++;break;
                }
                x+=dx; y+=dy;
            }
            output = path.length()>output.length()?path:output;
        }
    return output;
};

Takes a String like v  @\n>>>^.
Creates a path starting at each coordinate, then returns the longest one.
The lookahead required for the overlapping paths was the hardest part.

I am very impressed. I didn't expect anyone to even attempt this. And you're the first one. +1. (2016 bytes is okay, and even better for 2016 :D)

Strip all the spaces, names, etc then I'll +1. I'm not voting up until it's golfed properly.

Or, have two code snippets, one of the fully golfed version, one of the working readable example.

@mbomb007 I finished the logic golfing so here's the properly golfed version!

@CAD97 Probably just an oversight, replace variables dx and dy with a 1 character long variable name. Also, I believe you can set an int L=b.length; and you should save a few bytes since b.length is repetitive.

@CAD97 Also, kind of obscure, but consider this for-loop: int y=0,x;for(;y<3;y++)for(x=0;x<3;x++) is 1 byte less than for(int y=0;y<3;y++)for(int x=0;x<3;x++)

@MrPublic are you trying to run me out of one-letter variable names with any sort of meaning? Anyway, I put your things in and fixed the for(;;)if()break; to be while(), for a gain of -87 bytes.

Can you use | instead of || for any of those? Or for(x=0;x++<3;)? Also, remove spaces in char[][] d = new char.

@mbomb007 I just ninja'd you on | vs ||. The last one needs to short circuit but the others don't. The value of the loop variables matters too much to change incrimination from the end of the loop to the beginning.

@CAD97 For this challenge, I would say this is an excellent golf in Java.

Ruby, 217
->a{r=''
z=a.index ?@
a.tr!('<^>v',b='awds').scan(/\w/){c=0
e,n=[a[z,c+=1][?\n]?p: c,d=c*a[/.*
/].size,a[z-c,c][?\n]?p: -c,-d].zip(b.chars).reject{|i,k|!i||a[v=i+z]!=k||0>v}.max_by{|q|q&[a[z]]}until n
z+=e
r=n*c+r}
r}

This starts at the @ and walks backwards, looking for neighbors that point to the current position (z).  In order to choose the right way at 4-way intersections, it favors neighbors pointing in the same direction (max_by{...}).  If no immediate neighbors are found, it assumes that there must have been a cross-over and reaches out one level at a time until it finds one (until n and c+=1).  This process repeats for the number of body segments (not including the head) (.scan(/\w/){...}).
The test case I added to the puzzle kept tripping me up, so I went form 182 char to 218.  Those extra characters were all making sure my horizontal moves didn't go into the next/prev lines.  I wonder if I can deal with that in a better way.
Ungolfed:
f=->a{
  result=''
  position=a.index ?@ # start at the @
  a.tr!('<^>v',b='awds') # translate arrows to letters
  a.scan(/\w/){           # for each letter found...
    search_distance=0
    until distance
      search_distance+=1
      neighbors = [
        a[position,search_distance][?\n]?p: search_distance,  # look right by search_distance unless there's a newline
        width=search_distance*a[/.*\n/].size,   # look down (+width)
        a[position-search_distance,search_distance][?\n]?p: -search_distance, # look left unless there's a newline
        -width                  # look up (-width)
      ]
      distance,letter = neighbors.zip(b.chars).reject{ |distance, letter_to_find|
        !distance || # eliminate nulls
         a[new_position=distance+position]!=letter_to_find || # only look for the letter that "points" at me
         0>new_position # and make sure we're not going into negative indices
       }.max_by{ |q|
        # if there are two valid neighbors, we're at a 4-way intersection
        # this will make sure we prefer the neighbor who points in the same
        # direction we're pointing in.  E.g., when position is in the middle of
        # the below, the non-rejected array includes both the top and left.
        #   v
        #  >>>
        #   v
        # We want to prefer left.
        q & [a[position]]
        # ['>',x] & ['>'] == ['>']
        # ['v',x] & ['>'] == []
        # ['>'] > [], so we select '>'.
       }
    end
    position+=distance
    result=(letter*search_distance)+result # prepend result
  }
  result # if anyone has a better way of returning result, I'm all ears
}

You should be able to simplify your logic somewhat as your added case has been deemed out of the intended scope.

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


text:
Addition on Elliptic Curves
Disclaimer: This does not do any justice on the rich topic of elliptic curves. It is simplified a lot. As elliptic curves recently got a lot of media attention in the context of encryption, I wanted to provide some small insight how "calculating" on an elliptic curve actually works.
Introduction
Elliptic curves are sets of points \$(x,y)\$ in the plane of the form \$y^2 = x^3+Ax+B\$. (Additionally, \$4A^3+27B^2 ≠ 0\$ to avoid nasty singularities.) You can consider these curves in any field. If you use the field of real numbers, the curves can be visualized and they look like this:

Source
The special thing about these curves is that they have a built in arithmetic operation that is the analogue of addition. You can add and subtract points, and this operation is both associative and commutative (an abelian group).
How does addition work?
Note: addition of points on elliptic curves is not intuitive. This kind of addition is defined the way it is because it has certain nice properties. It's weird, but it works.
As elliptic curves form a group, there is an additive identity that is the equivalent of 0. That is, adding \$0\$ to any point will not change the result. This additive identity is the "point" at infinity. All lines on the plane include this point at infinity, so adding it makes no difference.
Let's say that any given line intersects the curve at three points, which may be \$0\$, and that the sum of these three points is \$0\$. Keeping that in mind, take a look at this image.

Source
Now, the natural question is, what is \$P+Q\$? Well, if \$P+Q+R = 0\$, then \$P+Q = -R\$ (alternatively written as \$R'\$). Where is \$-R\$? It is where \$R + (-R) = 0\$, which is on the other side of the x-axis from \$R\$ so that the line through them is vertical, intersecting only \$R\$, \$-R\$, and \$0\$. You can see this in the first part of this image:

Source
Another thing you can see in these images is that the sum of a point with itself means the line is tangent to the curve.
How to find intersections of lines and elliptic curves
In the case of two distinct points
Generally there is exactly one line through two points \$P=(x_0,y_0), Q=(x_1,y_1)\$. Assuming it is not vertical and the two points are distinct, we can write it as \$y = mx+q\$. When we want to find the points of intersection with the elliptic curve we can just write
$$0 = x^3+Ax+B-y^2 = x^3+Ax+B-(mx+q)^2$$
which is a third degree polynomial. These are generally not that easy to solve, but we already know two zeros of this polynomial: The two \$x\$-coordinates \$x_0, x_1\$ of the two points we want to add!
That way we factor out the linear factors \$(x-x_0)\$ and \$(x-x_1)\$ and are left with a third linear factor whose root is the \$x\$-coordinate of the point \$R\$. (\$-R\$ too because of the symmetry. Note that if \$R = (x_2,y_2)\$ then \$-R = (x_2,-y_2)\$. The \$-\$ is from the group; it is not a vectorial minus.)
In the case of adding one point \$P\$ to itself
In this case we have to calculate the tangent of the curve at \$P=(x_0,y_0)\$. We can directly write \$m\$ and \$q\$ in terms of \$A,B,x_0\$ and \$y_0\$:
$$m = \frac{3x_0^2+A}{2y_0}$$
$$q = \frac{-x_0^3+Ax_0+2B}{2y_0}$$
We get the equation \$y = mx+q\$ and can proceed the same way as in the paragraph above.
A complete case tree
This is a complete list of how to handle all those cases:
Let \$P,Q\$ be points on the elliptic curve (including the "infinity" point \$0\$)

If \$P = 0\$ or \$Q = 0\$, then \$P+Q = Q\$ or \$P+Q = P\$, respectively
Else \$P ≠ 0\$ and \$Q ≠ 0\$, so let \$P = (x_0,y_0)\$ and \$Q = (x_1,y_1)\$:

If \$P = -Q\$ (that means \$x_0 = x_1\$ and \$y_0 = -y_1\$) then \$P+Q = 0\$
Else \$P ≠ -Q\$

If \$x_0 = x_1\$ then we have \$P=Q\$ and we calculate the tangent (see section above) in order to get \$R\$. Then \$P+Q = P+P = 2P = -R\$
Else: We can construct a line of the form \$y = mx+q\$ through those two points (see section above) in order to calculate \$R\$. Then \$P+Q=-R\$

Finite fields
For this challenge we will only consider fields of size \$p\$ where \$p\$ is prime (and because of some details \$p ≠ 2, p ≠ 3\$). This has the advantage that you can simply calculate \$\bmod p\$. The arithmetic in other fields is much more complicated.
This in this example we set \$p = 5\$ and all equalities here are congruences \$\bmod 5\$.
2+4 ≡ 6 ≡ 1
2-4 ≡ -2 ≡ 3
2*4 ≡ 8 ≡ 3
2/4 ≡ 2*4 ≡ 3 because 4*4 ≡ 16 ≡ 1, therefore 1/4 ≡ 4

Challenge
Given the parameters \$A,B\$ of an elliptic curve, a prime field characteristic \$p\$ and two points \$P,Q\$ on the elliptic curve, return their sum.

You can assume that the parameters \$A,B\$ actually describe an elliptic curve, that means that \$4A^3+27B^2 ≠ 0\$.
You can assume that \$P,Q\$ are actually points on the elliptic curve or the \$0\$-point.
You can assume that \$p ≠ 2,3\$ is prime.

Test Cases
I made a (not very elegant) implementation in MATLAB/Octave, that you can use for your own test cases: ideone.com I hope it is correct. It did at least reproduce a few calculations I made by hand.
Note the trivial test cases that work for all curves we consider here:

Adding zero: \$P+0 = P\$
Adding the inverse: \$(x,y) + (x,-y) = 0\$

For \$p = 7, A = 0, B = 5\$ the two points \$P = (3,2)\$ and \$Q = (6,2)\$ are on the elliptic curve. Then following holds:
2*Q = Q+Q = P
2*P = P+P = (5,2)
3*P = P+P+P = (5,2)+P = (6,5)
4*P = P+P+P+P = (5,2)+(5,2) = (6,5)+(5,2) = Q

All the points on the elliptic curve are \$(3,2),(5,2),(6,2),(3,5),(5,5),(6,5),0\$

For \$p = 13, A = 3, B = 8\$ we get
(1,8)+(9,7) = (2,10)
(2,3)+(12,11) = (9,7)
2*(9,6) = (9,7)
3*(9,6) = 0

For \$p = 17, A = 2, B = 2\$ and \$P=(5,1)\$ we get
2*P = (6,3)
3*P = (10,6)
4*P = (3,1)
5*P = (9,16)
6*P = (16,13)
7*P = (0,6)
8*P = (13,7)
9*P = (7,6)
10*P = (7,11)

If you are really ambitious, take
p = 1550031797834347859248576414813139942411
A = 1009296542191532464076260367525816293976
x0 = 1317953763239595888465524145589872695690
y0 = 434829348619031278460656303481105428081
x1 = 1247392211317907151303247721489640699240
y1 = 207534858442090452193999571026315995117

and try to find a natural number \$n\$ such that \$n\times(x_0,y_0) = (x_1,y_1)\$. Further information here.
Appendix
First of all a big THANK YOU to @El'endiaStarman for reviewing and editing my draft!
Why elliptic curves?
Well it might appear like some kind of arbitrary equation, but it is not, it is quite general:
Generally we consider those geometric "shapes" in the projective plane (that is where the "infinity" is coming from. There we consider all homogeneous polynomials of third degree. (Those of lower or higher degree would be too difficult or just trivial to examine.) After applying some restrictions in order to get the nice properties we want, and after dehomogenizing those polynomials (projecting into one of three affine planes) we end up with equations like \$y^2+axy+by = x^3+cx^2+dx+e\$ This is an elliptic curve in the long Weierstrass form. These are basically the same curves as we considered, but just somewhat skewed. With a linear coordinate transform, you can easily make a short Weierstras equation out of that. example, which still hold all the interesting properties.
Why did we exclude \$p=2,3\$?
This has to do with the fact that for the short Weierstrass form we need the restriction \$4A^3+27B^2 ≠ 0\$ in order to avoid singularities (more on that below). In a field of characteristic 2 we have \$4 = 0\$ and in a field of characteristic 3 we have \$27 = 0\$, this makes it impossible to have curves in short Weierstrass form for those kinds of fields.
What are singularities?
If the equation \$4A^3+27B^2=0\$ holds, we have singularities like following: As you see at those points you cannot find a derivative and therefore no tangent, which "kills" the operation. You might look at the equations \$y^2 = x^3\$ or \$y^2 = x^3-3x+2\$
Why are they called elliptic curves anyway?
The reason is that equations of this shape pop up in elliptic integrals, e.g. which are what you get when you want to caclulate the e.g. the arclength of an ellipse. A short slideshow about the origin of the name.
What do they have to do with cryptography?
There are ways to compute \$nP = P+P+...+P\$ very efficiently. This can be used for example in the Diffie Hellman key exchange. The modular arithmetic can be replaced by the addition on torsion subgroups, these are just the points on the curve that have finite order. (That means that \$mP = 0\$ for some \$m\$, which is basically just calculating \$\bmod m\$ ).

Another nice read can be found here: https://cp4space.hatsya.com/2021/07/05/one-way-permutations/

Pyth, 105 100 bytes
A,@Q3eQ?qGZH?qHZG?&=YqhHhGqeG%_eHhQZ_m%dhQ,-*J?Y*+*3^hG2@Q1^*2eG-hQ2*-eGeH^-hGhH-hQ2-hGK--^J2hGhHeGK

Input is expected as (p, A, P, Q), where P and Q are the two points of the form (x, y) or, if they are the special 0 point, just as 0. You can try it out online here. The last two examples show how the special 0 works.
In order to save a few bytes, I only use mod p on the final answer. This means that it does things like x0^p a few times without doing modular exponentiation, so it might be very slow.
It works by following roughly the same logic as this Python function:
def add_ellip(p, A, P, Q): # points are in format (x, y)
    z = 0 # representing special 0 point

    if (P == z):
        return Q
    if (Q == z):
        return P

    if P[0] == Q[0]:
        if (P == (Q[0], -Q[1] % p)):
            return z
        else:
            m = ((3*pow(P[0], 2, p) + A)*pow(2*P[1], p-2, p)) % p
    else:
        m = (P[1] - Q[1])*pow(P[0] - Q[0], p-2, p) % p

    x = (pow(m, 2, p) - P[0] - Q[0]) % p
    y = (m*(P[0] - x) - P[1]) % p
    return (x, y)

This is heavily reliant on the fact that the modular multiplicative inverse of x is equal to x^(p-2) mod p if p is prime. Thus we are able to compute m, the slope of the line, by finding the modular multiplicative inverse of the denominator and multiplying it by numerator. Pretty handy. The Python function should calculate larger problems a little more efficiently because of the use of pow.
I also used the shortcuts shown on the Wikipedia page on this subject. It's quite interesting I only end up using A once, and B not at all.
Also just for fun:
def pow2floor(x):
    p = 1
    x >>= 1
    while (x > 0):
        x >>= 1
        p <<= 1
    return p

def multi_nP(p, A, n, P):
    d = {}

    def rec_helper(n, P):
        if (n == 0):
            return (0, 0)
        elif (n == 1):
            return P
        elif (n in d):
            return d[n]
        else:
            p2f = pow2floor(n)
            remainder = n - p2f

            lower_half = rec_helper(p2f//2, P)
            d[p2f//2] = lower_half
            nP = add_ellip(p, A, lower_half, lower_half)

            if (remainder):
                nP = add_ellip(p, A, nP, rec_helper(remainder, P))

            d[n] = nP
            return nP

    return rec_helper(n, P)

The multi_nP function computes n*P for a given integer n and point P. It uses a recursive strategy by splitting n into two parts p2f and remainder such that p2f + remainder = n and that p2f = 2^k. Then we call the function again on those parts, adding the result with add_ellip. I also used basic dynamic programming approach by saving already computed values in the dict d.
The next function would theoretically solve the bonus question using the same strategy:
def find_nPQ(p, A, P, Q): # P is input point, Q is what we're looking for
    d = {}
    found_Q = False

    def rec_helper(n, P):
        if (n == 0):
            return (0, 0)
        elif (n == 1):
            return P
        elif (n in d):
            return d[n]
        else:
            p2f = pow2floor(n)
            remainder = n - p2f

            lower_half = rec_helper(p2f//2, P)
            d[p2f//2] = lower_half

            nP = add_ellip(p, A, lower_half, lower_half)

            if (remainder):
                nP = add_ellip(p, A, nP, rec_helper(remainder, P))

            d[n] = nP
            return nP

    for x in range(p):
        xP = rec_helper(x, P)
        if (xP == Q):
            return x

Unfortunately, it runs nowhere near quickly enough to compute it. I'm guessing there might be much more efficient ways to do this, especially if we don't have to iterate through every possibly value for n.

Great, I honestly didn't expect any ansewers anymore=) How do you handle the point at infinity? (Note that y^2 = x^3 + x is a valid elliptic curve and (0,0) ≠ 0 is a point on the curve!)

Great question... I guess I didn't handle it! :P My apologies, I remember seeing the first picture where B = 0 and wondering how 0 would work... and then I forgot about it. I think I assumed B couldn't be 0 at some point late last night. Do you have any suggestions on what the input should like for this? Perhaps if B = 0, then define 0 = (-1, -1)? I'm happy to adjust my code to handle it, I'm just thinking it would be nice if it is standardized for other submissions as well...

Well I left that pont open such that submissions could use whathever is convenient for them. But of course you could say that e.g. all finite points on the curve have nonnegative coordinates, and everything else is considered as the Infinity point or something similar. Or if it is easier you could also assume that the input [0] (only one coordinate) is the infinity point, or anything similar!

Let me know if that doesn't handle it well enough. And thanks, that actually saved me 5 bytes!

@flawr, would you be able to tell me if I am on the right track for efficiently computing nP? Could you point me to any resources on the subject to get the thoughts flowing? I'm having a hard time finding anything Googling around. Thanks!

I do not know python very well, it seems you are using the usual add_ellip (addition via constructen of the line / solving for intersections) and the efficiency comes form decomposing n into powers of two, right? If yes, this is not what I meant. There are algorithms via polynomial recursion. (Note that you can ignore the y coordinate as it follows (except the sign) from the x coordinate.) I think this book is quite good, but also quite advanced. (Can be found on library genesis.)

Python 3, 193 191 bytes
A solution based on Rhyzomatic's Pyth answer and their Python logic. In particular. I liked how they found the third root of a monic cubic polynomial x^3 + bx^2 + cx + d when you have two roots x_1 and x_2 by noting that b == x_1 + x_2 + x_3 and subtracting accordingly. I plan to add an explanation, golf this, and perhaps transpile it into Ruby, if Ruby turns out to be shorter.
def e(p,A,B,P,Q):
 if P==0:return Q
 if Q==0:return P
 f,g=P;j,k=Q
 if f==j:
  if g==-k%p:return 0
  m=(3*f*f+A)*pow(2*j,p-2)
 else:m=(g-k)*pow(f-j,p-2)
 x=m*m-f-j;y=m*(f-x)-g;return(x%p,y%p)

Ungolfing:
def elliptic_curve_addition(p, A, B, P, Q):
    if P == 0:
        return Q
    if Q == 0:
        return P
    f,q = P
    j,k = Q
    if f==j:
        if g == (-k) % p:
            return 0
        m = (3 * f**2 + A) * pow(2*j, p-2)
    else:
        m = (g-k) * pow(f-j, p-2)
    x = m**2 - f - j
    y = m * (f-x) - g
    return (x%p, y%p)

I'm surprised that Python is less than twice as long as the Pyth answer!

Wolfram Language(Mathematica), 254 bytes.
254 bytes, it can be golfed more.
Modified from @user293787's answer on MSE.

Golfed version. Try it online!
Needs["FiniteFields`"];
f[A_,B_,p_,P:{xp_, yp_},Q:{xq_,yq_}]:=Module[{k=GF[p][{#}]&},xP=k@xp;yP=k@yp;xQ=k@xq;yQ=k@yq;a=k@A;If[And[xP===xQ,yP===-yQ],Infinity,With[{s=If[xP===xQ,(3*xP^2+a)/(2*yP),(yP-yQ)/(xP-xQ)]},With[{xR=s^2-xP-xQ},{xR,-yP-s*(xR-xP)}]]]]

Ungolfed vesrion. Try it online!
Clear["Global`*"];
add[a_][P : {xP_, yP_}, Q : {xQ_, yQ_}] :=
  If[And[xP === xQ, yP === -yQ], Infinity,
   With[{s = If[xP === xQ, (3*xP^2 + a)/(2*yP), (yP - yQ)/(xP - xQ)]},
     With[{xR = s^2 - xP - xQ}, {xR, -yP - s*(xR - xP)}]]];

Needs["FiniteFields`"];
f[a_, b_, p_, P : {xP_, yP_}, Q : {xQ_, yQ_}] :=
  Module[{kk = GF[p][{#}] &
    },
   aa = kk[a];
   bb = kk[b];
   PP = {kk[xP], kk[yP]};
   QQ = {kk[xQ], kk[yQ]};
   e[{x_, y_}] := y^2 - (x^3 + aa*x + bb);
   {PAddQ = add[aa][PP, QQ], e[PAddQ]}
   ];

params = {{0, 5, 7, {6, 2}, {6, 2}}, {0, 5, 7, {3, 2}, {3, 2}}, {0, 5,
     7, {5, 2}, {3, 2}}, {0, 5, 7, {5, 2}, {5, 2}}, {3, 8,
    13, {1, 8}, {9, 7}}, {3, 8, 13, {2, 3}, {12, 11}}, {3, 8,
    13, {9, 6}, {9, 6}}, {3, 8, 13, {9, 7}, {9, 6}}, {2, 2,
    17, {5, 1}, {5, 1}}, {2, 2, 17, {6, 3}, {5, 1}}, {2, 2,
    17, {10, 6}, {5, 1}}, {2, 2, 17, {3, 1}, {5, 1}}, {2, 2,
    17, {9, 16}, {5, 1}}, {2, 2, 17, {16, 13}, {5, 1}}, {2, 2,
    17, {0, 6}, {5, 1}}, {2, 2, 17, {13, 7}, {5, 1}}, {2, 2,
    17, {7, 6}, {5, 1}}};

Do[Print[params[[i]], " -> ", f @@ params[[i]]], {i, Length[params]}]

PARI/GP, 46 bytes
f(a,b,p,P,Q)=elladd(ellinit(Mod([a,b],p)),P,Q)
Attempt This Online!
Using built-ins. The zero point is represented by [0].

PARI/GP, 114 bytes
f(a,b,p,P,Q)=if(!#P,Q,!#Q,P,[x,y]=Mod(P,p);[x,-y]-[w,z]=Q,m=if(d=x-w,(y-z)/d,(3*x^2+a)/2/y);[t=m^2-x-w,m*x-m*t-y])
Attempt This Online!
A port of @Rhyzomatic's Pyth answer. The zero point is represented by 0.

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


text:
Make a directory tree
Imagine for a second that you can compose a tree out of dots.
       .
      ...
     .....
    .......
   .........
  ...........
 .............
...............
      ...
      ...

This tree is 13 dots tall.
Now imagine for a second that your filesystem looked like these dots. Your task in this challenge is to make a tree out of folders.
The Challenge
Given an input integer (let's call it n), make a tree out of subdirectories.

In each tree, you should start with a folder called 1.
In that folder, put the folders 1, 2, and 3.
In every level of folder thereon until n-3, in folder 1 of this level of the tree, there should be a folder labelled 1 and 2. In folder 2 of this level of the tree, there should be a folder called 3, in folder 3, a folder called called 4, and so on until the last folder (the integer this folder is called, we'll call k), in which there should be a folder called k and one called k+1.
At level n-3, however, all of the subdirectories but the middle three folders should be replaced with a file with the name that the subdirectories would have had. The middle three subdirectories should remain as subdirectories.
These three subdirectories should contain a folder called 1, 2, or 3 with respect to the order of these directories' name.
These are followed by a layer of files where 1 is in folder 1, 2 is in folder 2, and 3 is in folder three.

The example shown at the top of this question is represented below in folder form.

This would be n = 13.
Rules

You may use builtins for folder creation, but not for subdirectory creation.
All other standard loopholes apply.
You must support past n=5, but do not have to support greater than n=30.

There are several problems with the original post here.  The tree of dots appears to be 10 dots tall, not 13.  In the graphic, the folders are 9 deep, so I'm assuming it should be n=9.  The last folders on each level contain folders named k+1 and k+2, not k and k+1.

Windows Batch File, 429 423 404 bytes
md 1
set C= call:
set/a M=%1-2
%C%f 1 1 2 L
%C%f 1 2 2 M
%C%f 1 3 2 R
goto:eof
:f
md %1\%2
set/a P=%2+1
set/a Q=%2+2
set/a L=%3+1
set D= (%C%t %1\%2\%P%
if %L%==%M% (if %4==L .>%1\%2\1
if %Q%==%M%%D%1)else (if %P%==%M%%D%2)else (if %2==%M%%D%3)else .>%1\%2\%P%))
if %4==R .>%1\%2\%Q%
)else (if %4==L%C%f %1\%2 1 %L% L
%C%f %1\%2 %P% %L% M
if %4==R%C%f %1\%2 %Q% %L% R)
goto:eof
:t
md %1\%2
.>%1\%2\%2

Call it with the value of n as a command line parameter.
Here is a visualization of the output tree for n=9:
                   1
                +--+--+
                1  2  3
             +--+  |  +--+
             1  2  3  4  5
          +--+  |  |  |  +--+
          1  2  3  4  5  6  7
       +--+  +  |  |  |  |  +--+
       1  2  3  4  5  6  7  8  9
    +--+  |  |  |  |  |  |  |  +--+
    1  2  3  4  5  6  7  8  9 10 11
 +--+  |  |  |  |  |  |  |  |  |  +--+
 1  2  3  4  5  6  7  8  9 10 11 12 13
                |  |  |
                1  2  3
                |  |  |
                1  2  3


text:
Trilaterate your position
Introduction
Imagine you are on a two dimensional cartesian plane and want to determine your position on it. You know 3 points on that plane and your distance to each of them. While it is always possible to calculate your position from that, doing that in your head is pretty hard. So you decide to write a program for that.
The Challenge
Given 3 points and your distance to them, output the cordinates of your position.

Input and output may be in any convenient format, including using complex instead of real numbers. Please clarify in your answer which format you use.
You will always get exactly 3 distinct points with their distance to you.
The coordinates and distances will be floats with arbitrary precision. Your output has to be correct to 3 decimal places. Rounding is up to you. Please clarify in your answer.
You may assume that the three points are not collinear, so there will be always an unique solution.
You are not allowed to bruteforce the solution.
You may not use any builtins that trivialize this particular problem. Builtins for vector norms, etc. are allowed though.

Hint to get started:

 Think about a circle around each of those 3 points with their distance to you as radius.

Rules

Function or full program allowed.
Default rules for input/output.
Standard loopholes apply.
This is code-golf, so lowest byte-count wins. Tiebreaker is earlier submission.

Test cases
Input format for one point here is [[x,y],d] with x and y being the coordinates and d being the distance to this point. The 3 of those points are arranged in a list. Output will be x and then y in a list.

[[[1, 2], 1.414], [[1, 1], 2.236], [[2, 2], 1.0]] -> [2, 3]
[[[24.234, -13.902], 31.46], [[12.3242, 234.12], 229.953], [[23.983, 0.321], 25.572]] -> [-1.234, 4.567]
[[[973.23, -123.221], 1398.016], [[-12.123, -98.001], 990.537], [[-176.92, 0], 912.087]] -> [12.345, 892.234]

You can generate additional test cases with this Pyth program. Location goes on the first line of the input and the 3 points are on the following 3 lines.
Happy Coding!

Because it needs to fit onto a two-dimensional Cartesian plane, the code needs to be as short as possible.

You are obviously using inexact results which still can result in ambiguity, how should we handle this?

@flawr Just assume that all results are exact und unique. Your program should work for cases with very few decimal places, don't worry about ambiguity. I will clean the challenge up when I'm home.

Since the accepted answer is effectively just a graphing calculator, I'll mention that there's a 96-byte solution in TI-Basic (68k version). To clarify, is solve (given three circle equations) trivializing the problem? I thought it was, but if you're okay with such things I'll go ahead and post it.

Desmos, 122 bytes
Online use. Copy+paste each equation into an equation box, click "add all" for each box, then click on the point of intersection, then enter in each value as appropriate. each of A, B, and C are the distances for the points (a,b), (c,d), and (E,f), respectively. To get a square root in the value, type sqrt then the value in the box.
\left(x-a\right)^2+\left(y-b\right)^2=AA
\left(x-c\right)^2+\left(y-d\right)^2=BB
\left(x-E\right)^2+\left(y-f\right)^2=CC

Verify the first test case.
Or you can take a look here:

This looks pretty nice, but does this satisfy our criteria for programming languages? This looks just like a plotting tool for me, never used it tho, so I might be wrong.

@DenkerAffe I actually asked a question about it on meta before, and it does indeed count.

Alright, have my upvote then :)

I dispute the byte count. You get clicking the point of intersection for free, which doesn't seem right.

@lirtosiast I would argue that the point is always there by definition and further state that the OP said that this sort of interaction was okay. If, however, you believe there should be some penalty, I'm open to suggestions.

C, 362 348 345 bytes
Input is given as a sequence of space-separated floats on stdin: x1 y1 d1 x2 y2 d2 x3 y3 d3. Output is similar on stdout: x y.
#define F"%f "
#define G float
#define T(x)(b.x*b.x-a.x*a.x)
typedef struct{G a;G b;G c;}C;G f(C a,C b,G*c){G x=b.b-a.b;*c=(T(a)+T(b)-T(c))/x/2;return(a.a-b.a)/x;}main(){C a,b,c;G x,y,z,t,m;scanf(F F F F F F F F F,&a.a,&a.b,&a.c,&b.a,&b.b,&b.c,&c.a,&c.b,&c.c);x=f(a,a.b==b.b?c:b,&y);z=f(b.b==c.b?a:b,c,&t);m=t-y;m/=x-z;printf(F F"\n",m,x*m+y);}

C is a structure type whose members are an x-coordinate a, a y-coordinate b, and a distance (radius) c. The function f takes two C structures and a pointer to a float, and determines the line at which the C (circles) intersect. The y-intercept of this line is placed into the pointed-to float, and the slope is returned.
The program calls f on two pairs of circles, then determines the intersection of the produced lines.

Since we've clarified that the inputs are not collinear, the lines f produces will never be parallel. The tests are to ensure they are also not vertical, since I'm using slope-intercept form. This way, there is always exactly one answer.

329 bytes

APL (Dyalog Unicode) 18.0, 23 bytes
-∘(+/)⍥(×⍨)⌹⍥(2-⌿⊢)¯2×⊢

Try it online!
A tacit infix function that can be called like dists f pts, where pts contains three centers' coordinates as a 3-row 2-column matrix, and dists contains three distances to the respective centers.
Uses 18.0 feature ⍥. TIO's Dyalog Unicode is not updated yet from 17.1, so TIO link uses Dyalog Extended for demonstration purposes.
How it works
Uses the same method as R.T.'s Python answer, i.e. constructing a linear system of equations and solving it.
The distance equations are necessarily quadratic. Then how did we get linear ones?
Let's consider just two circles, and denote the point we want to find as \$P\$, two circles' centers as \$C, D\$, and their radii as \$r_C, r_D\$. Also, let's use \$A_x, A_y\$ for the \$x\$- and \$y\$-coordinates of a point \$A\$. Then the following equations hold:
$$
(P_x-C_x)^2+(P_y-C_y)^2 =r_C^2 \\
(P_x-D_x)^2+(P_y-D_y)^2 =r_D^2 \\
$$
Then we expand them and subtract the second from the first:
$$
P_x^2-2P_xC_x+C_x^2+P_y^2-2P_yC_y+C_y^2=r_C^2\\
P_x^2-2P_xD_x+D_x^2+P_y^2-2P_yD_y+D_y^2=r_D^2\\
-2P_x(C_x-D_x)+(C_x^2-D_x^2)-2P_y(C_y-D_y)+(C_y^2-D_y^2)=r_C^2-r_D^2\\
-2P_x(C_x-D_x)-2P_y(C_y-D_y)=(r_C^2-C_x^2-C_y^2)-(r_D^2-D_x^2-D_y^2)
$$
We've just got one linear equation on \$P_x\$ and \$P_y\$. Since we have three circles given, we can take any two pairs and construct two equations, which then solving the system of equations gives the coordinates we want.
-∘(+/)⍥(×⍨)⌹⍥(2-⌿⊢)¯2×⊢  ⍝ Left: dists, Right: pts
-∘(+/)⍥(×⍨) ⍥(2-⌿⊢)      ⍝ Constants part
      ⍥(×⍨)              ⍝ Square each number in both dists and pts
 ∘(+/)                   ⍝ Row sums of squared pts
-                        ⍝ Subtract above from squared dists
            ⍥(2-⌿⊢)      ⍝ Take pairwise difference

            ⍥(2-⌿⊢)¯2×⊢  ⍝ Coefficients part
                   ¯2×⊢  ⍝ -2 times pts
            ⍥(2-⌿⊢)      ⍝ Take pairwise difference between rows
           ⌹             ⍝ Solve linear equations

Python - 172
Takes input as a list of tuples of form (x,y,d). Let me know if you see a way to golf this further, I feel like there must be but I can't figure it out!
import numpy as N
def L(P):
    Z=[p[2]**2-p[0]**2-p[1]**2 for p in P];return N.linalg.solve([[P[i][0]-P[0][0],P[i][1]-P[0][1]]for i in[1,2]],[(Z[0]-Z[i])*0.5 for i in [1,2]])

You can omit some whitespaces here. Something like -1 if 1 else 1 can become -1if 1else 1 for example. This also works with brackets.There are a few places where you can take advantage of that. Also .5 is the same as 0.5.


text:
Is this a valid variable name?
Write a program or function that

checks if a variable name is valid and
output 1 or True if it is valid,
0.5 if it is valid but starts with an underscore (_),
and 0 or False if it is not valid.

Rules

A variable name in most languages is valid if it begins with an underscore or letter (a – z, A – Z, _) and the rest of the characters are either underscores, letters, or numbers. (a – z, A – Z, 0 – 9, _)
Output 1 or True if the variable name is valid and 0 or False if not valid.
However, it is not good practice to start a variable with an underscore, so return 0.5 if it starts with an underscore and the name is valid.
Standard loopholes apply.

Test Cases

input
output
reason

abcdefghijklmnop
1

_test_
0.5
starts with an underscore

123abc
0
starts with a number

A_b1C_23
1

_!
0
not 0.5 because it’s not valid

magical pony1
0
no spaces

Scoring
This is code-golf, so shortest code wins.
Bonus: −10% if your program/function outputs 0 for an empty string("").

can we output true/false/0.5?

Can we output truthy/falsy/anything?

You can output true/false/0.5

Just noting, in python, under scores are often used.  Classes need an init function, helper functions in classes are sometimes begun with an underscore.

@EasterlyIrk beware of mini-markdown; you meant __init__; also, no, classes do not need an __init__ but typically have one

Can we assume that the input will be non-empty? (Most of the current answers seem to fail for empty input.)

-2% for accounting for an empty input.

Does that bonus round up or down? If up, it's really not worth having for the current set of answers

@muddyfish Why would the bonus round at all?

-10% now, and don't round. Express your answer as a decimal.

shouldn't a single underscore return 0?

No, it should return 0.5. In languages like JavaScript, you can define a variable called _.

I see, you're right!

May we assume the input is entirely made of digits, plain Latin letters, underbars, and spaces?

MATLAB has a built-in function to check for valid variable names that conform to exactly the same rules as seen here (except for the 0.5 for the beginning underscore).  Are built-in functions allowed?

@Nᴮᶻ No, the fitfh test case contains an exclamation mark, so I don't think so.

Several current answers incorrectly give 1 for non-ASCII input, like Ψ.

May we assume the input is entirely made of ASCII (≤127)? (Ping @AandN)

If you do, you must say so in your answer.

JavaScript (ES6), 37 - 10% = 33.3 bytes
Saved 4 bytes thanks to @edc65
Saved 5.6 bytes thanks to @Mateon
s=>!/^\d|\W|^$/.test(s)/-~(s[0]=='_')

Are you absolutely sure this is not perl?

05AB1E, 25 24 20 19 bytes
Code:
¬D'_Qsa·+¹žj-""Q*2/

Explanation:
¬                     # Push input and also push the first character.
 D                    # Duplicate the first character.
  '_Q                 # Check if it is equal to an underscore character.
     sa               # Swap and check the duplicate if it's an alphabetic character.
       ·              # Double the value.
        +             # Add both values up
         ¹            # Take the first input.
          žj-         # žj is short for [a-zA-Z0-9_]. This will be substracted from the
                        initial string.
             ""Q      # Check if the string is empty.
                *     # Multiply this with the first value.
                 2/   # Halve it, resulting into 0.0, 0.5, or 1.0.

In short, the formula for the string s in pseudocode is:
((s[0] == '_' + s.isalpha() × 2) × (s.remove([a-zA-Z0-9_]) == "")) / 2

Try it online!
Uses CP-1252 encoding.

PHP (50 - 10% = 45)
Thanks to Schism for the -2 :)
preg_match('/^[a-z_]\w*$/i',$s)?$s[0]=='_'?.5:1:0;

Not to compete with the golflang answers, but I thought I'd try it anyways.
preg_match('/^[a-z_]\w*$/i', $s) # Matches every a-zA-Z0-9_ string that doesnt start with a number
?   $s[0] == '_'                   # Then, if it starts with an _
    ?   .5                         # give 0.5 points
    :   1                          # If it doesn't, give 1
:   0;                             # If it didn't match the regex, give 0

Something to note is that in PHP, without the /u modifier, \w only selects ASCII letters. In some other languages/Regex flavours, this pattern won't work.
Edit: I see a lot of people using \w and \d in their answers, when they use a language that includes non-ASCII letters and digits too. That is NOT the puzzle. They are wrong. (Can't downvote/comment yet, sorry to need to tell it this way.)

Welcome to Programming Puzzles and Code Golf Stack Exchange. This is a great answer; often [tag:code-golf] challenges are within languages as well as between them. I'm giving you a +1 for this solution! Well done.

You can shave off two characters with [a-z].../i.

@Schism Thank you. Don't know how I managed to forget that, usually I'm good at these kind of regex puzzles :)

About your edit: can you be more specific - what languages? In javascript \d is exactly the same as [0-9]. \w is exactlly the same as [A-Za-z0-9_] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

The code page that the language uses is irrelevant; as long as the regex properly handles ASCII, it's valid. All of the current regex-based answers work, to my knowledge. You're not trying to match a variable name in your language; rather, you're trying to match a variable name based on the rules in the challenge.

Retina, 30 - 10% = 27 28 - 10% = 25.2 29 - 10% = 26.1 bytes
Both versions qualify for bonus, as they handle empty input correctly (outputs 0)
I had to fix a bug caused by one of .NET regex features, which considers some (read as many) Unicode characters as "word" characters. Fortunately, this cost me only a single byte in both versions. It only came down to adding a modifier to make the regex matching behavior compliant to ECMAScript standards. More about that here.
New 28 29-byte version, made by @MartinBüttner. Thanks!
^_
$_¶_
Mme`^(?!\d)\w+$
2
0.5
Explanation
First, we check if the input starts with an underscore. If it does, the input is duplicated, with a newline in between. For example: _test_ -> _test_\n_test_, where \n is the newline. Then we try to match anything, that doesn't start with a number, but is followed by any number of "word" characters (a-z, A-Z, digits, and underscore) on each line. Note that if input started with an underscore and was replaced to two lines, this will match both lines. Then we check if we had 2 matches, and replace them with 0.5. Empty or invalid line will always yield 0 matches, and valid variable names always yield 1 match.

My own 30 31-byte version
Ae`^\d|\W
^_.*
0.5
^\D.*
1
^$
0
Explanation
First of all, we check if input starts with a digit or contains a non-word character (anything other than a-z, A-Z, digits and underscore). If it does, it's discarded, because it's invalid. Then we check if it starts with an underscore. If it does, it's replaced with 0.5. Then we check if it starts with a non-digit character (at this point the first character is either 0, a-z, or A-Z. Only a-z and A-Z are non-digits, obviously). If it does, it's replaced with a 1. Then we check for empty string and replace it with 0.
Try it online!
Try it online! Old version

Waitwaitwait. At the ^\D.* stage it can start with a 0? That's weird.

@CatsAreFluffy It can, if it started with a _ and was replaced with 0.5. Then it starts with a 0.

This incorrectly gives a 1 for input Ψ.

@TimmyD Interesting. I don't understand why does it do so. Quick check indicates that \w is matching non-ASCII characters, which it shouldn't do (I've tried to give it ƜƝƞƟƠ and ᎳᎴᎵᎶᎷᎸᎹ as input). I'll look into this later. Possible solution seems replacing \w with [a-zA-Z\d_].

Python 3, 36 bytes
lambda s:s.isidentifier()/-~(s[:1]=='_')

The code is 40 bytes long and qualifies for the -10% bonus.
Note that this will only work correctly for code pages that don't have non-ASCII letters/digits.

MATL, 27 bytes
1)95=2/8M3Y2m+G7M95h4Y2hmA*

This works in current version(15.0.0) of the language.
Input is a string with single quotes.
Try it online!
Explanation
1)      % take input implicitly. Get its first element
95=     % true if it equals 95 (underscore)
2/      % divide by 2: gives 0.5 if underscore, 0 if not
8M      % push first element of input again
3Y2     % predefined literal: string with all letters
m       % true if it's a letter
+       % add. Gives 1 if letter, 0.5 if underscore
G       % push input again
7M      % push string with all letters again
95h     % concatenate underscore
4Y2h    % predefined literal: string with all digits. Concatenate
mA      % true if all input chars belong to that concatenated string
*       % multiply. Display implicitly

Pyke, 21 bytes
(noncompeting, added string subtraction, various string constants)
Qh~u{Q~J\_+-|!Qh\_qh/

Explanation:
Qh~u{                 - Check first char isn't a digit
     Q~J\_+-          - Is the input alphanumeric + "_"
            |!        - Combine
              Qh\_q   - Is the first char an "_"
                   h/ - Combine

Dyalog APL, 19 bytes - 10% = 17.1
{(0≤⎕NC⍵)÷1+'_'=⊃⍵}

{…⍵…} anonymous function where the right argument is represented by ⍵
⊃⍵ first character (gives space if empty)
'_'= 1 if equal to 'underbar, 0 otherwise
1+ evaluates to 2 if initial underbar, 1 otherwise
⎕NC⍵ name class; -1 if invalid name, 0 if undefined (but valid name), 2-9 if defined (and thus valid)

Factor, 84 * 0.9 = 76.5
USE: regexp
[ R/ [_a-zA-Z]\w*/ R/ _.*/ [ matches? 1 0 ? ] bi-curry@ bi 0 = 1 2 ? / ]

Runs on the listener (repl), defines a quotation (anonymous function) that takes a string and outputs { 0 | 1/2 | 1 }.
Defining it as a word it's 97 chars:
USE: regexp
: v ( s -- n ) R/ [_a-zA-Z]\w*/ R/ _.*/ [ matches? 1 0 ? ] bi-curry@ bi 0 = 1 2 ? / ;

How does it work:
R/ [_a-zA-Z]\w*/ R/ _.*/ defines two regular expressions. bi-curry@ partially applies the quotation [ matches? 1 0 ? ] to each regex, leaving two curried quotations on the stack. bi applies each quotation to the argument string.
Each of those (curried quotations) leave either a 1 or a 0, depending if they matched. The first matches on the well formed names, the second on names starting with underscore.
0 = 1 2 ? / The last value is replaced with a 1 if it was 0, or with a 2 if it was 1. Then the first (1 or 0, valid or not) is divided by the second (2 or 1, starts with underscore or not).
This is loooong! Any pointers to shrinking a bit more appreciated...
And I hate regexps!
PS.
{ 0 } [ "" v ] unit-test
{ 0 } [ "" v ] unit-test
{ 0 } [ "1" v ] unit-test
{ 0 } [ "1var" v ] unit-test
{ 0 } [ "var$" v ] unit-test
{ 0 } [ "foo var" v ] unit-test
{ 1 } [ "v" v ] unit-test
{ 1 } [ "var" v ] unit-test
{ 1 } [ "var_i_able" v ] unit-test
{ 1 } [ "v4r14bl3" v ] unit-test
{ 1/2 } [ "_" v ] unit-test
{ 1/2 } [ "_v" v ] unit-test
{ 1/2 } [ "_var" v ] unit-test
{ 1/2 } [ "_var_i_able" v ] unit-test
{ 1/2 } [ "_v4r14bl3" v ] unit-test

all test pass ;)

Just wondering, is the whitespace truly necessary? I can't say for sure since I don't know the language or have the interpreter.

@MamaFunRoll yeah, not the best golfing language! In the Forth tradition, only delimiter are whitespace chars.

Oh, I see. Here, have an upvote.

Yay, ty! Now to break havoc with my comment-everywhere priv!

Pyth, 27 bytes
c!|-rz0++G\_JjkUT}hzJhqhz\_

Test Suite

Gogh, 29 bytes
÷"[^\W\d]\w*"g¦"_.*"g+÷2=0.5¿

Run using:
$ ./gogh no '÷"[^\W\d]\w*"g¦"_.*"g+÷2=0.5¿' "_test"

Explanation
                   “ Implicit input                               ”
÷                  “ Duplicate the TOS                            ”
"[^\W\d]\w*"g      “ Fully match the STOS against the TOS (regex) ”
¦                  “ Swap the STOS and TOS                        ”
"_.*"g             “ Fully match the STOS against the TOS (regex) ”
+                  “ Add the TOS to the STOS                      ”
÷                  “ Duplicate the TOS                            ”
2=                 “ Determine if the TOS is equal to 2           ”
0.5¿               “ Leave the correct output on the stack        ”
                   “ Implicit output                              ”

Perl, 21 bytes
$_=!/\W|^\d//2**/^_/

The score includes +1 byte for the -p switch. Try it on Ideone.

could you have, say -$_||$_=... to account for the empty answer? (using - because + is a noop in perl)

No, that's a runtime error. But even if it worked, it would make my score worse.

I only did minimalistic tests, so I'll trust you. Fair that 10% of 21 bytes isn't much..

Pyth, 19 bytes
c!:z"\W|^\d"0h!xz\_

Try it with the Pyth Compiler.
Note that this will only work correctly for code pages that don't have non-ASCII letters/digits.
How it works
c!:z"\W|^\d"0h!xz\_  (implicit) Save the input in z.

  :z        0        Test if z matches the following regex:
    "\W|^\d"           A non-word character or a digit at the beginning.
                     This returns True iff z is an invalid name.
 !                   Apply logical NOT to yield True iff z is a valid name.
               xz\_  Find the first index of the underscore in z.
                     This yields 0 iff z begins with an underscore.
             h!      Apply logical NOT and increment.
                     This yields 2 if z begins with an underscore, 1 otherwise.
c                    Divide the two results.

Python, 84 -10% = 76 bytes
lambda x:[0,[[.5,1][x[0]>'z'],0][x[0]<'A']][x.replace('_','a').isalnum()]if x else 0

Perl, 34 + 1 = 35 bytes
$_=/^([^\W\d])\w*$//(($1 eq"_")+1)

Uses the -p flag.
Explanation
$_=/^([^\W\d])\w*$//(($1 eq"_")+1)
   /^([^\W\d])\w*$/                 matches any string that starts with an underscore or a letter of the alphabet followed by 0 or more alphanumeric + underscore characters. The first character is stored in a capture group
                   /                divide result by
                    (($1 eq"_")+1)  (capture == "_") + 1. This is 1 if the first character was not an underscore and 2 if it was.
$_=                                 assign to $_ and implicitly print

[_a-zA-Z] -> [^\W\d] if perl works the same as JavaScript, I think you'd also have to do \w*

@Downgoat Seems to work fine with \w+.

matches false for a

@Downgoat Ah, right. I see.

Mathematica, 93 bytes
If[#~StringMatchQ~RegularExpression@"[A-Za-z_][0-9A-Za-z_]*",If[#~StringTake~1=="_",.5,1],0]&

I'm honestly not sure if this can be golfed further.

Vyxal, 22 bytes
hkdc¬:[kr\_+?F¬?h\_=ß½

Try it Online!
A mess.

Japt, 23 bytes
Guess which genius once upon a time suggested removing _ from Japt's \w character class thereby costing himself 3 bytes here! ETH was going to add a new class with _ included but then he disappeared.
¥f"[%l_][%w_]+")/ÒUè"^_

Try it or run all test cases

japt forking time?

Lua, 82 - 10% = 73.8
v=function(s)return(s:match("^[_%a]+[_%w]*$")and 1or 0)*(s:match("_")and.5or 1)end

Test Cases:
print(v("a") == 1) -- true
print(v("1") == 0) -- true
print(v("_") == 0.5) -- true
print(v("") == 0) -- true
print(v("1a") == 0) -- true
print(v("a1") == 1) -- true
print(v("_1") == 0.5) -- true
print(v("_a") == 0.5) -- true
print(v("1_") == 0) -- true
print(v("a_") == 0.5) -- true

I think you can use STDIN to eat at least 10 bytes.

Lua, 68 * .9 = 61.2 bytes
s=arg[1]print(s:find("^[%a_][%w_]*$")and(s:find("^_")and.5or 1)or 0)

Takes arguments on the command line

JavaScript ES7, 37 bytes
x=>!x.match(/\W|^\d/)/2**/^_/.test(x)

Try it online
How it works:
x=>                                   // Fat arrow function
   !x.match(/\W|^\d/)                 // Gives false if contains non word or starting
                                      //   with a digit. Booleans in numeric context will
                                      //   be 0 or 1
                      2**             // 2 to the power of...
                         /^_/.test(x) // gives true if starting with '_'.
                                      //   true -> 1 -> 2**1 -> 2
                                      //   false -> 0 -> 2**0 -> 1
                     /                // Devide the lValue boolean with the numeric rValue:
                                      // lValue = 0 or 1
                                      // rValue = 2 or 1

Port of @Dennis's Perl answer

Ruby, 57 - 10% = 51.3 bytes
->(s){case s
when'',/^\d/,/\W/
0
when/^_/
0.5
else
1
end}

A pretty naïve approach

51.3 bytes, mind you. :)

@Xesau whoops - embarassing. Fixed now :)

You save a huge amount of bytes if you use ternary chaining: ->(s){s=~/^$|^\d|\W/?0:s=~/^_/?0.5:1}

@KevinLau True - I added another ruby answer in that vein already (though it's not great either)

Ruby, 44 bytes
->(s){s=~/^(_|\d)?\w*$/?$1?$1==?_?0.5:0:1:0}

You don't need parens around the parameters for stabby lambdas

Also if you can figure out a way to drop that extra ternary you can probably save some bytes.  Maybe /^([a-z_]).../i instead of /^(_|\d)?.../

@NotthatCharles D'oh... you're right. I'll give it a closer look when I a chance

Julia 1.3, 46 44 -10% = 41.4 39.6 bytes
!s=[1 .5]count.(r"^[a-z]\w*$"i=>r"^_\w*$",s)

Try it online!
explanation

r"^[a-z]\w*$"i is the regex for a variable not starting with a _ (the i means case-insensitive)
r"^_\w*$" for a variable starting with a _
count.() counts the number of time each regex appears in s, result is in a vector (similar to a 2×1 matrix)
[1 .5] is a 1×2 matrix, when multiplied by the previous result, gives the expected result (0.5 when starting with _, 1 otherwise)

Scala 3, 85 bytes
Golfed version. Attempt This Online!
s=>if(s.isEmpty||s(0).isDigit|| !s.matches("^\\w+$")).0 else if(s(0)=='_').5 else 1.0

Ungolfed version. Attempt This Online!
object Main {
  def main(args: Array[String]): Unit = {
    val testCases = Map(
      "abcdefghijklmnop" -> 1,
      "_test_" -> 0.5,
      "123abc" -> 0,
      "A_b1C_23" -> 1,
      "_!" -> 0,
      "magical pony1" -> 0
    )

    testCases.foreach { case (input, expected) =>
      val result = validateString(input)
      println(s"Input: $input, Expected: $expected, Result: $result, Correct: ${result == expected}")
    }
  }

  def validateString(s: String): Double = {
    if(s.isEmpty || s.head.isDigit || !s.matches("^\\w+$")) {
      0.0
    } else if(s.head == '_') {
      0.5
    } else {
      1.0
    }
  }
}

Perl 5, (22 + 1 -p bytes) * .9 = 20.7
$_=!/\W/*/^\D//2**/^_/

Try it online!


text:
Walking on the Hypercube
I recently read up on graph theory, especially hypercubes and thought about interesting ways to construct paths on them. Here's what I came up with.
As you might know, you can construct an n-dimensional hypercube by taking all n-tuples consisting of 1 and 0 as vertices and connect them, iff they differ in one digit. If you interpret these binary digits as an integer number, you end up with a graph with nicely numerated vertices. For example for n=3:

Let's say you want to take a walk on this hypercube and start at the vertex 0. Now, how do you determine which vertex you want to visit next? The rule I came up with is to take the number a of the vertex you are on, flip its mod(a,n)s bit (zero-based indexing) and go to the resulting vertex.
Formally this rule can be recursively defined as
a[m+1] = xor(a[m], 2^mod(a[m],n)).

By following this rule, you will always stay on the cube and travel along the edges. The resulting path looks like this

As you can see, you will walk in a circle! In fact, in all dimensions and for all starting points your path will end up in a loop. For example for n=14 and a[0]=0 it looks like this

For the avid ambler, the length of his planned route is quite a crucial information. So, your job is to write a function or a program that takes the hypercube dimension n an the starting vertex a[0] as inputs and output the number of vertices in the resulting loop.
Test cases
n   a[0]   Output
-----------------
3   0      6
14  0      50
5   6      8
17  3      346

Rules

Standard loopholes are forbidden
Output/Input may be in any suitable format
You may assume a[0] to be a valid vertex

Scoring
Shortest code in bytes wins.
If you have any additional information on this topic, I'd be glad to hear!

Given the rule a[m+1] = xor(a[m], 2^mod(a[m],n)), it's irrelevant if the vertices belong to a hypercube, right?

Right. If a[m] was on the hypercube, a[m+1] will be too. And as you can assume a[0] to be a valid vertex, you pretty much don't need to care about any hypercube stuff and just follow the rule.

Where are the hyper ants?

Jelly, 9 bytes
%⁴2*^µÐḶL

Takes two command-line arguments.
%⁴2*^µÐḶL        A monadic link. Inputs: a_0. b also taken from command line.
%⁴2*^              Variadic link. Input: a
%⁴                   a modulo b. ⁴ is second input, b.
  2*                 Get 2 to that power
    ^                and bitwise xor with a.
     µ             Start a new, monadic link (input: a_0)
      ÐḶ             All elements of the cycle created when the preceding link
                     is applied repeatedly, starting with a_0.
        L            Length.

Try it here.

Haskell, 124
import Data.Bits
(y:z:w)%(x:s)|x==y||x==z=[i|(i,r)<-zip[1..]s,r==x]!!0|0<1=w%s
g n=(tail>>=(%)).iterate(\a->xor a$2^mod a n)

This finds the circle by the two-pointers-going-around-in-different-speeds algorithm, and heavily uses/abuses Haskell's approach to lists (for example, the two pointers are actually lists).
g is the function that computes the answer. give it n and then a[0] and it will return the number to you (note that n should be defined to be of type Int to avoid type ambiguity).

Pyth, 22 17 bytes
Lx^2%bQbl.uyNuyGE

Explanation:
Lx^2%bQbl.uyNuyGE     Implicit: Q=first line n. E=second line a[0].
Lx^2%bQb              y = lambda b: do one iteration
                      Then
             uyGE     Apply y until a previous result is found.
                      This makes sure we're in the cycle.
         .uyN         Then apply y again until a previous result is found.
                      Keep all intermediate values but not the repeat.
        l             Get the length; i.e. the length of the cycle.

Try it here.

MATL, 38 37 28 bytes
xi`vt0)2y1G\^Z~yywP=fn~]2M1$

This works in current version(15.0.0) of the language.
Try it online!
Explanation
x       % take first input: n. Delete (gets copied into clipboard G)
i       % take second input: initial value of a
`       % do...while loop
  v     %   concatenate all stack contents vertically
  t0)   %   duplicate. Get last element of that array: current a
  2     %   push 2
  y     %   duplicate second-top element in stack: current a
  1G    %   push first input (n)
  \     %   a modulo n
  ^     %   2 raised to that
  Z~    %   xor of that with current a
  yy    %   duplicate top two elements in stack: array of old a's and new a
  w     %   swap: move array of old a's to top
  P     %   reverse that array. So first entry is most recent a (before current)
  =f    %   indices of old values that equal current value. There may be 0 or 1
  n~    %   is it empty?
]       % if so, continue with a new iteration
2M      % push array of indices. It contains exactly 1 index
1$      % set 1 input for implicit display function, so it only displays the index

JavaScript (ES6), 69 bytes
(n,a)=>{g=m=>m^1<<m%n;for(c=1,b=a;(b=g(g(b)))!=(a=g(a));)c++;return c}

Returns 18812 for (23, 10).