text:
Bridge Hand Scoring
One of the things that makes contract bridge very interesting is its highly complicated "artificial" meta game. This system of scoring hands is a small part of it.
Bridge is a trick-taking card game. Each player gets a hand of 13 cards, and the game starts with the bidding. The bidding determines how the rest of the game plays, and so is a crucial part of it. In order to ensure that you and your partner do not bid too high (or too low), this artificial scoring system was developed to tell you how good your hand is.
Scoring
Here's a sample hand:
S:KQT5
H:J72
D:965
C:AK8

The S, H, D, C represent the suits (spades, hearts, diamonds and clubs) and the rest are the cards in those suits. So this hand has a queen of spades (Q), king of spades (K), ten of spades (T), five of spades, jack of hearts, seven of hearts, etc.
The scoring system works as follows:

You get 4 points for every ace (A) you have, 3 points for every king (K), 2 points for every queen (Q) and 1 point for every jack (J). No other cards give points.
Every card after the fourth in a suit gives you 1 point. So if you have six hearts, you'd get 2 points.
A suit where you only have 2 cards gives you 1 point (this is a doubleton). A suit where you have just 1 card gives you 2 points (this is a singleton). If you have no cards in a certain suit, you get 3 points (this is a void). (Usually these are only counted once you've agreed on a suit with your partner, but I'm including them to make the challenge more interesting.)

So, the above hand has 13 points.
Challenge
Given a bridge hand in the format shown above, calculate how many points the hand has. The suits will always be listed in the order spades, hearts, diamonds and clubs, and the cards will always be sorted in the order A, K, Q, J, T, 9 - 2.
Sample Inputs and Outputs
S:KQT5
H:J72
D:965
C:AK8
       \-> 13

S:AKQT6
H:54
D:J83
C:732
       \-> 12

S:
H:KQT8754
D:A86
C:432
       \-> 15

S:9876
H:843
D:652
C:432
       \-> 0

S:AKQT5
H:AQJ6
D:Q3
C:AK
       \-> 28

This is code-golf, so shortest code in bytes wins.

Jelly, 27 25 21 bytes
Thanks @Dennis for -3 bytes!
L_5.AḞW+“JQKA”i$€Sµ€S

This takes input as a list of lines. To take input as a multiline string, precatenate a ṣ⁷µ.
Making a table of the frequency points:
Cards:    0  1  2  3  4  5  6 ... 4+k
Points:   3  2  1  0  0  1  2 ... k

we can see that they're equal to abs(c-3.5)-.5, where c is the number of cards. Since each line contains two extra characters, and the number of points is always an integer, this is floor(abs(l-5.5)) where l is the line length.
Note that Jelly's indices are 1-based, and also the behavior of vectorized functions on mismatched dimensions: the extra elements of the longer list are unaffected. So [1] + [3,2,0,0] gives [4,2,0,0].
                  µ      The program is two monadic fs applied in turn; an atop.
L_5.AW+“JQKA”i$€S       Helper function:
                 €        For €ach line:
L                         Get the line Length.
 _5.                      Subtract 5.5 (Numeric literals' decimal parts default to .5)
    A                     Apply Absolute value
     Ḟ                    Floor
      W                   Then Wrap it in an array. "S:AKQT6" gives [1].
        “JQKA”i$          Monadic function: index into the string "JQKA".
                €         Apply ^ over €ach char of the line; [3,2,0,0,0].
       +                  Add the two arrays together; [4,2,0,0,0].
                 S        Sum; 6.
                    S    Main link: Sum all results

Try it here.

ES6, 107 99 89 bytes
s=>(t=0,[...s].map(c=>t+="JQKA".search(c)+1),s.split`
`.map(l=>t+=(l=l.length-6)^l>>4),t)

Pyth, 27 25 24 bytes
sms+a5.5ldshMxL"JQKA"d.z

We calculate the values separately for each suit, then add them.
  s m                 sum of map lambda d:  (d is a line of input)
      +                 add the
        s a                 floor of the absolute difference between
            5.5               5.5
            l d               and len(d)
          s hM xL           to the sum of the indices each incremented by one
                  "JQKA"      of each char in d in the string "JQKA"
                  d
      .z

Test suite.

Retina, 77 59 bytes
T`AKQJTd`5-1
:(.){0,3}(.)?
$#1$#1$#2 3$0
\S
$0$*1
+`1 1

1

Explanation by lines/line pairs:

In the first line we convert chars AKQJT987655432 to 5432111111111. This means for every suit we have a sum. If we have 0 1 2 3 4 5 6 7 ... cards in this suit, the sum is off by +3 +1 -1 -3 -4 -4 -4 -4 ... from the correct score.
In lines 2 and 3 to correct this we add 3 to every line and before a space we add values which we will subtract. This subtracted value is twice the length of cards with a max of 3, and 1 more if there are at least 4 cards.
In lines 4 and 5 we convert digits to unary dropping everything else except the separator space.
In lines 6 and 7 we do unary subtraction.
In line 8 we count up the 1's which gives the result.

Try it online here.

APL (Dyalog Classic), 24 bytes
+/(⌊∘|5.5-≢¨),5|'JQKA'⍳∊

Try it online!
uses ⎕io=1

Stax, 18 bytes
½Γ}♣▓="pì∩û╨▐M↨}╚-

Shortest answer so far, defeated Jelly (although I expect to be defeated soon ...)
Run and debug online!
Explanation
Uses the unpacked version to explain.
LZF{"JQKA"I^+i5-:++F5+
L                         Collect input in a list (if this is not needed, we can yet save another byte)
 Z                        Put a zero under the top of the stack, used as the accumulator
  F                       Loop for every suit
   {               F      Calculate the "score" for the string describing the suit
    "JQKA"I^              Find the 1-based index of current character in "JQKA", 0 for not found
            +             Add to the accumulator
             i5-:+        Subtract 5 from the current 0-based index, and take the sign
                  +       Add to the accumulator
                    5+    Add 5 extra points for each suit

This is achieved by translating

Every card after the fourth in a suit gives you 1 point. So if you have six hearts, you'd get 2 points.
A suit where you only have 2 cards gives you 1 point (this is a doubleton). A suit where you have just 1 card gives you 2 points (this is a singleton). If you have no cards in a certain suit, you get 3 points (this is a void).

To

Score 3 extra points for each suit
Each card before the fourth in a suit gives you -1 point, each card after the fourth gives you 1 point, the fourth card scores 0.

Then we can make use of the property of the signum function.
By doing this we can avoid explicit handling of number of cards saving a few bytes.

 Python, 123 bytes
k=input()
l=k.split("\n")
print(4*k.count("A")+3*k.count("K")+2*k.count("Q")+k.count("J")+sum([max(len(m)-6,0) for m in l])

.count is a wonderful function for these purposes, and I don't use [2:] for the sum of lengths because I can just subtract an extra 2.
Overall, this answer just does it the simple way.


text:
Electrons bouncing in a wire
Imagine a "wire" that has n spaces. Imagine further that there are "electrons" in that wire. These electrons only live for one unit of time. Any spaces in the wire that are adjacent to exactly one electron become an electron. In Game of Life terminology, this is B1/S.
For example, this is a wire of length 10, with period 62.

Rules

Input, n, is a single, positive integer.
Output must be a single integer denoting the period of a wire of length n.
The starting state is a single electron at one end of the wire.
The period does not necessarily include the starting state. Some lengths never return to the starting state, but all of them are periodic.
A static wire (i.e., one without electrons) has period 1.
Boundary conditions are not periodic. That is, the wire is not toroidal in any way.

Test cases
Special thanks to orlp for producing this list. (I have verified it up to n=27.)
1 1
2 2
3 1
4 6
5 4
6 14
7 1
8 14
9 12
10 62
11 8
12 126
13 28
14 30
15 1
16 30
17 28
18 1022
19 24
20 126
21 124
22 4094
23 16
24 2046
25 252
26 1022
27 56
28 32766
29 60
30 62
31 1
32 62
33 60
34 8190
35 56
36 174762
37 2044
38 8190
39 48
40 2046
41 252
42 254
43 248
44 8190
45 8188

You can see test cases for n=2 through 21 here with my Game-of-Life-esque simulator: Variations of Life.

EDIT: the sequence here has been published as A268754!

all of them are periodic And the period is upper-bounded by 2^n-1, because that's the number of possible nonzero states of the "wire"

@LuisMendo: Actually, the upper bound is less because electrons are never adjacent. Exactly how much less, I don't know.

The period does not necessarily include the starting state. Some lengths never return to the starting state, but all of them are periodic. Do you have an example?

@edc65: A wire of length 5 is the smallest example.

@El'endiaStarman The upper bound is actually the Fibonacci numbers. (For length n, you'll either have an empty cell first, which means you can choose the remaining n-1 arbitrarily, which gives s(n-1) strings; or you'll start with a filled cell which means the next one has to be empty and you can then treat the remaining n-2 as a separate string. So s(n) = s(n-1) + s(n-2). And s(1) = 2, s(2) = 3.)

Of course the interesting question would be whether this bound can be brought down further based on the dynamics of the CA, since the sequence clearly grows much slower than the Fibonacci numbers.

More strongly, electrons alternate between odd and even positions, so the period is at most 2^(n/2+1).

Python 2, 148 142 87 bytes
n=input()
p=l=1
t=1
h=2
while t!=h:
 if p==l:t,l,p=h,0,p*2
 h=h/2^h*2%2**n;l+=1
print l

Uses Brent's cycle detection algorithm, and thus actually runs fast.

I have also written an animation in Python (both 2 & 3 work). It needs pyglet to run. You can view the animation by running:
python -m pip install --user pyglet
curl -s https://gist.githubusercontent.com/orlp/f32d158130259cbae0b0/raw/ | python

(Feel free to download the gist and inspect the code before running.) You can press the + and - keys to increase/decrease the n being visualized.

And finally, for those interested in exploring this number sequence further, here is a readable version (this was used to generate the test cases above):
# Brent's cycle detection, modified from wikipedia.
def electron_period(n):
    wire_mask = (1 << n) - 1
    power = lam = 1
    tortoise, hare = 1, 2
    while tortoise != hare:
        if power == lam:
            tortoise = hare
            power *= 2
            lam = 0
        hare = ((hare << 1) ^ (hare >> 1)) & wire_mask
        lam += 1
    return lam

I know it's been over a year, but I'm wondering if using HashLife would have sped it up at all

Mathematica, 127 bytes
p@n_:=Tr[#2-#]&@@Position[#,Last@#]&@NestWhileList[1~Table~n~ArrayPad~1*18~CellularAutomaton~#&,{1}~ArrayPad~{1,n},Unequal,All]

Explanation
Rule 18:
{0,0,0} -> 0
{0,0,1} -> 1
{0,1,0} -> 0
{0,1,1} -> 0
{1,0,0} -> 1
{1,0,1} -> 0
{1,1,0} -> 0
{1,1,1} -> 0

Test cases
p/@Range[10]
(* {1,2,1,6,4,14,1,14,12,62} *)

Python 2, 68 bytes
f=lambda n,k=1,l=[]:k in l and-~l.index(k)or f(n,k/2^k*2%2**n,[k]+l)

The cycle detection could be better, but the iterative step is nice.
k -> k/2^k*2%2**n

By representing the array as a binary number k, the update can be done by taking the XOR of k shifted one left with /2 and one right with *2, then truncating to n bytes as %2**n.

Pyth, 39 36 bytes
L++Zmx@bd@bhhdQZ-lJ.uyN.[,Z1ZQ)xJyeJ

Uses the "cumulative fixed-point" function to iterate until just before a configuration recurs, and returns all intermediate configurations as a list of lists. This works because the rules are deterministic and the configuration of the next generation is a function of the current configuration. This means that once the same configuration appears again the automata have completed a cycle.
After reaching that (the last iteration of the cycle), it calls the next-gen function one last time on the last element of the "history" list, to obtain the next configuration (which is the starting configuration of a cycle), and find its index in the history. Now the period is simply the length ( 1 + index of cycle end) minus the index of cycle commencement.
In pythonic pseudocode:
                  Z = 0
                  Q = eval(input())
L                 def y(b):                # generates next-gen from current(param)
  ++Zm                return [Z] + map(    # adds head zero padding
    x@bd@bhhd             lambda d: b[d] ^ b[1+ 1+ d],  # xor the states of adjacent cells
    Q                     range(Q))        # implicit range in map
    Z                     + [Z]            # adds end zero padding
-lJ.uyN.[,Z1ZQ)   J = repeatTilRecur(lambda N,Y:y(N), padRight([Z,1],Z,Q)); print( len(J) -
                  # N:value; Y:iteration count
  JxJyeJ              J.index( y( J[-1] ) ) )

The test suite takes too much time that the server will kill it, so you'll need to use the regular program and test it one by one, or install Pyth (if you haven't) and use a script to test it.

Python 3 2, 134 121 118 bytes
Q=input()
h=[]
n=[0,1]+Q*[0]
while n not in h:h+=[n];n=[0]+[n[d]^n[d+2] for d in range(Q)]+[0]
print len(h)-h.index(n)

Basically the same as my Pyth answer, but adapted it somewhat because of lack of certain built-in functions in Python.
Ungolfed version:
length = input()
history = []
new = [0] + [1] + length*[0]
while new not in history:
    history += [new]
    new = [0] + [new[cell]^new[cell+2] for cell in range(length)] + [0]
print len(history) - history.index(new)

Jelly, 19 18 17 bytes
H^Ḥ%®
2*©Ç‘Ð¡UµiḢ

This code computes the first 2n states, so it's not particularly fast or memory efficient...
Try it online! or verify the first 16 test cases.
Alternate version, 13 bytes (non-competing)
Versions of Jelly that postdate this challenge have built-in loop detection, enabling a solution that is both shorter and more efficient.
H^Ḥ%®
2*©ÇÐḶL

This handles the last test case with ease. Try it online!
How it works
2*©Ç‘Ð¡UµiḢ    Main link. Input: n (integer)

2*             Compute 2 ** n.
  ©            Store the result in the register.
     Ð¡        Do the following:
   Ç             Apply the helper link, which updates the state, ...
    ‘            2 ** n + 1 times.
               Collect all 2 ** n + 2 intermediate results in a list.
       U       Upend; reverse the list of results.

        µ      Begin a new, monadic chain. Argument: R (list of results)
          Ḣ    Yield and remove the first element of R (final state).
         i     Find its first index in the remainder or R.
               This is the length of the loop.

H^Ḥ%®        Helper link. Argument: s (state, integer)

H            Halve s. This yields a float, but ^ will cast to integer.
  Ḥ          Double s.
 ^           Compute (s ÷ 2) ^ (s × 2).
    ®        Retrieve the value stored in the register (2 ** n).
   %         Compute ((s ÷ 2) ^ (s × 2)) % (2 ** n).

Note that the helper link is applied to 2n in the first iteration, which does not encode a valid state. However, ((2n ÷ 2) ^ (2n × 2)) % 2n = (2n - 1 + 2n + 1) % 2n = 2n - 1, which is one of the possible starting states.
Since we loop 2n + 1 times, we are guaranteed to encounter a state twice, making the loop detection successful.

CJam, 41 34 31 27 25 bytes
Thanks to Dennis for saving 3 bytes. Borrowing an idea from his Jelly answer saved another 4.
2ri#_){__4*^2/W$%}*]W%(#)

Test it here.
Explanation
I'm representing the wire simply as an integer (whose bits indicate the positions of the electrons) instead of using an actual list of bits. The state is the updated via fairly simple bitwise computations.
To find the period we collect all intermediate results on the stack, run the simulation for 2n-1+1 steps, and then determine the period as the number of elements since the last occurrence of the final state(plus 1).
Here's a breakdown of the code:
2ri#   e# Compute 2^n. This has a 1 in the n+1-th bit and zeroes below it. This is
       e# itself not a valid state but will be turned into 2^(n-1) by the first
       e# update.
_)     e# Duplicate and increment to get number of steps to simulate.
{      e# Repeat that many times...
  __   e#   Duplicate the last state twice.
  4*   e#   Multiply by 4, shifting all bits to the left by two positions.
  ^    e#   XOR - we only keep keep those cells where we have exactly one 1-bit
       e#   between both copies, i.e. those that neighboured a single electron
       e#   but shifted up by one position. We don't need handle the survival rule
       e#   explicitly, since electrons can never be adjacent in the first place.
  2/   e#   Divide by 2 shifting all bits back to the right again.
  W$   e#   Copy the initial number 2^n.
  %    e#   Modulo - this simply sets the first bit to 0.
}*
]      e# Wrap all states in an array.
W%     e# Reverse it.
(      e# Pull off the latest state.
#      e# Find its position in the remainder of the array.
)      e# Increment.

MATL, 38 37 36 35  bytes
1Oi(`t0Y)5BX+8L)1=vt6#Xut0)=fdt?w}A

This uses a loop that keeps computing new states until the new state equals any of the preceding ones. Each state is a vector of zeros and ones. These vectors are stored as rows of a growing 2D array.
Computation of each new state is done by convolving the current state with the sequence [1,0,1], keeping only the central part, and setting to 0 any entry that is not 1.
EDIT (May 13, 2016) The code in the following link has been slightly modified in accordance with changes introduced in the language after this answer was written
Try it online!
1Oi(            % create initial vector [1,0,0,...,0], with size equal to input
`               % do...while loop
  t0Y)          %   duplicate. Get last row of array: most recent vector
  5BX+8L)       %   compute new vector by convolving the most recent one
                %   with [1,0,1] and keeping only the central part
  1=            %   set ones to 1, rest to 0
  v             %   append to 2D array
  t6#Xu         %   compute vector of unique numeric labels, so that equal rows
  t0)=f         %   indices of entries whose value equals that of the last entry.
                %   This will contain the index of the last entry and possibly
                %   another index, in which case we've found a repetition
  d             %   this will either be empty (which is falsy) or contain the
                %   period, which is a nonzero number (and thus truthy)
  t?            %   duplicate. If non-empty (and nonzero)
    w           %     swap to put the 2D-array at the top of the stack. This is
                %     falsy, because it contains at least one zero, even in the
                %     n=1 case (the array is initiallized to 0 in that case)
                %     So the loop will terminate, with the period left on the stack
  }             %   else
    A           %     this transforms the empty array at the top of the stack
                %     into a true value, so that the loop will continue
                %   implicitly end if
                % implicitly end loop
                % implicitly display stack contents (period)

JavaScript (ES6) 99 104
n=>eval("a=[...Array(n)];k={};for(a[0]=i=1;!k[a=a.map((v,i)=>v?0:a[i-1]^a[i+1])];k[a]=i++);i-k[a]")

Test

f = n=>eval("a=[...Array(n)];k={};for(a[0]=i=1;!k[a=a.map((v,i)=>v?0:a[i-1]^a[i+1])];k[a]=i++);i-k[a]")

console.log = x => O.textContent += x + '\n';

;[...Array(45)].map((_, i) => console.log(++i + ' ' + f(i)))

Haskell, 170 bytes
x!p gives the element at index p if in bounds, else 0.
n calculates the next step.
g i gives the ith step.
c x gives the period, if starting with x.
f wraps it all together.
n x|l<-length x-1=[mod(x!(p-1)+x!(p+1))2|p<-[0..l],let y!q|q<0=0|q>=l=0|1<2=y!!p]
c x=[i-j|i<-[1..],j<-[0..i-1],let g k=iterate n x!!k,g i==g j]!!0
f n=c$1:map(*0)[2..n]

(Note: posted from phone that has the hugs interpreter, which is not full featured, so might have typos.)

Perl 6, 81 bytes
{my@h=my$w=2;@h.push($w=$w/2+^$w*2%2**$_)while 2>@h.grep($w);[R-] @h.grep($w,:k)}

Expanded and ungolfed a bit
-> $n {
    my @history = my $wire = 2;
    while 2 > @history.grep($wire) {
        @history.push($wire = $wire/2 +^ $wire*2 % 2**$n)
    }
    [R-] @history.grep($wire,:k)
}

A bit of explanation:

[op] reduces the list using op. For example [+] @list will sum @list
R is a meta-op that reverses the
arguments given to an op. For example 1 R- 3 will result in 2.

C++, 211 bytes
Golfed
#include <bitset>
#include <cstdio>
#define B std::bitset<1<<10>
B m,t(1),h(2);int main() {int p,l;for(scanf("%d",&p);p--;m.set(p));
for(p=l=1;t!=h;h=(h>>1^h<<1)&m,l++)p==l?t=h,p*=2,l=0:0;return !printf("%d",l);}

With added whitespace for readability
#include <bitset>
#include <cstdio>
#define B std::bitset<1<<10>
B m,t(1),h(2);
int main() {
    int p,l;
    for(scanf("%d",&p);p--;m.set(p));
    for(p=l=1;t!=h;h=(h>>1^h<<1)&m,l++)p==l?t=h,p*=2,l=0:0;
    return !printf("%d",l);
}

Good practice for C++'s bitset; and a great education learning about Brent's cycle detection algorithm (as used by @orlp)

183 bytes

Pyth, 95 bytes
J.[ZQ[1)K_1=bYW<K0=NY aN?hJZ?htJ1ZFTr1tlJ aN?@JTZ?x@JhT@JtT1Z) aN?eJZ?@J_2 1Z=JN=KxbJ abJ;-tlbK

You can try it out here.

Pyth, 29 bytes
J^2QL%x/b2*b2JK.uyN1;-lKxKyeK

Try it online!
Test suite

Uses the algorithm a(n+1) = ((a(n) << 1)^(a(n) >> 1)) % (2 ** N).

Ruby, 72 bytes
Anonymous function.
->n{s=[w=1];c=p
(j=s.index w=w*2%2**n^w/2
j ?c=s.size-j:s<<w)while !c
c}

source: Stack Exchange

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

sort: votes


text:
Residue Number System
In the vein of large number challenges I thought this one might be interesting.
In this challenge, we will be using the Residue Number System (RNS) to perform addition, subtraction, and multiplication on large integers.
What is the RNS
The RNS is one of many ways that people have developed to identify integers. In this system, numbers are represented by a sequence of residues (which are the results after a modulus operation (i.e. the remainder after integer division)). In this system, each integer has many representations. To keep things simple, we are going to limit things so that each integer is uniquely represented. I think it is easier to describe what is happening with a concrete example.
Let us look at the first three prime numbers: 2, 3, 5. In the RNS system, we can use these three numbers to uniquely represent any number that is less than 2*3*5 = 30 using residues. Take 21:
21 is less than 30, so we can represent it using the results after modding by 2, 3, and 5. (i.e. the remainder after integer dividing by 2, 3, and 5)
We would identify 21 with the following sequence of integers:
21 ~ { 21 mod 2, 21 mod 3, 21 mod 5 } = {1, 0, 1}
And so in our RNS system, instead of "21", we would use {1,0,1}.
In general given an integer n, we represent n as { n mod 2, ..., n mod p_k } where p_k is the smallest prime such that n is less than the product of all primes less than or equal to p_k.
Another example, say we have 3412. We need to use 2,3,5,7,11,13 here because 2*3*5*7*11*13=30030 whereas, 2*3*5*7*11=2310 which is too small.
3412 ~ { 3412 mod 2, 3412 mod 3, 3412, mod 5, ... , 3412 mod 13 } = { 0, 1, 2, 3, 2, 6 }
You notice that using this system we can represent very large numbers relatively painlessly. Using {1, 2, 3, 4, 5, 6, 7, 8, ... } residues, we can represent numbers up to {2, 6, 30, 210, 2310, 30030, 510510, 9699690 ...} respectively. ( Here is the series )
Our task
We will be using these residues to perform +, -, and * on large numbers. I will describe these processes below. For now here are the input and output specs.
Input
You will be given two (potentially very large) numbers via a stdin or function argument. They will be given as strings of base 10 digits.
For the purposes of outlining the problem further, we call the first input n and the second m. Assume n > m >= 0.
You will also be given + or - or * to indicate the operation to perform.
Output
Let x be an integer. We will use [x] to refer to the RNS representation described above of x.
You are to output [n] <operator> [m] = [result]
How to perform the operations in RNS
These operations are relatively simple. Given two numbers in RNS notation, to add, subtract, or multiply them, simply perform the given operations component-wise and then take the modulus.
i.e.
{ 1, 2, 3 } + { 1, 1, 4 } = { (1+1) mod 2, (2+1) mod 3, (3+4) mod 5 } = {0, 0, 2}
Note that if the number of residues used to represent two different numbers are not the same, when performing operations, you will need to extend the "shorter" number so that it has the same number of residues. This follows the same process. See the test cases for an example.
The same goes if the result requires more residues than either input. Then both inputs need to be "extended".
Important Details

We will be dealing with big numbers here, but not arbitrarily large. We will be responsible for numbers up to the product of the first 100 primes (see below). To this end, you are given the first 100 primes for free (no byte cost). You may stick them in an array called p or something idiomatic to your language and then subtract the number of bytes used to initiate this array from your final total. This of course means that they may be hard-coded or you may use a built-in to generate them.
If for someone reason this is the default integer representation used in your language. That is fine.
You may not use any Arbitrary Precision Integer type unless it is the default of your language. If it is the default, you may not use it to store integers that would not typically fit in 64 bits.
To be clear, each integer will always be represented with the fewest residues possible. This goes for both input and output.
I think the other specs should prevent this, but to be redundant: you may  not perform the given operation on the inputs and then and then change everything to RNS and then output. You must change the inputs to RNS and then perform the operations to produce the output.

Test Cases

Input:

n = 10
m = 4
+

Output:
{ 0, 1, 0 } + { 0, 1 } = { 0, 2, 4 }

Explanation:
First, change each number to its RNS representation as described above:
10 ~ {0,1,0} and 4 ~ {0,1}. Notice that when we want to do component-wise addition, that 10 has more components than 4. Therefore we must "extend" the shorter number. So we will briefly write 4 ~ {0,1} --> {0,1, 4 mod 5} = {0,1,4}. Now we proceed with addition and then take the modulus.

Input

n=28
m=18
+
Output:
 [ 0, 1, 3 ] + [0, 0, 3 ] = [ 0, 1, 1, 4 ]

Input (me mashing my face on the keyboard)

n=1231725471982371298419823012819231982571923
m=1288488183
*
Output (broken onto separate lines for readability):
[1, 2, 3, 6, 2, 10, 2, 1, 12, 16, 7, 15, 34, 29, 31, 5, 55, 32, 66, 61, 3, 76, 52, 14, 65, 44, 99, 57 ]
*
[1, 0, 3, 3, 4, 8, 9, 10, 8, 0 ]
=
[1, 0, 4, 4, 8, 2, 1, 10, 4, 0, 17, 7, 27, 21, 44, 51, 56, 9, 6, 9, 12, 0, 52, 36, 43, 68, 99, 24, 96, 39, 96, 66, 125]

n requires 28 primes. m requires 10. n*m requires 33.

Input

n=8709668761379269784034173446876636639594408083936553641753483991897255703964943107588335040121154680170867105541177741204814011615930342030904704147856733048115934632145172739949220591246493529224396454328521288726490
m=1699412683745170450115957274739962577420086093042490863793456500767137147999161679589295549397604032154933975242548831536518655879433595016
-
Output:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 509]
-
[0, 2, 1, 6, 1, 12, 11, 18, 14, 28, 21, 36, 37, 42, 16, 52, 41, 60, 16, 70, 49, 78, 80, 88, 49, 100, 13, 106, 4, 112, 68, 130, 36, 138, 37, 150, 0, 162, 8, 172, 163, 180, 18, 192, 129, 198, 135, 222, 78, 228, 90, 238, 57, 250, 36, 262, 87, 270, 206, 280, 193, 292, 253, 310, 224, 316, 57, 336, 48, 348]
=
[0, 1, 4, 1, 10, 1, 6, 1, 9, 1, 10, 1, 4, 1, 31, 1, 18, 1, 51, 1, 24, 1, 3, 1, 48, 1, 90, 1, 105, 1, 59, 1, 101, 1, 112, 1, 0, 1, 159, 1, 16, 1, 173, 1, 68, 1, 76, 1, 149, 1, 143, 1, 184, 1, 221, 1, 182, 1, 71, 1, 90, 1, 54, 1, 89, 1, 274, 1, 299, 1, 266, 1, 228, 1, 340, 1, 170, 1, 107, 1, 340, 1, 88, 1, 157, 1, 143, 1, 22, 1, 22, 1, 58, 1, 296, 1, 371, 1, 140]
n uses 100 primes. m uses 70 primes. n-m uses 99 primes.
I checked these using the ChineseRem built-in implementation of the Chinese Remainder theorem on GAP (which basically takes RNS numbers and changes them to base 10 integers). I believe they are correct. If something seems fishy, please let me know.

For those who care, the product of the first 100 primes is:
471193079990618495316248783476026042202057477340967552018863483961641533584503
422120528925670554468197243910409777715799180438028421831503871944494399049257
9030720635990538452312528339864352999310398481791730017201031090
This number is 1 larger than the maximal number we can represent using the given system (and 100 prime limitation).
Somewhat related

I think that performing the operation is far from being the hardest part, for which I feel strange about this challenge.

@njpipeorgan I agree, performing the operation is simply (a,b,o)=>a.map((v,i)=>eval(v+o+b[i])) in ES6 for instance. I think the hardest part is probably finding the number of primes needed to represent the result without using arbitrary precision arithmetic, although the subsequent conversion to RNS isn't exactly trivial.

Can I have the input like this (1234,1234,+)?

@derpfacePython yes functions are acceptable as well

"simply perform the given operations component-wise" - then where do extra components in the output come from?

@smls if you have too few components, additional components must be computed by calculating additional residues. Then perform operations component wise

but if you have one input near a product of 100 primes, i think it is not possible to fit in a 64 bit number so one has to use some big num function for divide that number with primes...

@roslup see my answer please

I looked at the description of operations in RNS, and I did not understand the rules of transferring between positions (residues) - it seems that there is no transfer at all, but how to get the value 4 in the result of example [ 0, 1, 3 ] + [0, 0, 3 ] = [ 0, 1, 1, 4 ]?

@voland the inputs must be extended by a residue before the operation is performed. You add 28 (mod 7) + 18 (mod 7) and then take

@Liam I got: 28 and 18 (i.e. initial decimal values) should be used for operations. In that case I think all operations should be done not with RNS representation, but like: 1) take op, N and M in decimal; 2) calculate R as R = N op M; 3) build result string as toRSN(N) + " + " + toRSN(M) + " = " toRSN(R) :-)

GAP
Some Background: I will admit that when I created this question, so many months ago, I did not have a method for solving the hard part of this question: determining the correct number of primes to use. We have a lot of very intelligent people on this site, and I really expected that someone would figure out a way to do it fairly quickly. However, as this did not happen, I wasn't even sure that it was truly possible to solve this problem. So, I had to take the time to devise a method. I believe that what I have done does not break any of the rules in this challenge, of course I would love this to be fact checked.
I also slightly regret the choice of code-golf because the solutions are slightly more in depth than would usually fit the tag format. Having said this, to follow site rules, there is a "golfed" version of my solution at the bottom of this post.

Code
### The first 100 primes;
primes := Primes{[1..100]};

### In many of the functions below, the 'string' variable is a string of digits
###

### Returns the 'index' digit of 'string' as an integer
GetValueAsInt := function(string, index)
    return IntChar(string[index]) - 48;
end;

### Used in the 'modulus' function. See that comment for more information.
### Calculates the contribution to the modulus of a digit 'digit' in the 10^power place.
### 'integer' is the modulus
digit_contribution := function(digit, integer, power)
    local result, i;
    result := 1;
    for i in [0..power-1] do
        result := ( result * (10 mod integer) ) mod integer;
    od;
    result := (result * (digit mod integer) ) mod integer;
    return result;
end;

### This modulus function is used to calculate the modulus of large numbers without storing them
##### as large numbers.
### It does so by breaking them into digits, and calculating the contribution of each digit.
### e.g. 1234 mod 5 = (1000 mod 5)(1 mod 5) + (200 mod 5)(2 mod 5) + (10 mod 5)(3 mod 5) + (4 mod 5)
### It actually mods after every calculation to ensure that we never get a number larger
##### than the modulus ('integer') squared, which will never be even close to 10^64-1
modulus := function(string, integer)
    local i, result, digit, len;
    len := Length(string);
    result := 0;
    for i in [1..len] do
        digit :=  IntChar(string[i]) -48;
        result := ( result + digit_contribution(digit, integer, len-i) )  mod integer;
    od;
    return result;
end;

### This returns the product of the first i-1 primes (mod j). It must not (and does not)
##### ever store an integer larger than 2^64-1
phi_i := function(i,j)
    local index, result;
    result := 1;
    for index in [1..i-1] do
        result := ( result * primes[index] ) mod primes[j];
    od;
    return result;
end;

### Calculates the first residues of 'string' mod the first 100 primes
get_residues := function(string)
    local p, result;
    result := [];
    for p in primes do
        Add( result, modulus(string, p) );
    od;
    return result;
end;

### Gets the ith element in the partial_chinese array, given the previous elements
### See the explanation section and partial_chinese function for more info
get_partial_i := function( i, residues, previous_array )
    local index, result;
    result := residues[i];
    for index in [1..Length(previous_array)] do
        result := ( result - previous_array[index]*phi_i(index,i) ) mod primes[i];
    od;
    result := ( result / phi_i(i,i) ) mod primes[i];
    return result;
end;

### returns an array such that the sum of prod_primes(i)*array[i] is equal to the integer value
##### that is represented by the residues. (It basically just does the CRT without
##### actually summing everything.) prod_primes(i) is the product of the first i-1 primes
### See the explanation for a bit more info
### This is what allows us to determine the minimal number of primes to represent a RNS number
partial_chinese := function( string )
    local array, i, residues;
    residues := get_residues(string);
    array := [];
    for i in [1 .. Length(primes)] do
        Add( array, get_partial_i( i, residues, array ) );
    od;
    return array;
end;

### Same as partial_chinese but takes input in a different form.
partial_chinese_from_residues := function(residues)
    local array, i;
    array := [];
    for i in [1 .. Length(primes)] do
        Add( array, get_partial_i( i, residues, array ) );
    od;
    return array;
end;

### gives you the number of primes needed to represent an integer. Basically asks how
##### many trailing zeros there are in the chinese array.
get_size := function(string)
    local array, i, len, result;
    array := partial_chinese(string);
    len := Length(array);
    for i in [0..len-1] do
        if  not (array[len-i] = 0) then
            return len -i;
        fi;
    od;
    Print("ERROR: get_size().\n");
    return 0;
end;

### Same as above but with different input format
get_size_from_residues := function(residues)
    local array, i, len, result;
    array := partial_chinese_from_residues(residues);
    len := Length(array);
    for i in [0..len-1] do
        if  not (array[len-i] = 0) then
            return len -i;
        fi;
    od;
    Print("ERROR: get_size().\n");
    return 0;
end;

### the actual function. inputs are all strings
f := function(in1, in2, opperation)
    local residues_1, residues_2, residues_result, i;
    residues_1 := get_residues(in1);
    residues_2 := get_residues(in2);
    residues_result := [];
    if opperation = "+" then
        for i in [1..Length(primes)] do
            Add( residues_result, ( residues_1[i] + residues_2[i] ) mod primes[i]);
        od;
    elif opperation = "*" then
        for i in [1..Length(primes)] do
            Add( residues_result, ( residues_1[i] * residues_2[i] ) mod primes[i]);
        od;
    elif opperation = "-" then
        for i in [1..Length(primes)] do
            Add( residues_result, ( residues_1[i] - residues_2[i] ) mod primes[i]);
        od;
    fi;
    Print(residues_1{[1..get_size(in1)]}, " ", opperation, " ", residues_2{[1..get_size(in2)]}, " = ", residues_result{[1..get_size_from_residues(residues_result)]} );
end;

Explanation:
To start off, we calculate all the 100 of the residues for both inputs. We do this with the modulus function in the code. I tried to be careful so that we use the built-in mod function after every step. This ensures that we never have a number that is larger than 540^2, which is 1 less than the 100th prime squared.
After we have all the residues, we can perform the given operation and mod each entry again. Now we have a unique designator for the result, but we need to determine the minimal number of entries that we have to use to represent the result and each of the inputs.
Figuring out how many residues we actually need is by far the hardest part of this problem. To determine this, we perform most of the steps of the Chinese Remainder Theorem (CRT). However, we obviously have to make modifications so that we don't end up with numbers that are too large.
Let prod(i) be the sum of the first i-1 primes. For example,
prod(1) = 1
prod(2) = 2
prod(3) = 6
prod(4) = 30
etc

Let X be an integer. Let {r_i} be the residues of X, that is
r_i = X mod p_i

Where p_i is the ith prime. This is for 1<i<=100 in our case.
Now we are going to use the CRT to find a sequence {u_i} such that the sum over i of prod(i) * u_i is equal to X. Note that each u_i is also technically a residue, as u_i < p_i. Furthermore, if X < prod(i) then u_i = 0. This is of critical importance. It means that by examining trailing zeros, we can determine how many of the residues r_i we actually need to represent X in the RNS.
If you care to examine some sequences of u_i, the partial_chinese function returns the u_i sequence.
By messing around with the CRT, I was able to find a recursive formula for the u_i values, solving the issue of determining how many residues we need.
The formula is:
u_i = [ r_i - SUM ] / prod(i)       (mod p_i)

Where SUM is the sum over j in [1,i) of u_j * prod(i).
Of course, prod(i) cannot actually be calculated in some cases because it is too large. For this purpose, I used the phi_i function. This function returns prod(j) (mod p_i). It mods at every step, so we never actually calculate anything that is too large.
If you are curious where this formula comes from, I would recommend working a couple of CRT examples, which can be found on the wikipedia page.
Finally, for each input as well as our output, we calculate the u_i sequence and then determine the trailing zeros. Then we throw out that many r_i from the end of the residue sequences.

"Golfed" Code, 2621 bytes
primes:=Primes{[1..100]};GetValueAsInt:=function(string,index)return IntChar(string[index])-48;end;digit_contribution := function(digit, integer, power)local result, i;result:=1;for i in [0..power-1] do result := ( result * (10 mod integer) ) mod integer;od;result:=(result*(digit mod integer) ) mod integer;return result;end;modulus:=function(string, integer)local i,result,digit,len;len:=Length(string);result:=0;for i in [1..len] do digit:= IntChar(string[i])-48;result:=(result+digit_contribution(digit,integer,len-i)) mod integer;od;return result;end;phi_i:=function(i,j)local index,result;result:=1;for index in [1..i-1] do result:=(result*primes[index] ) mod primes[j];od;return result;end;get_residues:=function(string) local p,result;result:=[];for p in primes do Add(result,modulus(string,p));od;return result;end;get_partial_i:=function(i,residues,previous_array)local index,result;result:=residues[i];for index in [1..Length(previous_array)] do result:=(result-previous_array[index]*phi_i(index,i) ) mod primes[i];od;result:=(result/phi_i(i,i)) mod primes[i];return result;end;partial_chinese:=function(string)local array,i,residues;residues:=get_residues(string);array:=[];for i in [1 .. Length(primes)] do Add(array,get_partial_i(i,residues,array));od;return array;end;partial_chinese_from_residues:=function(residues)local array,i;array:=[];for i in [1..Length(primes)] do Add(array,get_partial_i(i,residues,array));od;return array;end;get_size:=function(string)local array,i,len,result;array:=partial_chinese(string);len:=Length(array);for i in [0..len-1] do if not (array[len-i] = 0) then return len-i;fi;od;Print("ERROR: get_size().\n");return 0;end;get_size_from_residues:=function(residues)local array,i,len,result;array:=partial_chinese_from_residues(residues);len:=Length(array);for i in [0..len-1] do if not (array[len-i]=0) then return len-i;fi;od;Print("ERROR: get_size().\n");return 0;end;f:=function(in1,in2,opperation)local residues_1,residues_2,residues_result,i;residues_1:=get_residues(in1);residues_2:=get_residues(in2);residues_result:=[];if opperation = "+" then for i in [1..Length(primes)] do Add(residues_result,(residues_1[i]+residues_2[i] ) mod primes[i]);od;elif opperation = "*" then for i in [1..Length(primes)] do Add(residues_result,(residues_1[i]*residues_2[i])mod primes[i]);od;elif opperation = "-" then for i in [1..Length(primes)] do Add(residues_result,(residues_1[i]-residues_2[i]) mod primes[i]);od;fi;Print(residues_1{[1..get_size(in1)]}, " ", opperation, " ", residues_2{[1..get_size(in2)]}, " = ", residues_result{[1..get_size_from_residues(residues_result)]} );end;

I'm confused because regular RNS doesn't change dimensions as needed, but don't you bend the rules by computing the extended 100 residue number from input, rather than only the dimensions needed and then performing operations? "First, change each number to its RNS representation as described above" to me means the 'RNS' number should have only the residues needed before anything gets done.

Sorry @Linus,  I thought I responded to this already.  I agree with you, but I think the change required (which I will make) is relatively trivial. As I see it,  all I need to do is calculate the residue lengths of the inputs before performing the operation. Using all 100 primes for all three numbers merely leverages the fact that all numbers are bounded above

@Linus and in answer to your first question,  normally all numbers would use the same number of residues. That would make the question a lot simpler

Mathematica, not golfed
rns[d_,l_]:=Table[Reap[
    FoldPairList[Sow@QuotientRemainder[10#+#2,Prime@i]&,0,d]
  ][[2,1,-1,2]],{i,l}];
plus[a_,b_]:=Mod[a+b,Prime@Range@Length@a];
subtract[a_,b_]:=Mod[a-b,Prime@Range@Length@a];
times[a_,b_]:=Mod[a b,Prime@Range@Length@a];
mag[f_]:=LengthWhile[FoldList[#/#2&,f,Prime@Range@100],#>1.1&];
ext[m_,n_,i_]:=Fold[Mod[1##,Prime@i]&,m,Prime@Range@n];
multi[e_,p_,t_]:=Tr@Position[Mod[e Range@p,p],p-t];
appx[d_] := N@FromDigits[{d~Take~UpTo[6], Length@d}]

Function rns[d_,l_] converts a base-10 integer d into a RNS integer of length l.
Function plus / times / subtract add / multiply / subtract one RNS integer to / from another, both of which are of the same length.
Function mag[f_] estimates the approximate magnitude of the floating point number f in terms of the lower bound of the length of its RNS representation.
Function ext[m_,n_,i_] finds out the remainder from division of the product of m and Prime[Range@n] by Prime[i].
Function multi[e_,p_,t_] gives the smallest multiplier m satisfying that Divisible[m*e+t,p]
Function appx[d_] take the first 6 digits of a decimal integer and gives its approximate floating point value.

With the help of functions above, now we are able to solve a tricky problem - to determine the length of the result.
First, I have to clarify that it is not an easy task to determine the RNS length of an integer. For small integers, we can compare them directly with the product of primes. But for very large integers, since it is forbidden to calculate the product of primes infinitely accurate, such comparison no longer works.
For example, given that the product of prime 1 to 30 is 3.16*10^46, the RNS length of integers around 3.16*10^46 can possibly be 29 or 30. The function mag will give 29 as a reference for these integers, showing that both 29 and 30 are possible.
Once knowing the magnitude, we simply represent the integer according to that magnitude directly, hoping to calculate its true length. The trick here is to add some new numbers to the original number and modify its RNS representation, until the representation is all zero.
For example, mag[211.] is 4, and its length 4 representation is {1, 1, 1, 1}.
step 1:   {1,1,1,1} -> {0,2,2,2}  by adding  (1) * 1 = 1
step 2:   {0,2,2,2} -> {0,0,1,6}  by adding  (2) * 2 = 4
step 3:   {0,0,1,6} -> {0,0,0,2}  by adding  (2*3) * 4 = 24
step 4:   {0,0,0,2} -> {0,0,0,0}  by adding  (2*3*5) * 6 = 180
step 5:   calculate 211 + (1 + 4 + 24 + 180) ~ 420

By adding some number, we increase 211 to the smallest number that is divisible by 210 (2*3*5*7). And now we conclude that the original number is greater than 210, since 420 equals "approximately" two times of 210. It is not difficult to imagine that if we start from 209, the final number is "approximately" 210.
Function length[f_,n_] takes the floating point value f to estimate the magnitude, and correct it base on its RNS representation n.
length[f_,n_]:=With[{g=mag@f},
    g+If[#==0,1,Round[(#+f)/Times@@Prime@Range@g]-1]&[
      FoldList[Times,1.,Prime[Range[g-1]]].
      FoldPairList[
        Block[{i=#2,m},
          {m=multi[ext[1,i-1,i],Prime@i,Part@##],rnsPlus[#,ext[m,i-1,#]&/@Range[g]]}
        ]&,n,Range[g]]]]

Function rnsOperation[a_,b_,op_,rnsop_] gives rnsop[a,b] and op is corresponding normal operations used to get approximate results based on floating point values.
rnsOperation[a_,b_,op_,rnsop_]:=Block[{c=op[appx@a,appx@b],m},
    m=mag[c];m=length[c,rnsop[rns[a,m],rns[b,m]]];rnsop[rns[a,m],rns[b,m]]]

Example
rnsOperation[
    IntegerDigits@1231725471982371298419823012819231982571923,
    IntegerDigits@1288488183,
    Times, times]
(* {1,0,4,4,8,2,1,10,4,0,17,7,27,21,44,51,56,9,6,9,12,0,52,36,43,68,99,24,96,39,96,66,125} *)

Unfortunately, the rules outlined in our help center require all submissions to be a serious contender for the winning criteria in use. For a code golf contest, this means all submissions must be golfed.

@Dennis I know about this rule. However, even without golfing, I think this problem is difficult and complex enough, so that solving this problem rather than golfing is my objective.

this maybe isn't golfed but damn short compared to my java programm :P, though my programm is probably a lot faster.

I feel like you are capable of golfing this

Python 3, 435 bytes
This challenge has been on my bucket list for a while, but it's only recently that: a) I put time and attention into actually attempting an answer; and b) actually tested my idea to calculate the size of the numbers (and so the number of primes by comparing it to the size of the primorials) using some unholy combination of logarithms and the Chinese Remainder Theorem. Unfortunately, working with logarithms while trying to determine the number of primes that, for example, large_primorial + 3 requires, meant that I was having to find ways to work around floating-point problems.
And so, this is a port of Liam's answer.
Try it online!
from functools import reduce as R
G=range
d=lambda s:[R(lambda z,c:(z*10+int(c))%q,s,0)for q in p]
h=lambda j,i:R(lambda z,q:z*q%p[i],p[:j],1)
def s(r):
 a=[];z=99
 for i in G(100):
  P=p[i];u=r[i]
  for j in G(len(a)):u=(u-a[j]*h(j,i))%P
  for k in G(1,P):
   if h(i,i)*k%P<2:break
  a+=u*k%P,
 while(a[z]<1)*z:z-=1
 return r[:z+1]
def f(a,b,n):u=d(a);v=d(b);print(s(u),n,s(v),'=',s([eval(str(u[i])+n+str(v[i]))%p[i]for i in G(100)]))

Explanation
While trying to port Liam's answer, I personally found some of the explanation given was confusingly worded, so this is my attempt at explaining his algorithm.
First, we get the residues of n and m.
res1 = get_residues(n)
res2 = get_residues(m)

This involves turning all the digits of the input strings and turning them into numbers modulo each of our primes, e.g. for 28, we would have [(20 + 8) mod 2, (20 + 8) mod 3, (20 + 8) mod 5, etc]
def get_residues(string):
    result = []
    for p in primes:
        result.append(reduce(lambda z, c:(z*10+int(c)) % p, string, 0))

Then we add, multiply, or subtract the residues pairwise using eval()
result = []
for i in range(len(primes)):
    result.append((eval(str(res1[i]) + op + str(res2[i])) % primes[i])

Then we get the sizes of our residues, i.e. the minimum number of primes we need.
size1 = get_size(res1)
size2 = get_size(res2)
size3 = get_size(result)

Getting the sizes is the trickiest and most code-intensive part. We use the partial_chinese function, which gets us our sequence of u_i to determine the size with. More on u_i in a moment.
def get_size(residues):
    array = partial_chinese(residues)
    size = len(residues)-1
    while array[size] == 0 and size:
        size -= 1
    return size+1  # to prevent off-by-one errors from 0-indexing

The sequence u_i is calculated by taking each residue r_i, subtracting the sum u_j * primorial(j) for j in [1, i), and then dividing by primorial(i), all modulo primes[i]. That is, u_i = (r_i - SUM) / primorial(i). More on our primorial and division functions in a moment.
def partial_chinese(residues):
    array = []
    for i in range(len(primes)):
        array.append(get_partial_i(i, residues, array))
    return array

def get_partial_i(i, residues, previous_array):
    result = residues[i]
    for j in range(len(previous_array)):
        result = (result - previous_array[j] * phi_i(j, i)) % primes[i]
    result = result * inverse(phi_i(i, i), primes[i]) % primes[i]
    return result

phi_i(j, i) calculates primorial(j) mod primes[i]. Division modulo any prime p is easily implemented by checking for multiplicative inverses manually, as we can be sure that any possible u_i is 0 <= u_i < p is guaranteed to be coprime to p and so is guaranteed a multiplicative inverse.
def phi_i(j, i):
    return reduce(lambda z, q: z * q % primes[i], primes[:j], 1)

def inverse(n, p):
    for i in range(1, p):
        if n * i % p == 1:
            return i

With all that done, we print our string and we're done.
print(res1[:size1], op, res2[:size2], "=", result[:size3])

What's next
This was fun to implement. I still want to see if I can use logarithms in some way in another answer. And I'd like to implement this code or something like in a functional golfing language, like APL or Jelly. Any and all golfing suggestions and corrections are welcome!

all_licenses: 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/


text:
Where does the spaceship go?
Based on an idea suggested by Zgarb.
A spaceship is moving around a regular 3D grid. The cells of the grid are indexed with integers in a right-handed coordinate system, xyz. The spaceship starts at the origin, pointing along the positive x axis, with the positive z axis pointing upwards.
The spaceship will fly along a trajectory defined by a non-empty sequence of movements. Each movement is either F(orward) which makes the spaceship move one cell in the direction its facing, or one of the six rotations UDLRlr. These corresponds to pitch, yaw and roll as follows:

Thanks to Zgarb for creating the diagram.

Up and Down change the pitch of the spaceship by 90 degrees (where the direction corresponds to the movement of the spaceship's nose).
Left and Right change the yaw of the spaceship by 90 degrees. They are just regular left and right turns.
left and right are 90 degree rolling movements, where the direction indicates which wing moves downwards.

Note that these should always be interpreted relative to the spaceship so the relevant axes rotate along with it.
In mathematical terms, the spaceship is initially at position (0, 0, 0), pointing along the (1, 0, 0) vector, with (0, 0, 1) pointing upwards. The rotations correspond to the following matrices applied to the coordinate system:
U = ( 0  0 -1     D = ( 0  0  1
      0  1  0           0  1  0
      1  0  0 )        -1  0  0 )

L = ( 0 -1  0     R = ( 0  1  0
      1  0  0          -1  0  0
      0  0  1 )         0  0  1 )

l = ( 1  0  0     r = ( 1  0  0
      0  0  1           0  0 -1
      0 -1  0 )         0  1  0 )

You should output the final position of the spaceship as three integers x, y, z. Output may be three separate integers or a list or string containing them. They may be in any consistent order as long as you specify it.
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.
Standard code-golf rules apply.
Test Cases
F                                                   => (1, 0, 0)
FDDF                                                => (0, 0, 0)
FDDDF                                               => (1, 0, 1)
LrDDlURRrr                                          => (0, 0, 0)
UFLrRFLRLR                                          => (1, 0, 1)
FFrlFULULF                                          => (3, 0, -1)
LLFRLFDFFD                                          => (-2, 0, -2)
FrrLFLFrDLRFrLLFrFrRRFFFLRlFFLFFRFFLFlFFFlUFDFDrFF  => (1, 5, 7)
FUrRLDDlUDDlFlFFFDFrDrLrlUUrFlFFllRLlLlFFLrUFlRlFF  => (8, 2, 2)
FFLrlFLRFFFRFrFFFRFFRrFFFDDLFFURlrRFFFlrRFFlDlFFFU  => (1, 2, -2)
FLULFLFDURDUFFFLUlFlUFLFRrlDRFFFLFUFrFllFULUFFDRFF  => (-3, -2, -3)

Worked example
Here are the intermediate steps of the UFLrRFLRLR test case. Here, all intermediate coordinates and direction vectors are given in the initial, global coordinate system (as opposed to one local to the spaceship):
Cmd.  Position    Forward     Up
      ( 0, 0, 0)  ( 1, 0, 0)  ( 0, 0, 1)
U     ( 0, 0, 0)  ( 0, 0, 1)  (-1, 0, 0)
F     ( 0, 0, 1)  ( 0, 0, 1)  (-1, 0, 0)
L     ( 0, 0, 1)  ( 0, 1, 0)  (-1, 0, 0)
r     ( 0, 0, 1)  ( 0, 1, 0)  ( 0, 0, 1)
R     ( 0, 0, 1)  ( 1, 0, 0)  ( 0, 0, 1)
F     ( 1, 0, 1)  ( 1, 0, 0)  ( 0, 0, 1)
L     ( 1, 0, 1)  ( 0, 1, 0)  ( 0, 0, 1)
R     ( 1, 0, 1)  ( 1, 0, 0)  ( 0, 0, 1)
L     ( 1, 0, 1)  ( 0, 1, 0)  ( 0, 0, 1)
R     ( 1, 0, 1)  ( 1, 0, 0)  ( 0, 0, 1)

This challenge is a 3D generalization of this one, minus the intersection part.

Why does 2 != 2, 3 != -1, 4 != 0 != -4, 1 != -3

@username.ak I don't think I understand the question. What are you referring to?

@Martin Büttner, I say why 180 degrees rotation is not the same as -180, 270 is not the same as -90 etc

@username.ak is it not?

It goes to Area 51

MATL, 76 75 bytes
FFF!3Xyj"FFT_FTFv4BvtFT_YStTF_YS3:"3$y!]6$Xh@'ULlDRr'4#mt?X)Y*}xxt1Z)b+w]]x

This works in current version (12.1.1) of the language.
Edit (April 4, 2016): The behaviour of function v has changed in release 15.0.0 of the language. To make the above code run, remove the first v and replace the second 3$v. The following link includes this modification.
Try it online!
Explanation
The state of the ship can be described in terms of two variables:

position: 3x1 vector
orientation: 3x3 matrix with the accumulated rotation, where "accumulated" means repeated matrix product.

A third variable would be the direction in which the ship is facing, but that's not needed, because it can be obtained as the initial direction (column vector [1;0;0]) times the current orientation; that is, the first column of the orientation.
These two state variables are kept on the stack, and are updated with each letter. Each of the letters ULlDRr multiplies the orientation matrix by one of the six rotation matrices to update the orientation. Letter F adds the current position plus the first column of the orientation matrix.
The six rotation matrices are created as follows: first is introduced directly; second and third are circular shifts of the previous one; and the remaining three are transposed versions of the others.
FFF!             % 3x1 vector [0;0;0]: initial position
3Xy              % 3x3 identity matrix: initial orientation
j                % input string
"                % for-each character in that string
  FFT_FTFv4Bv    %   rotation matrix for U: defined directly
  tFT_YS         %   rotation matrix for L: U circularly shifted to the left
  tTF_YS         %   rotation matrix for l: L circularly shifted down
  3:"            %   repeat three times
    3$y!         %     copy third matrix from top and transpose
  ]              %   end loop. This creates rotation matrices for D, R, r
  6$Xh           %   pack the 6 matrices in a cell array
  @              %   push current character from the input string
  'ULlDRr'4#m    %   this gives an index 0 for F, 1 for U, 2 for L, ..., 6 for r
  t?             %   if non-zero: update orientation
    X)           %     pick corresponding rotation matrix
    Y*           %     matrix product
  }              %   else: update position
    xx           %     delete twice (index and rotation matrix are not used here)
    t1Z)         %     duplicate orientation matrix and take its first column
    b+           %     move position vector to top and add
    w            %     swap the two top-most elements in stack
  ]              %   end if
]                % end for-each
x                % delete orientation matrix
                 % implicitly display position vector

Octave, 175 bytes
function p=s(i)m.U=[0,0,-1;0,1,0;1,0,0];m.D=m.U';m.L=[0,-1,0;1,0,0;0,0,1];m.R=m.L';m.l=flip(flip(m.L),2);m.r=m.l';a=m.F=eye(3);p=[0;0;0];for c=i p+=(a*=m.(c))*[c=='F';0;0];end

Readable version:
function p=s(i)
  m.U=[0,0,-1;0,1,0;1,0,0];
  m.D=m.U';
  m.L=[0,-1,0;1,0,0;0,0,1];
  m.R=m.L';
  m.l=flip(flip(m.L),2);
  m.r=m.l';
  a=m.F=eye(3);
  p=[0;0;0];
  for c=i p+=(a*=m.(c))*[c=='F';0;0];
end

Nice use of dynamic field names!

"Readable version [citation needed]" ;)

ES6, 265 259 bytes
s=>[...s.replace(/F/g,"f$`s")].reverse().map(e=>d={U:(x,y,z)=>[-z,y,x],D:(x,y,z)=>[z,y,-x],L:(x,y,z)=>[-y,x,z],R:(x,y,z)=>[y,-x,z],r:(x,y,z)=>[x,-z,y],l:(x,y,z)=>[x,z,-y],F:(...d)=>d,f:(x,y,z)=>[a+=x,b+=y,c+=z]),s:_=>[1,0,0]}[e](...d),d=[1,0,a=b=c=0])&&[a,b,c]

Explanation: Normally to calculate the direction of the spaceship you would compose all the rotations together, and then for each move you would compose the result to the unit vector F = (1, 0, 0) (or more simply extract the first column of the matrix). For instance, FFrlFULULF => F + F + r⋅l⋅F + r⋅l⋅U⋅L⋅L⋅L⋅F. Since matrix multiplication is associative, languages with built-in matrix multiplication can obviously compute the partial product r⋅l⋅U⋅L⋅L⋅L as they go along, multiplying by F as necessary to produce the terms that are then added together. Unfortunately I don't have that luxury, so the cheapest option is to compute each term in the above expression separately, starting with F and working back. For that, I need a list for each of the occurrences of F of all the rotations up to that point. I do this using replace with $` so I also need to mark the start and end of each term in the list so that I can ignore the rest of the string. Slightly ungolfed:
s=>[... // split the string into separate operations
    s.replace(/F/g,"f$`s")] // For each 'F', wrap the operations up to that point
  .reverse() // Play all the operations in reverse order
  .map(e=>d= // Update the direction for each operation
    { // set of operations
      U:(x,y,z)=>[-z,y,x], // Up
      D:(x,y,z)=>[z,y,-x], // Down
      L:(x,y,z)=>[-y,x,z], // Left turn
      R:(x,y,z)=>[y,-x,z], // Right turn
      r:(x,y,z)=>[x,-z,y], // right roll
      l:(x,y,z)=>[x,z,-y], // left roll
      F:(...d)=>d, // does nothing, `s` and `f` do the work now
      f:(x,y,z)=>[a+=x,b+=y,c+=z], // do the move
      s:_=>[1,0,0] // back to start
    }[e](...d), // apply the operation to the current direction
    d=[1,0,a=b=c=0] // initialise variables
  )&&[a,b,c] // return result

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


text:
Maximise the squared difference
Consider a permutation of the integer values from 1 to N. E.g. this example for N = 4:
[1, 3, 4, 2]

We'll consider this list to be cyclic, such that 1 and 2 are treated as adjacent. One quantity we can compute for such a list is the total squared difference of adjacent values:
(1-3)² + (3-4)² + (4-2)² + (2-1)² = 10

Your task is to find a permutation which maximises this quantity, given a positive integer N. In the case of N = 4 the above example is not optimal (in fact, it's minimal). We can achieve a total squared difference of 18 with the following permutation (as well as several others):
[1, 4, 2, 3]

Your algorithm must run in polynomial time (of N). In particular, you cannot simply compute the total squared difference of all permutations.
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.
Output may be in any convenient, unambiguous, flat list or string format. You may choose to return a list with values from 0 to N-1 instead of 1 to N.
Standard code-golf rules apply.
Test Data
There is a nice analytical solution for this problem. E.g. all valid solutions for N = 10 are equivalent to the following list (up to cyclic shifts and reversal):
[7, 5, 6, 4, 8, 2, 10, 1, 9, 3]

I don't want to reveal too much beyond that (although it's probably enough to figure out the pattern), so instead of giving any more examples, you can check that your results have the following total squared differences for a given N:
N    Total squared difference

1                         0
2                         2
3                         6
4                        18
5                        36
6                        66
7                       106
8                       162
9                       232
10                      322
33                    11936
100                  333202
333                12308236
1000              333332002

This is OEIS entry A064842 (which also contains a reference to a paper with a solution to this challenge if you're stuck).

Jelly, 24 21 15 14 10 9 bytes
RUĖµ«/€ị"

To compute the total squared difference, append µ_ṙ1$²S to the code. Try it online!
Background
One way to generate a permutation with maximized squared difference is to take the integers 1 to n in ascending order, and swap the second from the left with the second from the right, the fourth from the left with the fourth from the right, and so forth until we meet in the middle.
For example, for n = 8, 9 we have
1 2 3 4 5 6 7 8        1 2 3 4 5 6 7 8 9
  ^   ^ ^   ^            ^   ^   ^   ^

(carets mark integers to be swapped), which results in
1 7 3 5 4 6 2 8        1 8 3 6 5 4 7 2 9

after swapping.
One way to achieve these swaps, independently of the parity of n, is as follows.
Start by writing the integers in ascending order and in descending order, one below the other.
1 2 3 4 5 6 7 8        1 2 3 4 5 6 7 8 9
8 7 6 5 4 3 2 1        9 8 7 6 5 4 3 2 1

For each pair of integers, compute the minimum of the pair. This gives the distance to the nearest edge, i.e., the index from the left or the right (whichever is lower).
1 2 3 4 5 6 7 8        1 2 3 4 5 6 7 8 9
8 7 6 5 4 3 2 1        9 8 7 6 5 4 3 2 1

1 2 3 4 4 3 2 1        1 2 3 4 5 4 3 2 1

If the minimum is odd, the integer should stay in its place, so we select the one from the first row; if it is even, the integers should be swapped, so we select the one from the second row.
1   3     6   8        1   3   5   7   9
  7   5 4   2            8   6   4   2

This is the desired output.
How it works
RUĖµ«/€ị"    Main link. Input: n

R            Range. Yields [1, ..., n].
 U           Upend. Yields [n, ..., 1].
  Ė          Enumerate. Yields p := [[1, n], [2, n-1], ... [n-1, 2], [n, 1]].

   µ         Begin a new, monadic chain. Argument: p
     /       Reduce...
      €        each pair of p...
    «          by minimum.
        "    For each minimum and the corresponding pair of p:
       ị       Select the element at that index.
            Indices are modular and 1-based in Jelly, so this selects the first
            element if the minimum is odd, and the second one if it is even.

JavaScript (ES6), 52 bytes
n=>[...Array(n)].map((_,i)=>(i<n/2|n%2)^i%2?i+1:n-i)

9 bytes saved thanks to @Neil!
Explanation
This approach determines the number that should be at index i with a length of n rather than concatenating the results to an array. This is based on the following observation (using n = 7 as an example):

Start with the lowest number on the left and the highest on the right: [ 1, 7 ]
Switch the order so the lowest is on the right and the highest is on the left, increment the lowest, decrement the highest, and place them in the middle of the array: [ 1, 6, 2, 7 ]
Repeat until the highest and lowest converge: [ 1, 6, 3, 4, 5, 2, 7 ]

The higher and lower numbers can easily be expressed as n-i and i+1 respectively.

var solution =

n=>
  [...Array(n)] // create an array of length n
  .map((_,i)=>  // set each value of the array at index i
    (i<n/2      // if we're on the left side,
    |n%2)       // or we're on the right and n is odd, even i => lower, odd i => higher
    ^i%2?       // else even i => higher, odd i => lower
    i+1:n-i
  )
N = <input type="number" id="input" oninput="result.textContent=solution(+this.value)" />

Nice algorithm; I tried and failed to think of a formula to generate them so I had to use the uglier method of pushing and unshifting. However, I can of course simplify your logic to (i<n/2||n%2)^i%2?i+1:n-i.

@Neil Wow, I just woke up, decided to golf this and came up with your exact logic and started typing it out right as you posted it! Crazy...

Python2, 105 98 bytes
7 bytes saved thanks to the comment by @Dennis
n=input()
r=([],[n/2+1])[n%2]
for i in range(n/2,0,-1):k=[n+1-i];r=([i]+r+k,k+r+[i])[i%2]
print r

Edited version 58 bytes
lambda n:[(n-i-1,i)[(i+(n,1)[i<n/2])%2]for i in range(n)]

I already believed it should be possible to do it as a one-liner, but the logic was too complex for me. Seeing the JavaScript-answer by @user81655 and the lambda-notation in @Dennis Python-answer, I gave it new try.
The condition is equal to
if i < n/2:
    i%2 != n%2
else:
    (i+1)%2

Unfortunately all the transformation effort saves only one no byte compared to the direct translation (i<n/2or n%2)!=i%2 of the JavaScript-logic.

Welcome to Programming Puzzles & Code Golf! This appears to be Python 2, so you don't need the int() around the input. Also, you can put the for loop's body on the same line as for....

Python, 51 49 bytes
lambda n:[(i^min(i,~i%n)%-2)%n for i in range(n)]

Thanks to @xnor for golfing off 2 bytes!
Try it on Ideone.
How it works
If i is a number in [0, ..., n - 1], then ~i % n = -(i + 1) % n = -(i + 1) + n = (n - 1) - i, meaning that it maps 0 to n - 1, 1 to n - 2 and, in general, the jth item from the left to the jth from the right.
As explained in my Jelly answer, we can construct the output by peeking at the lower value among i and ~i % n, and pick i if it is even and ~i % n if it is odd. We achieve this as follows.

If the minimum is even, min(i,~i%n)%-2 will yield 0, so XORing the result with i will yield i, and computing its residue modulo n will return i.
If the minimum is odd, min(i,~i%n)%-2 will yield -1, so XORing the result with i will yield ~i, so the entire expression evaluates to ~i % n as desired.

You can save a couple of chars by doing the conditional as (i^min(i,n+~i)%-2)%n.

That's not only short but insanely clever. Thank you!

PHP, 77 76 51 50 49 bytes
Uses ISO 8859-1 encoding.
Assembling the first half of the array like this:

Odd numbers have their index value (1, 3, 5..)
Even numbers have the value of N+1-index (9, 7, 5)
This results in 1, 9, 3, 7, 5

As for the second half of the array, the outermost values add up to N+1, which means you can get the corresponding right value from N-[left value] where the left value is already known.
for(;$k=$argv[1]-$j++;)echo" ",min($j,$k)%2?$j:$k;

Run like this (this also shows the total squared difference) (-d added for aesthetics only):
php -d error_reporting=32757 -r 'for(;$k=$argv[1]-$j++;)echo~ß,$x[]=min($j,$k)%2?$j:$k;  for(;$c=$x[+$i++];)$b+=($c-($x[$i]?:$x[0]))**2;echo"\n$b\n";' 10

Saved a byte by negating left/right condition so the second ternary can be nested without parentheses
Saved 25 bytes by shamelessly implementing Dennis' algorithm
Saved a byte by getting rid of the needed space after echo
Saved a byte by using ~ß to yield a space.

CJam, 17 15 14 bytes
{,W%ee_::e<.=}

This is a function that pops an integer n from the stack and pushes a permutation of [0 … n-1] in return. The code uses the same approach as my Jelly answer.
Try it online!
How it works
,W%ee_::e<.=    Function body. Stack: N

,               Turn N into [0 ... N-1].
 W%             Reverse to push [N-1 ... 0].
   ee           Enumerate. This pushes [[0 N-1] [1 N-2] ... [N-2 1] [N-1 0]].
     _          Push a copy of the array of pairs.
      ::e<      Reduce each pair by minimum.
          .=    Vectorized selection.
                For the Ith minimum M, select the Mth element of the Ith pair.
                Indices are modular and 0-based in CJam, so this selects the first
                element if the minimum is even, and the second one if it is odd.

Python 2, 100
I know there's already a python answer, but I think I may have done this differently.
n=input();a=n%2;b=n/2;x=[b+1,b+a][a:]
for i in range(b+a-1):f=1-i%2*2;x=[x[-1]-f]+x+[x[0]+f]
print x

And as an extra to test the total score:
def t(x,n):return sum((x[i]-x[(i+1)%n])**2for i in range(n))

def t(x,n):return sum((x[i]-x[i-1])**2for i in range(n)) uses the implicit wrap-around of negative indices and saves 4 bytes. I know, wasn't part of the  competition. ;)

LISP, 86 bytes
(defun g(n m)(if(= n m)(list n)(if(< m n)(cons m(reverse(cons n(g(- n 1)(+ m 1))))))))

The inputs of the function allow to choose the start (m) and the end (n) values of the sequence.
For testing the function according to the provided samples, n is fixed to N and m to 1.
Here the code to test the function:
    (defun g(n m)(if(= n m)(list n)(if(< m n)(cons m(reverse(cons n(g(- n 1)(+ m 1))))))))

(defun sq (c)
    (apply #'+ (mapcar #'(lambda(x y) (* (- x y) (- x y))) c (append (cdr c) (list (car c))))))

(format t "N~20TSequence~50TSquared Difference~%")
(mapcar #'(lambda (x)(format t "~S~20T~S~50T~S~%" x (g x 1) (sq (g x 1)))) '(1 2 3 4 5 6 7 8 9 10 33 100 333 1000))

Try it on Ideone!

Julia, 39 bytes
n->map(i->min(i-1,n-i)%2>0?n-~-i:i,1:n)

This prints a permutation of 1:n. A permutation of 0:n-1 does neither cost nor save bytes:
n->map(i->min(i,n+~i)%2>0?i:n+~i,0:n-1)

This last version is a direct port of my Python answer.

R, 117 86 bytes
z=1:(n<-scan());a=pmin(z,n:1);for(i in seq(2,,2,n%/%2))z[b]=z[rev(b<-which(a==i,T))];z

edit replaced buggy long version with an implementation of @Dennis' Jelly algorithm

ES6, 77 bytes
n=>[...Array(n)].map(_=>r[++i&2?"push":"unshift"](i&1?n--:++j),i=j=0,r=[])&&r

The i&1 samples the digits from the extremes to the middle. The i&2 adds them to the beginning or end of the result in pairs.


text:
Same-color arithmetic progressions
Van der Waerden's theorem says that

For any given positive integers r and k, there is some number N such
  that if the integers {1, 2, ..., N} are colored, each with one of r
  different colors, then there are at least k integers in arithmetic
  progression all of the same color. The least such N is the Van der
  Waerden number W(r, k).

Your goal is to compute the Van der Waerden number W(r, k) given positive-integer inputs r and k. Fewest bytes wins.
Beware that this function grows extremely quickly and is time-consuming to compute. Even W(4, 4) is unknown. You may assume your code runs on an ideal computer with unlimited resources (time, memory, stack depth, etc). Your code must theoretically give the right answer even for values for which the answer is not known.
Built-ins that compute this function are not allowed.
Example
For r = 2 colors and progressions of length k = 3, there is a length-8 sequence that avoids such a progression, i.e. 3 equally-spaced elements of the same color:
B R R B B R R B

But, there's no such length-9 sequence, so W(2, 3) == 9. For instance,
R B B R B R R B R
  ^     ^     ^

contains the length-3 same-color arithmetic progression shown.
Test cases
You'll probably only be able to test small cases.
+-----+-----+-----+-----+-----+-----+------+
|     | k=1 | k=2 | k=3 | k=4 | k=5 | k=6  |
+-----+-----+-----+-----+-----+-----+------+
| r=1 |   1 |   2 |   3 |   4 |   5 |    6 |
| r=2 |   1 |   3 |   9 |  35 | 178 | 1132 |
| r=3 |   1 |   4 |  27 | 293 |     |      |
| r=4 |   1 |   5 |  76 |     |     |      |
+-----+-----+-----+-----+-----+-----+------+

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

Python 3.5, 125 124 119 bytes
f=lambda r,k,*L:any(L[:x*k:x]==k*(*{*L[:x*k:x]},)for x in range(1,len(L)+1))*len(L)or max(f(r,k,i,*L)for i in range(r))

It's funny because, over the course of golfing this, the program actually got more efficient. Anything beyond f(2,4) or f(3,3) still takes forever, though.
Explanation
The initial version checked whether a sequence contained a progression of length k by trying all possible start indices and steps.
def f(r,k,L=[]):
 for i in range(len(L)):
  for j in range(len(L)):
   if len(set(L[i::j+1]))==1 and len(L[i::j+1])==k:
    return len(L)
 return max(f(r,k,L+[i])for i in range(r))

The golfed version only needs to try all possible steps since it prepends new sequence elements. The x*k cap is to take care of cases like [0, 0, 1], which contains a progression of length 2 but would not satisfy the uniqueness check uncapped.
As for the check
L[:x*k:x]==k*(*{*L[:x*k:x]},)

On the first pass of the golfed version, when L is empty, len(L) is 0. Thus the second half of the or will always be executed. After that L is non-empty, so {*L[:x*k:x]} (which is just Python 3.5 for set(L[:x*k:x])) will have at least one element.
Since L[:x*k:x] can have at most k elements and for L non-empty k*(*{*L[:x*k:x]},) has at least k elements, the two can only be equal when there are exactly k elements in both. For this to happen {*L[:x*k:x]} must have exactly one element, i.e. we only have one colour in our progression.


text:
Convert to and from the backwards-factorial number base
I wanted to ask this question: Convert to and from the factorial number system but I'm a couple of years too late!
So, instead you must convert to and from the lairotcaf backwards-factorial number base! The way it works is that the first digit is always 0, the maximum value of the next digit is 1, then 2 and so on. If a number has n digits, then each place value is given by n!/i! where i is the digit position starting at 1 on the left. The highest digit position is on the right. This means that each length uses different place values!
There is a unique shortest way to represent each number, which is what you must output for a decimal number input. If an input number starts with a 0, convert it to decimal. If it starts with any other digit, convert it to the backwards-factorial number base.
0 is both valid and the same number in both bases. In the test data no input value will use, or produce a number with a digit higher than 9. Note that the shortest representation of some numbers starts with multiple 0s.
Digit position:   1   2   3   4   5   6
Place value:    720 360 120  30   6   1
                  0   0   2   2   3   3
                  0   0 240+ 60+ 18+  3=321

This is the shortest way to represent 321 because removing a digit makes the highest number possible only 119 (5! - 1).
Test data:
Input:      Output:
0           0
1           01
002         2
3           010
011         4
5           012
0012        6
21          0121
0130        24
01000       60
01234       119
001000      120
321         002233
011235      563
0010330     987
4321        0120252
54321       000325536
654321      0010135621
0112351713  2838883
7654321     00102603574

This is code-golf so the fewest bytes wins!

ES6, 135 108 bytes
s=>s<"1"?[...s].reduce((t,d,i)=>+d+t*++i):eval("for(i=j=k=1;i<=s;i*=++j);for(r='';k<=j;k++)r+=s%i/(i/=k)|0")

Converting from backwards-factorial is nice and easy. Converting to it... not so nice. I found a 119-byte version that doesn't use eval:
s=>s<"1"?[...s].reduce((t,d,i)=>+d+t*++i):(i=j=k=1,g=_=>s<i||g(i*=++j),g(),[...Array(j)].map(_=>s%i/(i/=k++)|0).join``)

Jelly, 36 bytes
⁵R!>³¬TUŻ‘PƤµ³%Ḋ:ṖUŻṾ€
Jṙ1PÐƤḋV€µÇ¬?

Try it online!
How it works
⁵R!>³¬TUŻ‘PƤµ³%Ḋ:ṖUŻṾ€  Aux. link (monad). Integer -> string
⁵R!           [1..10]!
   >³¬T       All indices of above <= input
       UŻ‘    Reverse, prepend 0, increment
          PƤ  Product of each prefix
            µ           Re-focus on the above
             ³%Ḋ:Ṗ      Input % (next base value) // (own base value)
                  UŻṾ€  Reverse, prepend zero, map each digit to string

Jṙ1PÐƤḋV€µÇ¬?  Main link (monad). String -> integer || Integer -> string
         µÇ¬?  If input is string, apply the link on the left;
               otherwise, apply the aux. link
Jṙ1        List of indices rotated once to the left
   PÐƤ     Product of each suffix
      ḋV€  Convert each input char to digit, and dot product with above

Uses some tricks from my own Jelly answer for factorial base challenge.

Perl 6, 71 bytes
{{/^0/??.comb.reduce(* *-+^++$+*)!![R~] .polymod(+.polymod(1..*)...2)}}

Try it online!


text:
Expand shorthand increasing integer sequences
Given an input of a list of numbers in the format of a shorthand increasing
integer sequence, output the sequence in full.
Shorthand increasing integer sequence format works by finding every number n
with fewer digits than the number preceding it, m. With d as the number of
digits in n, the last d digits of m are replaced with all the digits of
n. Here's an example input:
123 45 6 7 89 200

Applying the replacement rule, we first turn 45 into 145 because 45 < 123:
123 145 6 7 89 200

Repeatedly applying the same rule, this becomes:
123 145 146 7 89 200
123 145 146 147 89 200
123 145 146 147 189 200

The sequence is now sorted (there are no numbers for which the rule applies),
so this is the final output.
You may assume that

shorthand notation is always used when possible. For example, input will be
12 3, never 12 13.
numbers will never decrease while remaining the same number of digits. For
example, input will never be 333 222.
applying the shorthand rule will never result in a number that is still less
than the previous number in the sequence. For example, input will never be
123 12.
numbers will always be positive integers and never contain leading 0s (if
using a string format).
the full, expanded sequence will never contain duplicate numbers. (However,
the shorthand sequence might; ex. 10 1 20 1 -> 10 11 20 21.)
there will be at least one number in the input.

Input and output can be either lists/arrays of numbers/strings or a single
string with elements separated by any non-digit.
Since this is code-golf, the shortest code in bytes will win.
Test cases, with input and output on alternating lines:
1 2 3 10 1 2 20 5 100 200 10 3 5 26 9 99 999 9999
1 2 3 10 11 12 20 25 100 200 210 213 215 226 229 299 999 9999
223 1184 334 441 5 927 2073 589 3022 82 390 5 9
223 1184 1334 1441 1445 1927 2073 2589 3022 3082 3390 3395 3399
5 10 5 20 5 30 5 40 5 50 5
5 10 15 20 25 30 35 40 45 50 55
7 8 9 70 80 90 700 800 900 7000 8000 9000
7 8 9 70 80 90 700 800 900 7000 8000 9000
42
42

Challenge is pretty old, but a) can the input be empty? b) can the input contain only one number?

@EriktheOutgolfer I'll go ahead and say there will be ≥1 numbers in the input.

Jelly, 7 bytes
DUṛ"\UḌ

Try it online! or verify all test cases.
How it works
DUṛ"\UḌ  Main link. Input: A (list of integers)

D        Convert each integer to a list of its base 10 digits.
 U       Reverse each digit list.
    \    Do a cumulative reduce, applying the dyadic link to the left:
   "       For each pair of corresponding digits:
  ṛ          Select the right one.
           Vectorization leaves digits that do not have a counterpart untouched.
     U   Reverse the resulting digit arrays.
      Ḍ  Convert from base 10 to integer.

Javascript, 45 42 bytes
3 bytes off thanks @Neil.
a=>a.map(x=>z=z.slice(0,-x.length)+x,z='')

The above function expects an array of strings.

f=
a=>a.map(x=>z=z.slice(0,-x.length)+x,z='')

F=a=>document.body.innerHTML+='<pre>'+a+'\n'+f(a)+'\n</pre>';

F(['1','2','3','10','1','2','20','5','100','200','10','3','5','26','9','99','999','9999'])
F(['223','1184','334','441','5','927','2073','589','3022','82','390','5','9'])
F(['5','10','5','20','5','30','5','40','5','50','5'])
F(['7','8','9','70','80','90','700','800','900','7000','8000','9000'])

Save 4 bytes using z=z.slice(0,-x.length)+x,z='' (or variable name of your choice).

@Neil. Nice one! I knew there should have a way to do that

(Sorry for miscounting the saving.) Also, the string version is unnecessary as it turns out that s=>s.split\ `.map(is 2 bytes (I double-checked this time) shorter thans=>s.replace(/\d+/g,`.

@Neil. Valid point. I just leaved it there because was my first goal when answering... but you are right

Retina, 45 bytes
+`(?=(?<1>\d)+)(?<=(\d)(?(1)x)(?<-1>\d)+ )
$1

Uses balancing groups to count the digits which costs a lot. Haven't found a better approach yet but I'm interested in it.
Try it online here.

Gema, 35 characters
<D>=@set{p;@fill-right{${p;};$0}}$p

Input: string with numbers separated by anything, output string.
Sample run:
bash-4.3$ gema '<D>=@set{p;@fill-right{${p;};$0}}$p' <<< '123 45 6 7 89 200'
123 145 146 147 189 200

Ruby, 39 characters
->a{l='';a.map{|c|l=l[0..-c.size-1]+c}}

Input: array of strings, output: array of strings.
Sample run:
2.1.5 :001 > ->a{l='';a.map{|c|l=l[0..-c.size-1]+c}}[%w{123 45 6 7 89 200}]
 => ["123", "145", "146", "147", "189", "200"]

Python 2, 58 bytes
s=''
for i in input():s=s[:max(len(s)-len(i),0)]+i;print s

Try it online!


text:
Calculating Parabolic Curves in 3D Space
Task
Write a program or function that will determine if a point in 3D space lies on a 2D parabolic curve.

Input
3 points in 3D space

vertex of a 2D parabolic curve
arbitrary point on the curve
arbitrary point in space

Input may be taken in any form (string, array, etc.) provided no other data is passed.

You may assume

the axis of a parabola will be parallel to the z axis
the vertex of a parabola has the maximal z value
parabolae will never degenerate
point values will be whole numbers that are ≥ -100 and ≤ 100

Output
A truthy/falsey value representing whether the third point given lies on the parabolic curve of the first two points.

Examples
Input:
(2, 1, 3)
(1, 0, 1)
(4, 3, -5)

Output:
1

Input:
(16, 7, -4)
(-5, 1, -7)
(20, 6, -4)

Output:
0

Walkthrough (Example #1)

Find a third point on the curve. To do this, mirror the arbitrary point (on the curve) over the vertex. Here is a visual (each blue line is √6 units):

Find the parabolic curve between the three. This is easiest on a 2D plane. Here is the 3D graph, translated to a 2D graph (each blue line is √6 units):

Graph the third given point and solve.

I'll have a Jelly answer in five minutes.

@ThomasKwa its been 6 minutes.

@Maltysen Sorry for the disappointment; I think a feature may have changed.

by "axis of the parabola is parallel to z-axis" you mean that the plane containing the parabola is parallel to the z-axis?

@Liam both the plane containing the parabola, and also its plane of symmetry. The intersection of those two planes defines the axis.

Jelly, 13 11 bytes
_÷/µḢ²=A;$P

The input format is a bit strange; it takes P1 as the second argument, and (P3,P2) as the first argument, where each point is expressed in the form ((x+yj),z).
We first normalize the points so that the vertex is on the origin, and then make sure that P1 and P2 are on the same line, and also that the ratio of their z distances is equal to the ratio of their x distances.
_÷/             Helper link. Inputs: (P3,P2) on left, P1 on right.
_                  Subtract right from left. (P3-P1,P2-P1).
 ÷/                Fold division. (P3-P1)/(P2-P1). P2-P1 is nonzero in both x+yi and z.
   µ               Push the chain onto the stack, and start a new monadic link.
    Ḣ²=A;$P     Hook; main link. Calculates whether w² = a and a is nonnegative.
                Input: The result of the helper link. Call it [w,a].
    Ḣ²              Pop w and square it. Now the list is [a].
       A,$          Concatenate a to its absolute value.
      =             Fork; is w equal to [a,abs(a)]? Returns 2 element list of 0 or 1
          P         Product; that is, true if w was equal to both a and abs(a).

Try it here.