text:
Construct the Jacobian matrix
Take the vector of unknowns , and apply some generic differentiable function . The Jacobian is then given by a matrix  such that:

For example, suppose m=3 and n=2. Then (using 0-based indexing)

The Jacobian of f is then

The goal of this challenge is to print this Jacobian matrix.
Input
Your program/function should take as input two positive integers m and n, which represent the number of components of f and u respectively. The input may come from any source desired (stdio, function parameter, etc.). You may dictate the order in which these are received, and this must be consistent for any input to your answer (please specify in your answer).
Output
Something which represents the Jacobian matrix. This representation must explicitly spell out all elements of the Jacobian matrix, but the exact form of each term is implementation defined so long as is unambiguous what is being differentiated and with respect to what, and every entry is outputted in a logical order. Example acceptable forms for representing a matrix:

A list of lists where each entry of the outer list corresponds to a row of the Jacobian, and each entry of the inner list corresponds to a column of the Jacobian.
A string or textual output where each line is a row of the Jacobian, and each delimiter separated entry in a line corresponds to a column of the jacobian.
Some graphical/visual representation of a matrix. Example: what is shown by Mathematica when using the MatrixForm command
Some other dense matrix object where every entry is already stored in memory and can be queried (i.e. you can't use a generator object). Example  would be how Mathematica internally represents a Matrix object

Example entry formats:

A string of the form d f_i/d u_j, where i and j are integers. Ex: d f_1/d u_2. Note that these spaces between d and f_1 or x_2 are optional. Additionally, the underscores are also optional.
A string of the form d f_i(u_1,...,u_n)/d u_j or d f_i(u)/d u_j. That is, the input parameters of the function component f_i are optional, and can either be explicitly spelled out or left in compact form.
A formatted graphical output. Ex.: what Mathematica prints when you evaluate the expression D[f_1[u_,u_2,...,u_n],u_1]

You may choose what the starting index for u and f are (please specify in your answer). The output may be to any sink desired (stdio, return value, output parameter, etc.).
Test cases
The following test cases use the convention m,n. Indexes are shown 0-based.
1,1
[[d f0/d u0]]

2,1
[[d f0/d u0],
 [d f1/d u0]]

2 2
[[d f0/d u0, d f0/d u1],
 [d f1/d u0, d f1/d u1]]

1,2
[[d f0/d u0, d f0/d u1]]

3,3
[[d f0/d u0, d f0/d u1, d f0/d u2],
 [d f1/d u0, d f1/d u1, d f1/d u2],
 [d f2/d u0, d f2/d u1, d f2/d u2]]

Scoring
This is code golf; shortest code in bytes wins. Standard loopholes are forbidden. You are allowed to use any built-ins desired.

Python, 63 bytes
lambda m,n:["df%d/du%%d "%i*n%tuple(range(n))for i in range(m)]

For m=3,n=2, outputs
['df0/du0 df0/du1 ', 'df1/du0 df1/du1 ', 'df2/du0 df2/du1 ']

The string formatting is 1 byte shorter than the more obvious
lambda m,n:[["df%d/du"%i+`j`for j in range(n)]for i in range(m)]

R, 93 78 bytes
function(M,N){v=vector();for(i in 1:N){v=cbind(v,paste0("df",1:M,"/du",i))};v}

The numbering is 1-based.
-15 bytes thanks to @AlexA. remaks !

You can save a few bytes by removing the function name, i.e. f=, as that's common practice here. R also returns the last thing evaluated in a function, so you can just use v instead of return(v).

You should also be able to save bytes by indexing from 1 instead of 0, which is permitted by the OP.

@AlexA. Very interesting remarks, thanks a lot !

My pleasure. :)

Maxima, 68 bytes
It's too bad I don't know Maxima like I know my dear C and Matlab. But I'll try nontheless.
f(m,n):=(x:makelist(x[i],i,m),g:makelist(g[i](x),i,n),jacobian(g,x))

Example session using TeXmacs as a Maxima interpreter, mostly for neat math rendering:

There may very well be better ways doing lists and such in Maxima (I would especially like to make the functions appear without the list markers, []), but I don't know the language well enough.

Ruby, 53 bytes
f is 0-indexed, u is 1-indexed. Try it online!
->m,n{m.times{|i|p (1..n).map{|j|"d f#{i}/d u#{j}"}}}

Each row occupies one line as an array representation as seen below. If it isn't compliant to spec, please let me know and I will fix it.
["d f0/d u1", "d f0/d u2", "d f0/d u3"]
["d f1/d u1", "d f1/d u2", "d f1/d u3"]

Cheddar, 79 49 bytes
m->n->(|>m).map(i->(|>n).map(j->"df%d/du%d"%i%j))

Apparently a fork of this answer.
For 3,2 returns:
[["df0/du0", "df0/du1", "df0/du2"], ["df1/du0", "df1/du1", "df1/du2"]]

Jelly, 18 bytes
ps⁴’“ df“/du”ż$€€G

Try it out!
Given (m, n) = (3, 2), prints (with spaces marked as ·:)
·df0/du0·df0/du1
·df1/du0·df1/du1
·df2/du0·df2/du1

C, 125 bytes:
main(w,y,b,q){scanf("%d %d",&w,&y);for(b=0;b<w;b++){for(q=0;q<y;q++)printf("d f%d/du u%d%s",b,q,q<y-1?", ":"");printf("\n");}}

Takes input as 2 space separated integers, b y, and outputs the Jacobian Matrix as y comma separated strings on b lines.
C It Online! (Ideone) or Test Suite (Ideone)

114 bytes


text:
Count the rectangles in a diagonal grid
As a follow-up to this challenge, we now want to count the number of rectangles in grid with r rows and c columns where there is a line crossing through every diagonal of a square in the grid. Now, we are still counting the the same rectangles as before, but this time we must also include rectangles that are tilted by 45 degrees.
Your goal is to create a function or program that given the number of rows r and columns c outputs the number of rectangles in a diagonal grid with dimensions (r, c).
As a demonstration, this is an animation that iterates through all 37 rectangles formed by a (2 x 3) diagonal grid.

Test Cases
Each case is [rows, columns] = # of rectangles
[0, 0] = 0
[0, 1] = 0
[1, 0] = 0
[1, 1] = 1
[3, 2] = 37
[2, 3] = 37
[6, 8] = 2183
[7, 11] = 5257
[18, 12] = 40932
[42, 42] = 2889558
[51, 72] = 11708274

Rules

This is code-golf so the shortest code wins.
Builtins that solve this are not allowed.

Only Mathematica could have a builtin for this XD

Gosh, this is a lot more difficult than the other rectangle ones.....

See related challenge https://projecteuler.net/problem=147

I think built-ins should be allowed. I like seeing those answers.

Ruby, 58 bytes
This is a straightforward implementation of the algorithm in Releasing Helium Nuclei's C answer.
g=->m,n{n>m ?g[n,m]:m*~m*n*~n/4+n*((2*m-n)*(4*n*n-1)-3)/6}

I have been investigating why this formula works, with limited success. It's easy to confirm that the number of upright rectangles is equal to (m+1)*m/2 * (n+1)*n/2, the number of diagonal rectangles is a little more elusive.
Neil has confirmed for m==n that the number of tilted rectangles in an n*n square is (4*n**4-n*n-3*n)/6 and that when m>n you need to add an additional (m-n)(n*(4*n*n-1)/3) (related to OEIS A000447), though this does not explain where those two formulas came from. I have found part of the answer.
For m==n, the shape inside the grid is an Aztec diamond.

The number of rectangles in an Aztec diamond is the sum of number of large rectangles superimposed to make it (for the fourth diamond, which is found in a 5x5 grid, 2x8, 4x6, 6x4, and 8x2) minus the number of the rectangles counted twice (the number of rectangles in the previous Aztec diamond).
The formula here is (TeX to be added later):
# superimposed rectangles, 2x(2n-2), 4*(2n-4), ...
f = lambda n: sum( (2*k)*(2*k+1)/2 * (2*n-2*k)*(2*n-2*k+1)/2 for k in range(1, n) )
aztec_rect = f(n) - f(n-1)

According to Wolfram Alpha, the closed form for f is 1/30*(n-1)*n*(4*n**3+14*n**2+19*n+9) and the closed form for aztec_rect is, as Neil discovered, 1/6*n*(n-1)*(4*n**2+4*n+3) == 1/6*(4*n**4-n**2-3*n).
I have yet to discover why (m-n)(n*(4*n*n-1)/3) works, though I suspect that it is because one definition of A000447 is binomial(2*n+1, 3). I will keep you posted.
Update: I have reason to believe that the function of the number of rectangles in an extended Aztec diamond m>n is related to the number of superimposed 2k*2(n-k) rectangles in the diamond minus F(m-1,n-1). More results when I have them.
Update: I tried a different route and ended up with another formula for extended Aztec diamonds that is mostly explainable but has one term that I don't yet understand. Huzzah! :D
def f(m,n):
 if n > m:
     return f(n,m)
 if n == 0:
     return 0
 else:
     return(m-n+1)*(4*n**4-n*n-3*n)/6-f(m-1,n-1)+(m-n)*2+(m-n)*(n-2)-(m-n-1)*f(n-1,n-1)

A quick breakdown of that last formula:

(m-n+1)*(4*n**4-n*n-3*n)/6 is the number of superimposed Aztec diamonds of size n in the structure, as f(n,n) = (4*n**4-n*n-3*n)/6. f(7,3) has 5 superimposed Aztec diamonds size 3, while f(3,3) has only 1 diamond.
-f(m-1,n-1) removes some of the duplicate rectangles from the middle of the superimposed diamonds.
+(m-n)*2 accounts for 2 extra 2-by-(2n-1) rectangles for each extra diamond.
+(m-n)*(n-2) accounts for an extra n-by-n square for each extra diamond.
-(m-n-1)*f(n-1,n-1) This is the new puzzling term. Apparently I have not accounted for some extra squares in my counting, but I haven't figured out where they are in the extended diamond.

Note: when m==n, m-n-1 = -1, meaning that this last term adds squares to the counting. I might be missing something in my regular formula. Full disclosure, this was only meant to be a patch to an earlier draft of this formula that just happened to work. Clearly, I still need to dig into what's going on, and it may be that my formula has some bugs in it. I'll keep you posted.
Russell, Gary and Weisstein, Eric W. "Aztec Diamond." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/AztecDiamond.html

I like how this answer has more upvotes than the original answer, and a +100 bounty... :P

This newer OEIS link has the sequence in question and may answer some of the outstanding questions here: http://oeis.org/A330805

C, 71 64 bytes
f(m,n){return n>m?f(n,m):m*~m*n*~n/4+n*((2*m-n)*(4*n*n-1)-3)/6;}

Try it on Ideone

I'd love to know what's going on here and how you arrived at this solution.

@Jordan So far I've verified the second half of the formula for m==n: the number of tilted rectangles in an n*n square is (4*n*n*n*n-n*n-3*n)/6. The sequence is 0, 9, 51, 166, 410, 855, 1589, 2716, 4356, 6645 but it doesn't appear in OEIS.

I've now verified that when m>n you need to add an additional (m-n)(n*(4*n*n-1)/3) (latter part of formula taken from OEIS A000447). Rearranging and adding gives @betseg's formula.

@Neil How did you arrive at those formulas?

@Sherlock9 I manually calculated the numbers of tilted rectangles in the first 10 squares and fed the sequence into the OEIS search engine which didn't recognise the sequence but found a formula for it which matched the OP's formula for m==n. I then manually calculated the numbers of tilted rectangles in small rectangles and noticed increasing the longer dimension always added the same amount of rectangles for a given shorter dimension. I fed the increments into OEIS which found a match on A000447.

@Neil It looks like this has since been added: http://oeis.org/A330805

@Jonah So that's orthogonal rectangles in a tilted square - I guess it's not surprising that it's the same as the number of titled rectangles in an orthogonal square.

Right.  Technically we still need that proof too.  I haven’t tried to think about it but thought the link might be of use to someone

Python, 73 68 bytes
x=lambda m,n:m*~m*n*~n/4+n*((2*m-n)*(4*n*n-1)-3)/6if m>n else x(n,m)

And while the following version has a higher bytecount (75), it was a nice exercise in finding places to use ~:
def f(r,c):
 if r<c:r,c=c,r
 x=(4*c**3-c)/3
 return r*c*~r*~c/4+x*r--~x*c/2

68 bytes if you use a lambda: x=lambda m,n:m*~m*n*~n/4+n*((2*m-n)*(4*n*n-1)-3)/6if m>n else x(n,m)

Ahh, for some reason I assumed we had to use def. Thanks! Updated.

Convex, 37 36 bytes
__:)+×½½\~æ<{\}&:N\¦\-N¦¦N*(*3-N*6/+

Try it online!
Uses betseg's algorithm modified and optimized for a stack-based language. Explanation to come when I have some more free time. I bet this can be shortened but I'm not going to bother at the moment.

Batch, 82 bytes
@if %2 gtr %1 %0 %2 %1
@cmd/cset/a%1*~%1*%2*~%2/4+((%1+%1-%2)*(%2*%2*4-1)-3)*%2/6

source: Stack Exchange

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

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

sort: votes


text:
A newly discovered number: bleen!
"The Nobel Prize in mathematics was awarded to a California professor who has discovered a new number! The number is bleen, which he claims belongs between 6 and 7."  --George Carlin
In this challenge, you will print all Integers, inclusive, within the given input range.  Print numbers ascending or descending according to their input order.  That is, for input [n1, n2], print ascending if n1 < n2, descending if n1 > n2.
Since bleen is now an Integer number it may be used as input.  It must also be included in the output, between 6 and 7 where applicable.  Also note that -bleen exists between -7 and -6.
Input
Two Integers [n1, n2] in the range [-10, 10], inclusive, via your programming language's input of choice.
(Input may also contain bleen and -bleen!)
Output
Print all Integers starting at n1 and ending with n2, including the newly discovered bleen between 6 and 7.  Output can be a range of character separated numbers in some form your language supports - that is, comma or space separated.  One trailing space of output is okay.
Examples
Input:  1 10
Output: 1 2 3 4 5 6 bleen 7 8 9 10

Input:  -9 -4
Output: -9 -8 -7 -bleen -6 -5 -4

Input:  -8 bleen
Output: -8 -7 -bleen -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 bleen

Input:  9 1
Output: 9 8 7 bleen 6 5 4 3 2 1

Input:  2 -bleen
Output: 2 1 0 -1 -2 -3 -4 -5 -6 -bleen

Input:  -bleen 0
Output: -bleen -6 -5 -4 -3 -2 -1 0

Input:  bleen bleen
Output: bleen

Input:  2 2
Output: 2

Additional notes
You may write a program or function and use any standard method of receiving input and providing output.
You may use any programming language, but standard loopholes are not allowed.
This is code-golf, so the shortest valid answer – measured in bytes – wins.

Can output be prefixed and postfixed, i.e. [1 2 3 4 5 6]?

@LeakyNun Sure!

Is bleenteen between 16 and 17 also? (and is bleenty-bleen between bleenty-six and bleenty-seven?)

@Joffan ... and bleenty between 60 and 70?

@Adám - exactly, and so on...

@Joffan How much is (bleen + 7) / 2 ?

@Adám it is just possible that we are overthinking this :-)

According to #2 here, this is perfectly possible in a notation of base eleven, where 6₁₁ = 6₁₀, bleen₁₁ = 7₁₀, 7₁₁ = 8₁₀, 8₁₁ = 9₁₀, 9₁₁ = 10₁₀, 10₁₁ = 11₁₀.

(bleen₁₁ + 7₁₁) / 2 = bleen.555…₁₁ = 7.5₁₀

Newline separators are not allowed?

In mathematics there is only the Field's medal, no Nobel Prizes there....

@Graipher That's why you shouldn't rely on a comedian's standup bit as hard news ;)

@Geobits Wait, this new number is not real? But I just modified all the code I ever wrote to be in base 11...

@Graipher I never said it wasn't real. The part about the Nobel Prize probably wasn't though. Keep your modified code as-is :P

@Graipher: the Abel prize is a slightly closer analogue to the Nobel prize.

Was hoping for a bigger skit or context for Carlin and bleen. Here it is https://youtu.be/YHFLTb9Fp18?t=4m35s

So apparently Derf isn't the only newly established number... 1, 2, 3, 4, 5, derf, 6, bleen, 7, 8, 9, 10

@PatrickRoberts There's also Gird between three and four: 1, 2, 3, gird, 4, 5, derf, 6, bleen, 7, 8, 9, 10

Python 3, 132 130 bytes
r=round
bleen=6.1
m=1.08
a,b=eval(input())
d=1-2*(a>b)
print(*[[r(i/m),"-bleen"[i>0:]][i*i==49]for i in range(r(m*a),d+r(m*b),d)])

Takes input in the following example format:
-8, bleen

Does this work outside of [-10,10]?

@mbomb007 Nope.

Very ingenious solution with bleen and eval there, nice one. Another suggestion: use bleen=7/m for clearification without character penalty

@orlp is there a reason you named the variable bleen and not just a single digit char?

@muddyfish Yes, it's necessary for the eval to translate bleen into the correct value.

Ohh... Thats really clever!

Ruby, 114 100 98 bytes
Input is an array with [n1, n2]. (If it must be two seperate arguments, +1 byte to change the function arg from g to *g. Bleen must be a string, "bleen". Outputs an array of the range. Suggested by @Jordan with his (?) initial version granting -7 bytes, but I also golfed off 7 more after that.
Try it online.
->g{a=*-10..-7,?-+b='bleen',*-6..6,b,*7..10;x,y=g.map{|v|a.index v}
y<x ?a[y..x].reverse: a[x..y]}

Original full program version that reads input from ARGV:
b='bleen'
a=[*-10..-7,?-+b,*-6..6,b,*7..10].map &:to_s
x,y=$*.map{|v|a.index v}
puts y<x ?a[y..x].reverse: a[x..y]

If you make this a lambda you can get rid of .map &:to_s and save 6 bytes, and you can save one more by changing the initialization of a to a=*-10..10;a[4,0]=?-+b;a[18,0]=b.

I.e. ->*g{b='bleen';a=*-10..10;a[4,0]=?-+b;a[18,0]=b;x,y=g.map{|v|a.index v};puts y<x ?a[y..x].reverse: a[x..y]}

@Jordan thanks. Didn't need to use the slicing trick to insert the bleen, though; my array composition is still shorter by about 1 byte.

Ah, I was counting the brackets; forgot you could omit them.

Should I upvote, or leave you at exactly 4k?

@NoOneIsHere lol fire away, it's going to break eventually anyhow

Pyth, 35 bytes
K++L\-P_J++`M7"bleen"`M}7TJ@LK}FxLK

Test suite.
The first part, i.e. K++L\-P_J++`M7"bleen"`M}7TJ, generates this array:
['-10', '-9', '-8', '-7', '-bleen', '-6', '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5', '6', 'bleen', '7', '8', '9', '10']

and then stores it in K.
The second part, i.e. @LK}FxLK, finds the sublist indicated by the input.

I thought of such an approach too. Mure interesting if we had to take any int range...

... and especially if we had to include bleenteen, and bleenty, etc.

Python 3, 157 145 123 108 115 139 161 158 153 bytes
Saved 22 thanks to Lynn. 17 saved thanks to shooqie. 3 saved thanks to ljeabmreosn. 5 saved thanks to Geoff Reedy.
a,b=eval(input())
s='-'
c='bleen'
d=a l=list(map(str,range(-10,11)))

Though I'm not sure why you need strings in the first place. l=list(range(-10,11)) works as well

Lines 2, 4, 5 can be replaced with for i in(4,18):l.insert(i,'bleen').

@shooqie The for loop is missing the negative sign at index 4. e.g. the list contains two elements of 'bleen' rather than a '-bleen','bleen'

Does it work for input 'bleen' or '-bleen'?

@edc65 it should now, input should now be in string form rather than int form

@JustinTervay instead of s=['-',' '], use s='- '

@JustinTervay: code doesn't work because you're looking for a number in a list, but it's a list of strings; use l=list(range(-10,11))[::[-1,1][a<b]] (which is shorter, too!)

@shooqie Works for me. My input is '-8','8'. Make sure you have the apostrophes. Your code won't work for cases where the input is 'bleen', 8. Also using s='- ' leaves a space in front of positive bleen, which isn't in the challenge and I'm picky. Note that my s=['-',''], the second part is just an empty string, not a space.

OK, I get it now. Still, having to include these apostrophes seems like a really dirty workaround to me.

@JustinTervay add d=ab] with d*s, replace [a<b] with [d] and s[a<b] with (1^d)*s. That should save 3 bytes.

you can save a few bytes by adding x=l.insert and y=l.index and replacing those occurrences by the variables

This doesn't work for me with the input '-2', '-9' (outputs an empty list, because '-2'<'-9' == True)

@WorldSEnder good catch, unsure how to fix in a short/concise manner

Ruby, 141 bytes
->*a{
l="bleen"
s=13
a,b=a.map{|n|2*n rescue s*(n<=>?b)}
b,a,r=a,b,1if b<a
o=(a..b).map{|n|n==s ?l:n==-s ??-+l:n/2}.uniq
puts r ?o.reverse: o}

Ungolfed
lambda do |*args|
  bleen = "bleen"
  subst = 13 # This will stand in for "bleen"

  a, b = args.map {|arg|
    begin
      # Double the number
      2 * arg
    rescue
      # It wasn't a number, so it's "bleen" or "-bleen"; replace it with 13 or -13
      subst * (arg <=> "b")
    end
  }

  if b < a
    # If the range isn't ascending, reverse it and remember that we did
    b, a, reverse = a, b, 1
  end

  # Step through the range, replacing 13 and -13 with "bleen" and "-bleen" and
  # halving everything else
  result = (a..b).map {|n|
    if n == subst
      bleen
    elsif n == -subst
      "-" + bleen
    else
      n / 2
    end
  }.uniq # Drop duplicates

  # Reverse the result if the range was descending
  puts reverse ? result.reverse : result
end

Batch, 239 186 bytes
@set/ableen=1431655772,a=%1*3,b=%2*3,c=b-a^>^>31^|1
@for /l %%i in (%a%,%c%,%b%)do @((if %%i==20 echo bleen)&(if %%i==-20 echo -bleen)&set/aj=%%i%%3,k=%%i/3&cmd/cif %%j%%==0 echo %%k%%)

Works by looping from 3*%1 to 3*%3 and then dividing by three and printing the numbers with no remainder, however setting bleen to that magic number causes integer overflow and the value 20 is used instead. This is then printed out at the appropriate point in the loop.

@edc65 When was the last time I read a question correctly first time...

@edc65 oh, and I forgot -bleen too. Bah.

Tried it but no output. Usage example?

@edc65 bleen.bat bleen -bleen perhaps?

No output, as I said. Is it dos/windows bat language? I use Windows 10

@edc65 Works for me in both Windows XP and Windows 10.

JavaScript (ES6), 158
Nice challenge, hard to golf. Probably the range methods used in Python and Ruby answers could score better even in JS.
(a,b)=>(c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,a=c(a),b=c(b),d=b>a?1:-1,a-=d,e=x=>x-7?x-(x>7):'bleen',[...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x)))

Less golfed
(a,b)=>(
  c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,
  a=c(a),b=c(b),
  d=b>a?1:-1,
  a-=d,
  e=x=>x-7?x-(x>7):'bleen',
  [...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x))
)

Test

f=(a,b)=>(c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,a=c(a),b=c(b),d=b>a?1:-1,a-=d,e=x=>x-7?x-(x>7):'bleen',[...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x)))

function go(){
  var a=A.value,b=B.value
  // make them numeric if possible
  a=isNaN(a)?a:+a
  b=isNaN(b)?b:+b

  O.textContent=f(a,b)
}
go()
A <select id=A onchange='go()'>
<option>-10<option>-9<option>-8<option>-7<option>-bleen<option>-6<option>-5<option>-4<option>-3<option>-2<option>-1<option>0
<option>1<option>2<option>3<option>4<option>5<option>6<option>bleen<option>7<option>8<option>9<option>10
</select>
B <select id=B onchange='go()'>
<option>-10<option>-9<option>-8<option>-7<option>-bleen<option>-6<option>-5<option>-4<option>-3<option>-2<option>-1<option>0
<option>1<option>2<option>3<option>4<option>5<option>6<option>bleen<option>7<option>8<option>9<option selected>10
</select>

I think you missed -6.

Swift 2.2, 342 Bytes
func a(x:String,y:String){var k="bleen",a=Int(x) ?? (x==k ?(x==y ? -9:6):-6),b=Int(y) ?? (y==k ?6:-6),t=0,s=[Any](),f=Int(x)==nil ?x:"";if a>b{t=a;a=b;b=t};for i in a...b{if i==7 && a != 7{s.append(k)};s.append(i);if -i==7 && b != -7{s.append("-"+k)}};for v in t==0 ?s:s.reverse(){f+=" \(v)"};if Int(y)==nil&&b>0{f+=" \(y)"};print(x==y ?x:f)}

Test this using IBM's Swift Sandbox
Ungolfed
func bleen(x: String, y: String){
    var k = "bleen",
        a = Int(x) ?? (x == k ? (x == y ? -9 : 6) : -6),
        b = Int(y) ?? (y == k ? 6: -6),
        t = 0,
        s = [Any](),
        f = Int(x) == nil ? x : ""

    if a > b{
        t = a
        a = b
        b = t
    }

    for i in a...b{
        if i == 7 && a != 7{s.append(k)}
        s.append(i)
        if -i == 7 && b != -7{s.append("-" + k)}
    }

    if Int(y) == nil && b > 0{s.append(y)}

    for v in t == 0 ? s : s.reverse(){
        f+="\(v) "
    }

    print(x == y ? x : f)
}

Python 3, 126 bytes
Input is in the form -5, 'bleen'
l=list(range(-10,11))
c='bleen'
s=l.insert
t=l.index
s(4,'-'+c)
s(18,c)
i,j=map(t,eval(input()))
d=1-2*(i<j)
print(l[i:j+d:d])

Java, 271 bytes
int p(String w){if(w.contains("b"))return w.length()<6?7:-7;int i=Integer.decode(w);return i<-6?i-1:i>6?i+1:i;}void b(String s,String f){Integer l=p(s),r=p(f);for(r+=l<r?1:-1;l!=r;l-=l.compareTo(r))System.out.print(l==-7?"-bleen ":l==7?"bleen ":l+(l<-7?1:l<7?0:-1)+" ");}

Ungolfed with test cases:
class Bleen {
     static int p(String w) {
         if(w.contains("b"))
             return w.length() < 6 ? 7 : -7;
         int i = Integer.decode(w);
         return i < -6 ? i-1 : i>6 ? i+1 : i;
     }

     static void b(String s, String f) {
         Integer l = p(s), r = p(f);
         for(r += l<r ? 1 : -1; l != r; l -= l.compareTo(r))
             System.out.print(l == -7 ? "-bleen " : l == 7 ? "bleen ": l+(l < -7 ? 1 : l<7 ? 0 : -1)+" ");
     }

     public static void main(String[] args) {
         b("1","10"); System.out.println();
         b("-9","-4"); System.out.println();
         b("-8", "bleen"); System.out.println();
         b("9", "1"); System.out.println();
         b("2", "-bleen"); System.out.println();
         b("-bleen", "0"); System.out.println();
         b("bleen", "bleen"); System.out.println();
         b("2", "2"); System.out.println();
     }
}

Call b(start, end). Because the parameters are strings, it takes a lot of space to convert those into ints. Essentially the program treats 7 & -7 as bleen and -bleen.

Nice answer, +1. Was pretty hard to come up with something to golf you answer, but I did. ;) Your method p can be changed to the following to save 6 bytes: int p(String w){int x=w.length(),i;if(x>3)return x<6?7:-7;i=Integer.decode(w);return i<-6?i-1:i>6?i+1:i;}. Also, you might want to state this is Java 7 and perhaps add an ideone.

Also, I've been able to make a shorter variant in Java 7 based on @LeakyNun's approach of first creating the complete list.

Java 7, 251 bytes
import java.util.*;String b(Object...a){String q="bleen",r="";List l=new ArrayList();int j=-10,i,z,y,t;while(j<11)l.add(j++);l.add(4,"-"+q);l.add(18,q);z=l.indexOf(a[0]);y=l.indexOf(b[1]);if(y<z){t=z;z=y;y=t;}for(i=z;i<=y;)r+=l.get(i++)+" ";return r;}

Different approach which is shorter than the already existing Java 7 answer.
Also, it's unfortunate that the parameters are potentially not in order, which adds some bytes to swap them around.
Ungolfed & test cases:
Try it here.
import java.util.*;
class Main{
  static String b(Object... a){
    String q = "bleen",
           r = "";
    List l = new ArrayList();
    int j = -10, i, z, y, t;
    while(j < 11){
      l.add(j++);
    }
    l.add(4, "-"+q);
    l.add(18, q);
    z = l.indexOf(a[0]);
    y = l.indexOf(a[1]);
    if(y < z){
      t = z;
      z = y;
      y = t;
    }
    for(i = z; i <= y; ){
      r += l.get(i++) + " ";
    }
    return r;
  }

  public static void main(String[] a){
    System.out.println(b(1, 10));
    System.out.println(b(-9, -4));
    System.out.println(b(-8, "bleen"));
    System.out.println(b(9, 1));
    System.out.println(b(2, "-bleen"));
    System.out.println(b("-bleen", 0));
    System.out.println(b("bleen", "bleen"));
    System.out.println(b(2, 2));
  }
}

Output:
1 2 3 4 5 6 bleen 7 8 9 10
-9 -8 -7 -bleen -6 -5 -4
-8 -7 -bleen -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 bleen
1 2 3 4 5 6 bleen 7 8 9
-bleen -6 -5 -4 -3 -2 -1 0 1 2
-bleen -6 -5 -4 -3 -2 -1 0
bleen
2

Scala, 223 bytes
object B extends App{val b="bleen"
val L=((-10 to -7)++List(s"-$b")++(-6 to 6)++List(b)++(6 to 10)).map(""+_)
val Array(s,e)=args.map(L.indexOf(_))
println((if(s<=e)L.slice(s,e+1)else L.slice(e,s+1).reverse).mkString(" "))}

JavaScript (ES6), 178 bytes
 (s,e)=>{q='bleen';t=[];for(i=-10;i<11;i++)t.push(i);t.splice(4,0,'-'+q);t.splice(18,0,q);s=t.indexOf(s);e=t.indexOf(e);s>e&&t.reverse()&&(e=22-e)&&(s=22-s);return t.slice(s,e+1)}

Try it
EDIT: Fix for reverse ordering.Thanks Patrick, missed this condition

R,  110 107 bytes
Thanks to Cyoce for golfing 3 bytes.
a=function(x,y){e=c(-10:-7,"-bleen",-6:6,"bleen",6:10)
b=function(d)which(e==as.character(d))
e[b(x):b(y)]}

Builds the whole list in order, picks out the relevant ones. Function in the middle named "b" seemed the easiest way to make that happen. Apply,etc

Is all that whitespace required?

No, and usually I wouldn't have had it. Thanks! Edit: I didn't even count much of it. Must have been half asleep.

Javascript (using external library) (343 bytes)
(a,b)=>{r="bleen";s="-"+r;c=d=>d==r?7:(d==s?-7:d);i=c(a);j=c(b);m=Math.min(i,j);n=Math.max(i,j);w=i<=j?_.RangeTo(i,j):_.RangeDown(i,Math.abs(j-i)+1);g=i<j?6:7;if(n>-7&&m<-6){w=w.InsertWhere("-bleen",x=>x==-7)}if(m<8&&n>6){w=w.InsertWhere("bleen",x=>x==g)}if(a==r||b==r){w=w.Where(x=>x!=7)}if(a==s||b==s){w=w.Where(x=>x!=-7)}return w.ToArray()}

Link to lib: https://github.com/mvegh1/Enumerable
Screenshot:

Python 2, 100 bytes
The first four lines generate the list [-10, -9, -8, -7, 'bleen', -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 'bleen', 7, 8, 9, 10]. The next line gets input and stores it in s and e. The last two lines use .index() and list slicing notation to get the correct range.
a=range(-10,11)
b="bleen"
c=a.insert
c(17,b)
c(4,b)
s,e=eval(input())
d=a.index
print a[d(s):d(e)+1]

Works in the same way as Leaky Nun's answer but developed independently. Stole an input method from orlp.
Ungolfed:
array = range(-10, 11)
array.insert(17, "bleen")
array.insert(4, "bleen")
start, end = eval(input())
print array[array.index(start):array.index(end) + 1]

This is incorrect - the number between -7 and -6 is -bleen, not bleen. Though we have found a new number, the basic rules of algebra must remain constant: 0 is the only number that is its own additive inverse, by virtue of being the additive identity element. Furthermore, eval(input()) is just input() in Python 2.

@Mego oh, oops....

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


text:
Hofstadter H-sequence
Definition

\$a(0) = 0\$
\$a(n) = n-a(a(a(n-1)))\$ for integer \$n > 0\$

Task
Given non-negative integer \$n\$, output \$a(n)\$.
Testcases
n     a(n)
0     0
1     1
2     1
3     2
4     3
5     4
6     4
7     5
8     5
9     6
10    7
11    7
12    8
13    9
14    10
15    10
16    11
17    12
18    13
19    13
20    14
10000 6823

References

WolframMathWorld
OEIS A005374

Related challenges about Hofstadter sequences: 1, 2, 3

And I still think you should reference GEB...

How is [tag:number-theory] relevant here?

@flawr facepalm  Let me try that again: Gödel, Escher, Bach: An Eternal Golden Braid

@StigHemmer Actually facepalm has its own Emoji now:

Haskell, 23 22 bytes
f 0=0
f n=n-f(f$f$n-1)

Simply uses the definition of the sequence. f(f$f$n-1) is equivalent to f (f (f (n-1))).
Test:
main = putStrLn . show $ map f [0..20]
-- => [0,1,1,2,3,4,4,5,5,6,7,7,8,9,10,10,11,12,13,13,14]

Thanks to Anders Kaseorg for a byte!

(f$f$f$n-1) = f(f$f$n-1) saves a byte.

Jelly, 8 bytes
’ßßßạµṠ¡

Try it online! or verify the smaller test cases.
How it works
’ßßßạµṠ¡  Main link. Argument: n

     µṠ¡  Execute the preceding chain sign(n) times.
’         Decrement n, yielding n - 1.
 ßßß      Recursively call the main link thrice.
    ạ     Take the absolute difference of n and the result.

Can the Jelly parser even handle programs larger than 10 bytes?

J, 14 12 bytes
-$:^:3@<:^:*

Saved 2 bytes thanks to @Leaky Nun.
Computes the result by calling itself recursively when n > 0 three times on n-1 and subtracting that result from n. There is a different situation for the base case when n = 0. There it computes n-n which equals 0.
a(n) = n - n = 0           if n = 0
       n - a(a(a(n-1)))    if n > 0

Try it here.
Explanation
-$:^:3@<:^:*  Input: n
           *  Get the sign of n (n = 0 => 0, n > 0 => 1)
         ^:   Execute that many times
                (0 times means it will just be an identity function)
       <:       Decrement n
 $:             Call itself recursively
   ^:3          three times
      @         on n-1
-             Subtract that result from n and return

I don't think the parentheses are needed.

Mathematica, 20 bytes
Byte count assumes ISO 8859-1 (or compatible) encoding and $CharacterEncoding set to a matching value, like the Windows default WindowsANSI.
±0=0
±n_:=n-±±±(n-1)

This defines a unary operator ±.

Would you explain what ± does or how it works?  Btw, congrats on 100k.

@DavidC Thanks. :) It's just a built-in operator which is shorthand for the unused function PlusMinus. See this post for details.

Very interesting. Dispenses with the @ or [ ] too.

Julia, 16 bytes
!n=n>0&&n-!!!~-n

Try it online!
How it works
We redefine the unary operator ! for our purposes.
If n = 0, the comparison n>0 returns false and so does !.
Otherwise, the code after && gets executed. ~-n is equivalent to (n-1) in two's complement, !!! recursively calls ! thrice on n - 1, and the resulting value is subtracted from n.

Mind adding an explanation? I have no idea what is going on with -!!~- ._.

Nothing fancy. ! is simply the function's name.

Python, 31 bytes
a=lambda n:n and n-a(a(a(n-1)))

Recursion limit and time constraints make above function impractical, but in theory it should work (and does work for small n).

JavaScript (ES6), 52 bytes
n=>[0,...Array(n)].reduce((p,_,i,a)=>a[i]=i-a[a[p]])

I could have been boring and written the recursive version but this version is much faster (easily coping with the last test case) and also uses reduce so that's a plus!

Retina, 49 43 bytes
.+
$*1:
{`^1(1*):
$1:::-1$1
}`^:*(1*)-\1

1

Try it online!

CJam, 13 12 bytes
Thanks to Dennis for saving 1 byte.
ri0{_(jjj-}j

Test it here.

That works for surprisingly high values. I think you don't need the a.

@Dennis Oh, that's good to know, thanks.

R, 42 41 bytes
a=function(n)ifelse(n<1,0,n-a(a(a(n-1))))

Usage:
> a(1)
1
> a(10)
7

This recursive approach doesn't scale well for larger values of n though.

You should be able to lose a byte (and a number of errors w/ bad inputs) if you change your condition to n<1. As its a sequence, it is only really defined for non-negative integers anyhow.

a=function(n)"if"(n,n-a(a(a(n-1))),0) will work for several bytes off.

Oasis, 6 bytes
Code:
nbaa-0

Expanded version:
a(n) = nbaa-
a(0) = 0

Code:
n      # Push n
 b     # Calculate a(n - 1)
  a    # Calculate a(a(n - 1))
   a   # Calculate a(a(a(n - 1)))
    -  # Subtract a(a(a(n - 1))) from n

Try it online!

APL (Dyalog Unicode), 18 17 bytes
{⍵=0:0⋄⍵-∇⍣3⊢⍵-1}

Try it online!
Surprisingly, there's no APL answer to this challenge. This is a literal implementation of the function in the OP.
TIO times out for \$n>90\$.
Saved a byte thanks to @Zacharý.

{⍵=0:0⋄⍵-∇⍣3⊢⍵-1}

{×⍵:⍵-∇⍣3⊢⍵-1⋄0} for 16.

Sesos, 58 55 bytes
0000000: 16e0d7 bdcdf8 8cdf1b e6cfbb 840d3f bf659b 38e187  ..............?.e.8..
0000015: f8639b 39dc37 fc893f 666c05 7e7ed9 b88b3f ae0d3f  .c.9.7..?fl.~~...?..?
000002a: 676ed8 bd9940 7fdc3b 36619e f1                    gn...@..;6a..

Handles inputs up to 400 reasonably well, but run time increases dramatically after that point.
Try it online! Check Debug to see the generated SBIN code.
Sesos assembly
The binary file above has been generated by assembling the following SASM code.
set numin, set numout

get
jmp
    jmp
        rwd 3, add 1, rwd 1, add 1, fwd 4, sub 1
    jnz
    rwd 3, sub 1
jnz
rwd 3, add 1, fwd 2
jmp
    rwd 1, sub 1, fwd 3, sub 1, fwd 2, add 3
    jmp
        rwd 2
        jmp
            rwd 3
        jnz
        fwd 6, get, rwd 4, sub 1
        jmp
            fwd 1, sub 1
            jmp
                rwd 3
            jnz
            sub 1
            jmp
                fwd 3
            jnz
            rwd 4, sub 1
        jnz
        fwd 1
        jmp
            rwd 1, add 1, fwd 1, add 1
        jnz
        sub 1, fwd 3, sub 1
        jmp
            fwd 3
        jnz
        rwd 1, sub 1
    jnz
    rwd 2, get
    nop
        rwd 3
    jnz
    fwd 3, get, rwd 2
    jmp
        fwd 2, add 1
        jmp
            fwd 3
        jnz
        rwd 1, add 1, rwd 2
        jmp
            rwd 3
        jnz
        fwd 1, sub 1
    jnz
    fwd 2
    jmp
        rwd 2, add 1, fwd 2, sub 1
    jnz
    nop
        get, fwd 3
    jnz
    rwd 1, add 1, fwd 2
jnz
rwd 2, sub 1
jmp
    rwd 1, sub 1, fwd 1, sub 1
jnz
rwd 1, put

LISP, 61 bytes
(defun H(N)(if(= N 0)(return-from H 0)(- N(H(H(H(- N 1)))))))

Probably not the optimal solution, but it works.

C, 35 32 bytes
Saved 3 bytes thanks to @PeterTaylor!
a(n){return n?n-a(a(a(n-1))):0;}

Try it on Ideone!

In C you can use an integer directly as a conditional, giving a three-byte saving: a(n){return n?n-a(a(a(n-1))):0;}

@betseg - You have an erroneous : in your code too. You should take out the one after ?.

Java 7, 42 bytes
int c(int n){return n>0?n-c(c(c(n-1))):0;}

Ungolfed & test cases:
Try it here.
class Main{
  static int c(int n){
    return n > 0
              ? n - c(c(c(n-1)))
              : 0;
  }

  public static void main(String[] a){
    for(int i = 0; i < 21; i++){
      System.out.println(i + ": " + c(i));
    }
    System.out.println("1000: " + c(1000));
  }
}

Output:
0: 0
1: 1
2: 1
3: 2
4: 3
5: 4
6: 4
7: 5
8: 5
9: 6
10: 7
11: 7
12: 8
13: 9
14: 10
15: 10
16: 11
17: 12
18: 13
19: 13
20: 14
 (last case takes too long..)

Ruby, 27 bytes
The obvious implementation.
a=->n{n<1?0:n-a[a[a[n-1]]]}

This is a longer, faster answer that caches previous entries in the sequence.
Both answers only work for versions after 1.9, as that was when ->, the stabby lambda, was introduced to Ruby.
->n{r=[0];i=0;(i+=1;r<<i-r[r[r[i-1]]])while i<n;r[n]}

C#, 35 bytes
int a(int n)=>n>0?n-a(a(a(n-1))):0;

Golfscript, 26 25 bytes

~[0]{....,(===\.,@-+}@*)\;
~[0]{...)\;==\.,@-+}@*)\;

Try it online!
Locally 10000 takes less than half a second.

Maple, 28 26 bytes
`if`(n=0,0,n-a(a(a(n-1))))

Usage:
> a:=n->ifelse(n=0,0,n-a(a(a(n-1))));
> seq(a(i),i=0..10);
0, 1, 1, 2, 3, 4, 4, 5, 5, 6, 7

Javascript ES6, 22 bytes
a=n=>n&&n-a(a(a(n-1)))

I'll be boring and do the recursive version :P

VBA, 69 bytes
Function H(N):ReDim G(N):For j=1To N:G(j)=j-G(G(G(j-1))):Next:H=G(N)

Works in the blink of an eye on the test set, slows down a little above n=1000000, runs into a memory wall a little above n=25 million.

Pyth, 10 bytes
L-WbbyFtb3

Defines a function y. Try it online: Demonstration
This uses a relative new feature of Pyth. You can apply a function multiple times using the fold-syntax. It doesn't actually save any bytes, I used it just for demonstration purposes.
Explanation:
L-WbbyFtb3
L            define function y(b), that returns:
    b           b
 -Wb            and subtract the following if b>0
     yF  3      y applied three times to
       tb       b - 1

dc, 34 bytes
dsn[zdddd1-;a;a;a-r:aln!=L]dsLx;ap

Input is taken from the top of the stack. This must be the only item on the stack, because the stack depth is used as a counter. Example of usage:
$ dc
10000dsn[zdddd1-;a;a;a-r:aln!=L]dsLx;ap

This is a fairly straightforward implementation of the sequence definition:
dsn               # Store n as `n', and keep a copy as a depth buffer (see below)
[                 # Open loop definition
 z                # Push stack depth i for i-th term
 dddd             # Duplicate stack depth four times, for a total of five copies
 1-               # Get i-1 for use as index to previous term
                  #   Note that if we hadn't duplicated n above, or left something else
                  #   on the stack, 0-1 would be -1, which is not a valid array index
 ;a;a;a           # Fetch a(a(a(i-1)))
 -                # Calculate i-a(a(a(i-1)))
 r                # Arrange stack to store i-th term: TOS |  i  (i-a(a(a(i-1))))
 :a               # Store i-th term in array `a'
 ln!=L            # Load n. If n!=i, we're not done calculating terms yet, so execute loop
]                 # Close loop definition. Note that we started with five copies of i:
                  #   i-1 was used to get last term
                  #   i-a(...) was used to calculate current term
                  #   ... i :a was used to store current term
                  #   i ln !=L was used to check loop exit condition
                  # One copy of i is left on the stack to increment counter
dsLx              # Duplicate loop macro, store it, and execute copy
;a                # Last i stored on stack from loop will equal n, so use this to get a(n)
p                 # Print a(n)

Anyways, it started out straightforward...then the golfing happened.

Common Lisp, 44 bytes
(defun f(x)(if(= x 0)0(- x(f(f(f(1- x)))))))

Try it online!

C++ ( MSVC, mainly )
Normal version : 40 bytes
int a(int n){return n?n-a(a(a(n-1))):0;}

Template meta programming version : 130 bytes
#define C {constexpr static int a(){return
template<int N>struct H C N-H<H<H<N-1>::a()>::a()>::a();}};template<>struct H<0>C 0;}};

Usage :
std::cout << a(20) << '\n';       // Normal version
std::cout << H<20>::a() << '\n';  // Template version

The template version is the fastest code, since there's nothing faster than moving a value into a register => with optimization, H<20>::a() compile as :
mov esi, 14

For 10000, the recursive version crashes due to a stack overflow error, and the template version crashes at compile time due to template instantiation depth. GCC goes to 900 ( 614 )

I think you don't need the space between C and { in the template meta programming version

@Zacharý MSVC refuses to compile without that space

Ahh, I see now why that seems to keep happening

@Zacharý It depends on the type of macro. If it has parameters, then i can remove the space, but here it doesn't

Japt, 7 bytes
©aßßßUÉ

Try it or run all test cases (throws an overflow error for 10000)

D, 36 bytes
T a(T)(T n){return n?n---n.a.a.a:0;}

Try it online!

Python 3, 72 bytes
def f(n):
    a=[0];i=0
    while n:i+=1;a+=[i-a[a[a[i-i]]]];n-=1
    return a[i]

Ideone it!

PowerShell v2+, 56 bytes
$a={$n=$args[0];if($n){$n-(&$a(&$a(&$a($n-1))))}else{0}}

The PowerShell equivalent of a lambda to form the recursive definition. Execute it via the & call operator, e.g. &$a(5). Takes a long time to execute -- even 50 on my machine (a recent i5 with 8GB RAM) takes around 90 seconds.
Faster iterative solution, 59 bytes
param($n)$o=,0;1..$n|%{$o+=$_-$o[$o[$o[$_-1]]]};$o[-1]*!!$n

Longer only because we need to account for input 0 (that's the *!!$n at the end). Otherwise we just iteratively construct the array up to $n, adding a new element each time, and output the last one at the end $o[-1]. Super-speedy -- calculating 10000 on my machine takes about 5 seconds.

><>, 55+2 = 57 bytes
^~n;
.~-]{:0$
v>1-}32[
v/  /:1-32[
>$:?/$~]{:0$.
/30@2[

The input is expected to be present on the stack at program start, so +2 bytes for the -v flag. Try it online!
This is hecka slow, as it uses recursion to calculate the result. Using TIO, h(50) takes over a minute. It returns the correct results <= 30, so I'm confident it would work for h(10000), I just haven't run it to find out!

RETURN, 17 bytes
[$[$1-aaa-][]?]=a

Try it here!
Recursive operator that leaves result on the stack. Example usage:
[$[$1-aaa-][]?]=a 4a

Python 2, 54 53 bytes
a=r,=0,
exec'r=len(a)-a[a[r]];a+=r,;'*input()
print r

Not even close to the recursive solution, but at least it's fast.
Test it on Ideone.

C#, 156 bytes
Mine is going to be a bit longer than the other C# answer, but my version can compute up to 10,000 (and higher) without a stack overflow, and can do all integers from 0 to 10,000 in a fraction of a second due to addition of a dictionary.  Most of the answers here can take hours to do integers in the thousands, so my extra bytes also lead to massive speed increases.
Golfed
Dictionary<int,int> l=new Dictionary<int,int>();int H(int n){int v;if(n==0)return 0;if(l.TryGetValue(n,out v)){}else{v=n-H(H(H(n-1)));l.Add(n,v);}return v;}

Ungolfed (with test program)
using System;
using System.Collections.Generic;

namespace HH
{
    class Program
    {
        static Dictionary<int, int> l = new Dictionary<int, int>();

        static int H(int n)
        {
            int v;
            if (n == 0)
                return 0;
            if (l.TryGetValue(n, out v))
            { }
            else
            {
                v = n - H(H(H(n - 1)));
                l.Add(n, v);
            }
            return v;
        }

        static void Main(string[] args)
        {
            for(int i = 0; i <= 10000; i++)
                Console.WriteLine("{0}: {1}", i, H(i));
            Console.ReadLine();
        }
    }
}

Edit: The other C# answer can't compute H(10,000) without a stack overflow, mine can print all numbers from H(1) to H(1,000,000) in a few seconds.  H(1,000,000) is 682,328 if anyone was wondering :P

Clojure, 44 42 bytes
(fn f[n](if(= 0 n)0(- n(f(f(f(dec n)))))))

So sad this is sorter than (fn f[n](if(= 0 n)0(- n((comp f f f dec)n)))).

Pyth, 11 bytes
L?b-byyytb0

Try it online!
The program defines a lambda function.
The link adds yQ for I/O

Brachylog, 11 bytes
0|-₁↰↰↰-↙?ȧ

Try it online!
10000 times out and I've not yet been able to verify it, nor do I expect to.
0|             The input and output are 0, or the input
  -₁           minus 1
    ↰          passed through this same predicate
     ↰         passed through this same predicate
      ↰        passed through this same predicate
       -↙?     minus the input
          ȧ    has an absolute value equal to the output.

GolfScript, 21 bytes
~{.{.(a a a-}{}if}:a~

Try it online!
~                      # Parse input to a number
 {               }:a   # Assign this function to the variable a
  .                    # Copy the number
   {        }{}if      # If it is bigger than 0 execute the first block, if it is 0 execute the second
    .(                 # Copy the number and decrement
      a a a            # a(a(a( n-1 )))
           -           # Subtract from the original number
                    ~  # Execute a

If the number is 0 nothing happens because there is already a 0 on top of the stack and we use that as the answer.

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


text:
Tips for golfing in Cheddar

Cheddar is a high-level, functional + object-oriented programming language created by our user Downgoat designed to make programming easier, faster, and more intuitive.
What general tips do you have for golfing in Cheddar? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Cheddar (e.g. "Remove unnecessary whitespace." is not an answer).

Use Functionized Properties

If you ever use just a property in a function:
A->A.long.property(n).foo.bar

You can use functionized properties to save some bytes:
@.long.property(n).foo.bar

You can reference the variable in the functionized property with $0.

Use the String Operator for string sequences
I'm talking about the @" operator which does different things, all of which deal with strings. This has quite a bit of uses but this is one of my favorite uses:
Take a look at this:
@" [103, 111, 97, 116, 115] === "goats"

not that useful but the opposite is:
@"'goats' === [103, 111, 97, 116, 115]
'goats'.bytes // compare the above too

This is especially useful to generate the alphabet:
65@"90    // Uppercase Alphabet
97@"122   // Lowercase Alphabet
65@"90+97@"122 // Both cases
String.letters // Compare 97@"122 to this

Curry
No not red curry (what other curry would you be thinking about ¬_¬). I mean this type of curry:
a->b->

If you have a function taking two arguments. It's shorter to curry than to not:
(a,b)->
a->b->

Note: This is only shorter when you have exactly two arguments.

Use default arguments
Declaring Cheddar variables can be quite the byte-waster:
->{var a=b+1}

luckily, you can (ab)use function default values for creating variables:
b=a+1->b

Here are some examples of uses:
let f= (a,b=a+1)->b
f(5) // 6

let f= a=Math.rand()->a
f() // 0.8757450950797647

Use Functionized Operators and Bonding
This is a simple one. If you have anything like:
i->1+i

or any similar operation. You can shorten using functionized operators + bonding:
1&(+)

Use the mapping operator
The => maps LHS to RHS, due to it's precedence, this also means you can use it with ranges and use it multiple times:
a=>f
(a).map(f)

Additionally:
a=>f=>g           // This is equivilant to...
(a).map(f).map(g) // this


text:
Integers, Assemble!
Your task is to assemble the integers from 1 to N (given as input) into a rectangle of width W and height H (also given as input). Individual numbers may be rotated by any multiple of 90 degrees, but they must appear as contiguous blocks in the rectangle. That is, you cannot break one of the numbers into multiple digits and place the digits in the rectangle individually, neither can you bend three digits of a number around a corner. You could consider each number a brick from which you're building a wall.
Here is an example. Say your input is (N, W, H) = (12, 5, 3). One possible solution is:
18627
21901
53114

For clarity, here are two copies of this grid, one with the one-digit numbers hidden and one with the two-digit numbers hidden:
1####    #8627
2##01    #19##
##11#    53##4

It's fine if the rectangle cannot be disassembled again in a unique way. For instance, in the above example, the 12 could also have been placed like this:
#####    18627
21#01    ##9##
##11#    53##4

Rules
You may assume that N is positive and that W*H matches the number of digits in the integers from 1 to N inclusive, and that a tiling of the rectangle into the given numbers exists. I don't currently have a proof whether this is always possible, but I'd be interested in one if you do.
Output may either be a single linefeed-separated string or a list of strings (one for each line) or a list of lists of single-digit integers (one for each cell).
The results of your submission must be determinstic and you should be able to handle all test cases in less than a minute on reasonable desktop machine.
You may write a program or a function and use any of the our standard methods of receiving input and providing output.
You may use any programming language, but note that these loopholes are forbidden by default.
This is code-golf, so the shortest valid answer – measured in bytes – wins.
Test Cases
Except for the first one, none of these are unique. Each test case is N W H followed by a possible output. Make sure that your answer works when the rectangle is too narrow to write the larger numbers horizontally.
1 1 1
1

6 6 1
536142

6 2 3
16
25
34

10 1 11
1
0
8
9
2
6
7
3
1
5
4

11 13 1
1234567891011

27 9 5
213112117
192422581
144136119
082512671
205263272

183 21 21
183116214112099785736
182516114011998775635
181116013911897765534
180415913811796755433
179115813711695745332
178315713611594735231
177115613511493725130
176215513411392715029
175115413311291704928
174115313211190694827
173115213111089684726
172015113010988674625
171915012910887664524
170814912810786654423
169714812710685644322
168614712610584634221
167514612510483624120
166414512410382614019
165314412310281603918
164214312210180593817
163114212110079583716

200 41 12
81711132917193661114105533118936111184136
50592924448815915414562967609909953662491
89529721161671582389717813151113658811817
41418184511110119010183423720433017331118
35171183614003547461181197275184300111711
41874381132041861871718311415915921116264
11914245014112711011594492626831219331845
17125112629222085166344707736090956375181
94507611291431121128817413566319161275711
11011540021119913511011169939551729880780
92725141607727665632702567369893534277304
78118311405621148296417218591118562161856

Is there a proof that this is always possible?

@Fatalize Good question actually. You can assume it's possible for all given inputs, but a proof either way would be interesting.

@Fatalize: At least in the trivial case of input (10, 1, 1), it's not possible (assuming that all numbers from 1 to N MUST be used in the construction). If that constraint is held, the area of the rectangle in units must be at least the number of digits in 1..N in order to make it possible. If that constraint is relaxed, it's possible in all cases (but then the challenge isn't much fun :P)

@SebastianLenartowicz: I think you missed the part where it says the area of the rectangle matches the sum of the digits of the numbers in [1,N]. If N == 10, then width and height have to be 1 and 11. If the width or height is 1, this problem is always solvable.

@MartinEnder Some test cases to add: (100,2,96); (99,3,63); (183,21,21) (And their transpositions)

Helpful tool for creating test cases

@MartinEnder The opposite challenge could be interesting too : a rectange of digits as input (and eventually N, but the program could calculate it from the width and height), and the program needs to check if the rectangle is a valide answer to this challenge....

@Dada Well, that was actually my original challenge idea but I ended up deciding to post this direction, because I wasn't sure whether there would be any feasible non-brute force solutions to the other one.

Pyth, 35 bytes
juum+WghHl+dQd~tQN<+.TGmkeHeH)_BvzY

Credits to mbomb007. I used his algorithm.
Originally I only wanted to help Steven H., but then I really wanted to see a short version.
Takes N on the first line, and W,H on the second line: Try it online: Demonstration
Found a nasty bug in the Pyth implementation of .[ (my own fault, since I implemented it). Gotta fix it tomorrow. This resulted in +3 bytes.
Explanation:
juum+WghHl+dQd~tQN<+.TGmkeHeH)_BvzY
                                  Y   start with the empty list []
                                      I'll perform all operations on this list.
                                      Sometimes it is called G, sometimes N.
                                vz    read the second line and evaluate it: [W, H]
                              _B      bifurcate it with reverse: [[W, H], [H, W]]
 u                                    for each pair H in ^:
                    .TG                  transpose G
                   +   mkeH              append H[1] empty strings
                  <        eH            use only the first H[1] strings
                                         lets call this result N
  u                          )           modify N, until it doesn't change anymore:
   m                        N               map each d in N to:
     WghHl+dQ                                  if H[0] >= len(d+Q):
    +        d  Q                                 d + Q
              ~t                                  and decrement Q by 1
             d                                 else:
                                                  d
j                                     at the end print every row on a separate line

Python 2, 210 200 bytes
Edit: Works now!
Fills from top to bottom, left to right, starting with the largest numbers. Then, transpose and do it again. Then transpose and print. I had to pad with spaces for the transposition to work, since the lines aren't to their full length yet.
I had trouble getting a nested exec working (to do exec'exec"..."*w\n;...'*2. If someone can figure it out, let me know.
n,w,h=input()
s=[""]*h
for x in 1,2:
    exec"for i in range(h):l=len(s[i]+`n`)<=w;s[i]+=`n`*l;n-=l\n"*w;s=[r.replace(" ","")for r in map(lambda x:`x`[2::5],zip(*[r.ljust(w)for r in s]))];w,h=h,w
print s

Try it online - Uses a modified function so it can run multiple test cases more easily (and it couldn't use exec). Uncomment the other version and modify stdin to see it run.
Less golfed:
def f(n,w,h):
    s=[""]*h
    for x in 1,2:
        for j in[0]*w:
            for i in range(h):
                l=len(s[i]+`n`)<=w
                s[i]+=`n`*l
                n-=l
        s=[r.ljust(w)for r in s]
        s=map(lambda x:`x`[2::5],zip(*s))
        s=[r.replace(' ','')for r in s]
        w,h=h,w
    print"\n".join(s)

It's very likely that this should work for all cases now, but an (informal) proof would still be appreciated. ;)

@MartinEnder A proof is probably beyond me. For the numbers to vary more in length, the test cases get very large. It's probably related to or the same as the proof of whether there is always a solution.

JavaScript, 284 259 245 241 240 223 209 205 bytes

// Golfed
let f = (N,W,H)=>eval('a=Array(H).fill("");while(N)g:{s=""+N--;d=s[L="length"];for(i in a)if(a[i][L]+d<=W){a[i]+=s;break g}for(p=0;d;++p){l=a[p][L];for(k=p+d;k>p;)l=a[--k][L]-l?W:l;while(l<W&&d)a[p+--d]+=s[d]}}a');

// Ungolfed
(N,W,H) => {
    a = Array(H).fill(""); // Create `H` empty rows.

    while (N) g : {
        s = "" + N--; // Convert the number to a string.
        d = s[L="length"]; // Count the digits in the number.

        // Loop through the rows trying to fit the number in horizontally.
        for (i in a) {
            if (a[i][L] + d <= W) { // If it fits.
                a[i] += s; // Append the number to the row.
                break g; // This is what a goto statement looks like in JavaScript.
            }
        }

        // Loop through the rows trying to fit the number in vertically.
        for (p = 0; d; ++p) {
            l = a[p][L]; // Get the length of the row.

            // Find `d` adjacent rows of the same length.
            for (k = p + d; k > p; ) {
                // If `a[--k][L] == l`, continue.
                // Else set `l` to `W` so the next loop doesn't run.
                l = a[--k][L] - l ? W : l;
            }

            // Put the characters in position.
            while (l < W && d)
                a[p+--d] += s[d];
        }
    }

    return a;
}

let test_data = [[1,1,1],
                 [6,6,1],
                 [6,2,3],
                 [10,1,11],
                 [10,11,1],
                 [11,13,1],
                 [27,9,5],
                 [183,21,21],
                 [184,2,222],
                 [200,41,12],
                 [1003,83,35]];

for (let test of test_data)
    console.log(f(test[0],test[1],test[2]));

Save 1 byte by using - instead of != to test whether two numbers are different.

Pyth, 79 50  48 Bytes
Noncompeting until I work out bugs (for example, [6,6,1] returns the same as [6,1,6]).    It's my first time trying to use Pyth, so I'm probably missing a lot of features.
Thanks to Jakube, saved 29 bytes and made my code actually work!
Saved another two byte by realizing that the repr() calls were unnecessary.
It's basically just a translation of mbomb007's Python 2 answer.
AEJmkHFb2VHVGIgGl+@JNQ XNJ~tQ)))=.[.TJkGA,HG)jJ

Takes input in the form of
n
w,h.

Answers should be deleted until they are a valid solution.

I think most of the code is correct. The only error I see happens during the transposition. mbomb007 transposes by carefully filling up the remaining columns with spaces, then zips and removes the spaces. This guarentees. that the after transposing the matrix has w length. =.TZ can't guarantee that, since it doesn't know the length w.

Actually the main error is, that !>+@ZN`zK should be !>+@ZN`zJ. Then all the small test cases work. But you can create test-cases, where the transposing fails (like described above). For this to work you need something like =.[.TZkK (fill the missing columns with empty strings) instead of =.TZ.

And try to not confuse yourself with Pyth. In your code you have two multiple variable that point to the same values (like K and @Q1). It was quite hard to track which variable is which value, ... And don't just copy the code. Keep it simple. The boolean trick =Y... may be a good idea for Python, but a simple I (if) would be much more readable (and also shorter).

Here's a really simple solution using mbomb007's code: Link It takes n on the first line (this way we don't have to assign the value to an extra variable, we can simply use Q). And w and h on the second line, which get immediately assigned to G and H with AE.

@Jakube Do you want to post that as your own solution?  It's quite removed from mine, and I'd feel kind of bad by replacing what I have by your code without you getting any rep for it.

@StevenH.Actually you can post it if you want. I won't. Simply because I didn't come up with the algorithm myself. Also the solution is still not really golfed. It's only a concise translation. I think you can still save a quite a few bytes. For instance by using u (reduce) instead of the for loops. But then you would need to change the algorithm a little bit.

@StevenH. O.k. I took the challenge of golfing the solution a little bit more. Still using the same algorithm: http://codegolf.stackexchange.com/a/88808/29577

Stax, 27 bytes
é!L↑?∞S░♠╔)¥¼/ÿµ◄÷│♦╫Δò6√√╣

Run and debug it
It takes input on one line in the for {N} {H} {W}.
This program starts with a grid of spaces of the specified size.  For each number from N .. 1, it attempts to do a single string replacement from a string of spaces of the appropriate size to the formatted number.  If no replacement can be performed, then it tries again with a transposed grid.
z)A+*   create "grid" of spaces and newlines of specified size
,Rr     create range [n ... 1]
F       for each number execute the indented section; it will fit the value into the grid
  $%z(  make a string out of spaces the same length as the number; e.g. 245 => "   "
  Y     store the space string in register Y; this will be used as a search substring
  [#    count the number of occurrences of y in the grid; the grid is still on the stack
  X     store the count in register X; this will be used as a condition
  G     jump to routine at closing curly brace
  y_$|e replace the first instance of y (the spaces) with the current number
  xG    push x; then jump to routine at closing curly brace
        end program
}       called routine jump target
C       pop top of stack; if it's truthy terminate routine
|jM|J   split on newlines; transpose; join with newlines

Run this one

Pip, 59 bytes
Oy, Pip can be verbose for a golfing language sometimes...
YsXbRLcJnWa{T` `X#a~yx:Y(t:{J*Z:a^n}Jny)Y$`.a.$'--a}x?(ty)y

Try it online!
Ungolfed
Approach: store the grid as a newline-separated string, using regex to replace a run of spaces with the current number, and transposing if there isn't a run of spaces long enough.
; Command-line arguments are: a (the number), b (the width), c (the height)
; x is "", a falsey value

; Set up the initial string:
;  sXb  String of b spaces
;  RLc  Make a list of c of those
;  Jn   Join on newline
Y sXb RL c J n

; Define a function t that transposes a newline-separated string:
;  a^n  Split argument on newlines
;  Z    Zip (transposes, but results in a list of lists of characters)
;  J*   Join each of the sublists into a string
;  Jn   Join those strings on newline
t: {(J* Z (a^n)) J n}

; Loop while a is nonzero:
W a {

  ; Loop till a regex made of len(a) spaces matches in y:
  T y ~ ` `X#a

    ; Transpose y and set x to a truthy value to indicate that we've transposed it:
    ;  (t y)  Call the t function on y
    ;  Y      Assign the result back to y
    ;  x:     Assign it to x also
    x: Y (ty)

  ; When we break out of the loop, we have matched the first run of len(a) spaces
  ; in y; now we want to replace that with the number a:
  ;  $`   The part of the string before the match
  ;  .a   Concatenated to a
  ;  .$'  Concatenated to the part of the string after the match
  ;  Y    Assign that to y
  Y $`.a.$'

  ; Decrement a
  --a
}

; After the main loop, we need to transpose y back if we transposed it:
;  x?     Is x truthy?
;  (t y)  If so, transpose y
;  y      If not, return y as-is
x ? (ty) y

; The result is autoprinted.


text:
Szekeres's sequence
Definition

\$a(1) = 1\$
\$a(2) = 2\$
\$a(n)\$ is smallest number \$k>a(n-1)\$ which avoids any 3-term arithmetic progression in \$a(1), a(2), ..., a(n-1), k\$.
In other words, \$a(n)\$ is the smallest number \$k>a(n-1)\$ such that there does not exist \$x, y\$ where \$0<x<y<n\$ and \$a(y)-a(x) = k-a(y)\$.

Worked out example
For \$n=5\$:
We have \$a(1), a(2), a(3), a(4) = 1, 2, 4, 5\$
If \$a(5)=6\$, then \$2, 4, 6\$ form an arithmetic progression.
If \$a(5)=7\$, then \$1, 4, 7\$ form an arithmetic progression.
If \$a(5)=8\$, then \$2, 5, 8\$ form an arithmetic progression.
If \$a(5)=9\$, then \$1, 5, 9\$ form an arithmetic progression.
If \$a(5)=10\$, no arithmetic progression can be found.
Therefore \$a(5)=10\$.
Task
Given \$n\$, output \$a(n)\$.
Specs

\$n\$ will be a positive integer.
You can use 0-indexed instead of 1-indexed, in which case \$n\$ can be \$0\$. Please state it in your answer if you are using 0-indexed.

Scoring
Since we are trying to avoid 3-term arithmetic progression, and 3 is a small number, your code should be as small (i.e. short) as possible, in terms of byte-count.
Testcases
The testcases are 1-indexed. You can use 0-indexed, but please specify it in your answer if you do so.
1     1
2     2
3     4
4     5
5     10
6     11
7     13
8     14
9     28
10    29
11    31
12    32
13    37
14    38
15    40
16    41
17    82
18    83
19    85
20    86
10000 1679657

References

WolframMathWorld
OEIS A003278

Related. (If I understand your challenge correctly.)

@MartinEnder You did understand my challenge correctly.

Jelly, 4 bytes
Bḅ3‘

Try it online! or verify all test cases.
How it works
This uses 0-based indexing and the primary definition from OEIS:

Szekeres's sequence: a(n)-1 in ternary = n-1 in binary

Bḅ3‘  Main link. Argument: n

B     Convert n to binary.
 ḅ3   Convert from ternary to integer.
   ‘  Increment the result.

Haskell, 37 36 32 bytes
Using the given formula in the OEIS entry, using 0-based indices. Thanks @nimi for 4 bytes!
a 0=1;a m=3*a(div m 2)-2+mod m 2

Python 3, 28 bytes
lambda n:int(bin(n)[2:],3)+1

An anonymous function that takes input via argument and returns the result. This is zero-indexed.
How it works
lambda n    Anonymous function with input zero-indexed term index n
bin(n)      Convert n to a binary string..
...[2:]     ...remove `0b` from beginning...
int(...,3)  ...convert from base-3 to decimal...
...+1       ...increment...
:...        and return

Try it on Ideone

Python 3, 113 bytes
def f(n):
 i=1;a=[]
 for _ in range(n):
  while any(i+x in[y*2for y in a]for x in a):i+=1
  a+=[i]
 return a[n-1]

Ideone it!

Ruby, 28 24 bytes
Using the same method as Dennis, with 0-based indexes:
->n{n.to_s(2).to_i(3)+1}

Run the test cases on repl.it: https://repl.it/Cif8/1

Pyke, 5 bytes
b2b3h

Try it here!
0-based indexing
Same formula as jelly answer

APL (Dyalog Extended), 5 bytes
1+3⊥⊤

Try it online!
Jo King's suggestion.
APL (Dyalog Unicode), 12 bytes
1+3⊥2(⊥⍣¯1)⊢

Try it online!
Based on Dennis' Jelly answer.
Outputs are zero indexed.
1+3⊥2(⊥⍣¯1)⊢
           ⊢ Take argument
    2(⊥⍣¯1)  Encode in binary
  3⊥         Decode from ternary
1+           Add 1

With Dyalog Extended, this can be just 5 bytes! You can also save 2 bytes in Unicode

Java 7, 60 42 bytes
0 Indexed
int s(int n){return n<1?1:3*s(n/2)-2+n%2;}

Using the implicit sequence definition from OEIS.
Thanks to Kevin for the improvement using only one return statement.

Welcome to CGCC! :) You don't need the static , and you can also golf the if(n==0)return 1;return 3*s(n/2)-2+n%2; to return n<1?1:3*s(n/2)-2+n%s;. :) If you haven't seen it yet, tips for golfing in Java and tips for golfing in all languages might be interesting to read through. Enjoy your stay!

Java 8, 52 46 bytes
0 indexed.
i->Integer.valueOf(Integer.toString(i,2),3)+1;

You don't need the return but  you do need the semicolon afterwards

This answer that say semicolons aren't counted; I could change it either way, but is counting semicolons the consensus?

Eh, that's what they told me. I don't know if the consensus is as such.

Alrighty, no return plus semi-colon is shorter than before anyway :)

Pip, 11 bytes
1+(aTB2)FB3

Try it online!
Based on Dennis' Jelly answer. Zero Indexed.

Japt, 4 bytes
0-indexed
Ò¢n3

Try it or run all test cases from the OEIS entry
Same as most other solutions:
Ò¢n3     :Implicit input of integer U
Ò        :Negation the bitwise NOT of
 ¢       :U converted to a binary string
  n3     :Converted from a ternary string


text:
Simulate a sock drawer
Background
I have a collection of "weekday socks", which are seven pairs of socks labeled by the days of the week.
When I wash my socks, they end up in a pile, and I must arrange them into the correct pairs before putting them into the closet.
My strategy is to pull one random sock from the pile at a time and put it on a drawer.
Whenever there's a matching pair of socks on the drawer, I tie them together and put them in the closet.
Your task is to simulate this random process and return the number of draws required to find the first matching pair.
Input
Your input is an integer N ≥ 1.
It represents the "number of days in a week": there are N pairs of socks in the pile, and each pair has a distinct label.
If necessary, you may also take a PRNG seed as input.
Output
Your output is the number of socks I have to draw before the first matching pair is found.
For example, if the first two socks already form a matching pair, the output is 2.
Of course, the output is random, and depends on the drawing order.
We assume that all drawing orders are equally likely, so that each time a sock is drawn, the choice is uniform and independent from all other choices.
Example
Let N = 3, so that we have 6 socks in total, labeled A A B B C C.
One possible run of the "sock-drawing protocol" is as follows:
       | Pile   | Drawer | Pairs
Begin  | AABBCC | -      | -
Draw B | AABCC  | B      | -
Draw C | AABC   | BC     | -
Draw B | AAC    | C      | BB
Draw A | AC     | AC     | BB
Draw A | C      | C      | AA BB
Draw C | -      | -      | AA BB CC

The first matching pair was found after drawing the second B, which was the third sock to be drawn, so the correct output is 3.
Rules and scoring
You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.
Input and output can be in any reasonable format, including unary (string of 1s).
You may assume that your language's built-in RNG is perfect.
You don't have to actually simulate the sock-drawing protocol, as long as your outputs have the correct probability distribution.
"Test cases"
Here are the approximate probabilities of all outputs for the input N = 7:
Output       2     3     4     5     6     7     8
Probability  0.077 0.154 0.210 0.224 0.186 0.112 0.037

To test your solution, you can run it for, say, 40 000 times and see whether the output distribution is reasonably close to this.

Real Life, 42 bytes -- Draw all socks. End up with an odd number.

See How to pair socks from a pile efficiently?

So n=8 is not equal to 1->7 and then 1 again? i.e. 4 socks labeled 1

@ViktorMellgren No, you would have 8 distinct labels.

I have a drawer full of identical socks, so there is no need to sort through them.

In which universe "all drawing orders are equally likely" for socks? Not in ours, that's for sure!

Jelly, 8 bytes
ḤX€Ṛ<RTḢ

Try it online! or verify the distribution for N = 7.
Background
Let n be the number of pairs; there are 2n individual socks.
For the first draw, there are 2n socks and 0 of them would result in a matching pair. Therefore, the probability of success is 0 / 2n = 0.
Since the first draw wasn't successful, there are 2n - 1 socks on the pile and 1 of them would result in a matching pair. Therefore, the probability of success is 1 / (2n - 1).
If the second draw wasn't successful, there are 2n - 2 socks on the pile and 2 of them would result in a matching pair. Therefore, the probability of success is 2 / (2n - 2).
In general, if the first k draws were unsuccessful, there are 2n - k socks on the pile and 2 of them would result in a matching pair. Therefore, the probability of success is k / (2n - k).
Finally, if none of the first n draws was successful, there are 2n - k socks on the pile and all of them would result in a matching pair. Therefore, the probability of success is n / (2n - n) = 1.
How it works
ḤX€Ṛ<RTḢ  Main link. Argument: n

Ḥ         Unhalve; yield 2n.
 X€       Map `random draw' over [1, ..., 2n], pseudo-randomly choosing an integer
          from [1, ..., k] for each k in [1, ..., 2n].
   Ṛ      Reverse the resulting array.
     R    Range; yield [1, ..., n].
    <     Perform vectorized comparison.
          Comparing k with the integer chosen from [1, ..., 2n - (k - 1)] yields 1
          with probability (k - 1) / (2n - (k - 1)), as desired.
          The latter half of elements of the left argument do not have a counter-
          part in the right argument, so they are left untouched and thus truthy.
      T   Truth; yield all indices of non-zero integers.
       Ḣ  Head; extract the first one.

Jelly, 8 bytes
Rx2ẊĠṪ€Ṃ

Try it online!
R    generate [1, 2, ..., n]
x2   duplicate every element (two socks of each pair)
Ẋ    shuffle the list, to represent the order in which socks are drawn
Ġ    group indices by value. this will produce a list of pairs of indices;
       each pair represents the point in time at which each of the corresponding
       socks were drawn
Ṫ€   take the last element of each pair. this returns an array of n integers
       which represent the points in time at which a matching sock was drawn
Ṃ    minimum, find the first point at which a matching sock was drawn

To verify, here is a version that displays both the desired output and the result of the "shuffle list" operation (to see what order socks were drawn in).

Python, 66 bytes
from random import*
f=lambda n,k=1:k>randint(1,n*2)or-~f(n-.5,k+1)

Dennis thought up a clever way to rearrange things, saving 5 bytes.

MATL, 16 15 bytes
Q:"r@qGEy-/<?@.

Try it online! Or observe the empirical distribution for 1000 samples in the N=7 case (it takes a while).
This directly generates the random variable representing the result, based on its probability distribution. Let N be the number of sock pairs, and let p(k) denote the probability that the k-th draw is successful, conditioned on the fact that the k-1-th draw was not succesful. Then (see also here):

p(1) is obviously 0. You can't have a pair with a single sock.
p(2) is 1/(2*N−1). At the second draw there is one winning sock that may be chosen out of 2*N−1 remaining socks.
p(3) is 2/(2*N−2). At the third draw there are 2 winning socks out of 2*N−2. The number of winning socks is 2 because the two socks you got after the second draw were different.
In general, by the same reasoning, p(k) is (k−1)/(2*N−k+1)
By the above formula, p(N+1) is 1. If you get to the N+1-th draw you are guaranteed to succeed then.

So the code iterates for a maximum of N+1 draws. At the k-th draw a random variable is generated that equals 1 with probability (k-1)/(2*N-k), or 0 otherwise. Whenever the random variable equals 1 (the draw has been succesful) the process stops and the current k is output.
Q:      % Input N implicitly. Generate [1 2 ... N+1] (values of draw index, k)
"       % For each
  r     %   Random variable uniformly distributed on the interval (0,1)
  @q    %   Push iteration index, k-1
  GE    %   Push 2*N
  y     %   Duplicate: push k-1 again
  -     %   Subtract: gives 2*N-k+1
  /     %   Divide: gives (k-1)/(2*N-k+1)
  <     %   Push 1 if random value is less than (k-1)/(2*N-k+1), 0 otherwise
  ?     %   If we got a 1
    @   %     Push k
    .   %     Break loop
        %   End if implicitly
        % End loop implicitly
        % Display implicitly

You and I had the same idea, but you know MATL :)

MATL, 14 13 bytes
EZ@G\&=XRafX<

Try it online! Or observe the empirical distribution for 4000 samples in the N=7 case (it takes a while).
E      % Input N implicitly. Multiply by 2
Z@     % Random permutation of [1 2 ... 2*N]
G\     % Modulo N: random permutation of [0 0 1 1 ... N-1 N-1]
&=     % Compare all pairs for equality. Gives an N×N matrix
XR     % Upper triangular part excluding the diagonal
a      % True for each column if it contains at least one true entry
f      % Get indices of true values
X<     % Take minimum. Implicitly display

JavaScript, 77 73 bytes
n=>{p={};for(i=n;i--;p[i]=2);while(--p[n*Math.random()|0])i++;return i+2}

Explanation
var f = (n) => {
    var index;      // used first to initialize pile, then as counter
    var pile = {};  // sock pile

    // start with index = n
    // check that index > 0, then decrement
    // put 2 socks in pile at index
    for(index = n; index--; pile[index] = 2);
    // index is now -1, reuse for counter

    // pick random sock out of pile and decrement its count
    // continue loop if removed sock was not the last
    while(--pile[n * Math.random() | 0]) {
        index++;    // increment counter
    }
    // loop finishes before incrementing counter when first matching pair is removed
    // add 1 to counter to account for initial value of -1
    // add 1 to counter to account for drawing of first matching pair
    return index + 2;
};

You can save four characters replacing f=(n)=> with n=> (or two, if you want to keep the assignment, some keep it, some remove it).

Nice catch, I've fixed it.  Although, when I read "You can write a full program or a function" in the rules, I thought that was a requirement.

As per consensus on Meta, unnamed functions that are not bound to a name are acceptable by default.

Shouldn't this be JavaSock? (yes, lame)

Python 3, 142 105 104 bytes
Thanks to Eʀɪᴋ ᴛʜᴇ Gᴏʟғᴇʀ for saving one byte!
My first answer:
import random
i=[x/2 for x in range(int(2*input()))]
d=[]
a=0
random.shuffle(i)
while 1:
 b=i.pop()
 if b in d:
  print(a)
  s
 d=d+[b]
 a+=1

My new answer:
from random import*
i=range(int(input()))*2
shuffle(i)
j=0
for x in i:
 if x in i[:j]:print(1+j)+s
 j+=1

Both exit with a NameError on s.

CJam, 17 bytes
ri,2*mr{L+:L(&}#)

Test it here.

R, 49
N=scan();which(duplicated(sample(rep(1:N,2))))[1]

I'm sure there must be a better way of doing this in R! I tried doing something cleverer but it didn't work.
Edit: Improved by @bouncyball since it doesn't have to be a function.

do you have to use function(N)? using N=scan(); would save 2 bytes

Python 2, 101 bytes
from random import*
d=[]
p=range(input())*2
shuffle(p)
while list(set(d))==d:d+=p.pop(),
print len(d)

VBA, 61 bytes
Function K(D):While 2*D-K>K/Rnd:K=K+1:Wend:K=K+1:End Function

- models the shifting probability of sock match given previous failure to match. At the point of evaluation, K is "socks in hand", so draw number is one more.

Pyth, 14 bytes
lhfnT{T._.S*2S

Explanation:
       ._        #Start with a list of all prefixes of
         .S      #a randomly shuffled
           *2S   #range from 1 to input (implicit), times 2.
  f              #filter this to only include elements where
   nT{T          #element is not equal to deduplicated self (i.e. it has duplicates)
lh               #print the length of the first element of that filtered list


text:
Diff compression
For this challenge, you need to compress a diff.  A diff is some data that represents the difference between two strings.  For this challenge, you need to provide one or more programs that can:

Input A and B, and output a diff, C
Input A and C, and output B
Input B and C, and output A

The goal is to make the diff, C, as small as possible.  The diff can be anything: a string, a number, a blob of data.  We just care about the size (number of bytes).
I have 50 test cases that can found on Github.  Each test case consists of two space-separated URLs which point to the 2 files you need to diff.  (These test cases originated from PPCG members' Github profiles.  Thanks all!)
All three tasks above should take under a minute to run on a reasonably powered computer (for each test case).
Your score is equal to the total size (in bytes) of all 50 diffs, lower is better.   Hardcoding diffs in your program is not allowed (I reserve the right to change the test cases to prevent hardcoding). Builtins that produce a diff (like diffutils) are not allowed.

What precisely is a diff?

Anything you want it to be, really.  Informally, its a string that represents the differences between A and B

For tasks 2 and 3, do we have to dynamically figure out which which file is which, i.e., do we get the contents or the name of the file as input? Also, is built-in compression allowed?

@Dennis You can make 3 different functions/programs if you'd like, and assume that they each get the correct input (as a string or filename).  Built-in compression is allowed.

In other words, you can assume that 1,2,3 are completely independent tasks.

You explain what is a diff, but what is a string? Any sequence of bytes? Just printables? Can it contains null bytes?

@edc65 a sequence of characters.   You should be able to handle unprintables.  However, I don't care if you assume a certain encoding.

Can we assume all input is ASCII?

@SocraticPhoenix yes.

Hmm.. can we also compress the result of our algorithm with gzip or similar? (Edit: am I asking the same thing as Dennis?)

@SocraticPhoenix yes, that's the same question as Dennis, and its still allowed :)

So we are allowed to depend on the fact that A is first and B is second? Basically, can we use the order of the input to our advantage?

@SocraticPhoenix absolutely.

umm.. file not found Edit: 13th line, first entry

Bah, link rot already?  There are now 49 test cases.

More link rot: numbering test case pairs by 1-base line index; both pairs of test cases 3, 13, 14, 15, 16, 17, 18, 19, 20, 21 are all 404.  Outside of these, I managed to retrieve every other case.

I'm closing this question because it is largely unanswered and many of the old links I was using as test cases no longer work.  Feel free to update the question and reopen if you wish.

I think it is still an interesting question but maybe you could update the links to have a static .tar file on github?

@Seth I agree, but getting all of the links was quite a bit of work, and I'm not really motivated to do it again.  If you are up for the task, be my guest :)

Done.  The GIST is https://gist.github.com/sethhillbrand/64066935e3f8c0fac75d75edd43c9ef8
The second file is a uuencoded archive of the 40 remaining pairs of test cases.

@Dennis: Question doesn't seem unclear.  Could you add a comment to specify what your concern is?

@Seth sorry for the late reply.  The question was closed by my request.  I've tried opening up your commits.uu file, and I'm struggling to get it decoded, which is why I haven't reopened the question.

Got it.  To simplify, I've updated the gist with the files base64 encoded as this seems to be more standard than uudecode these days.  To extract the files, save the gist as commits.tar.xz.64 and execute base64 -d commits.tar.xz.64|tar -xvJ

Is my answer valid?
set f [open commits.txt]
while {![eof $f]} {scan [gets $f] %s\ %s a b; puts [string compare $a $b]}
close $f

testable on: http://www.tutorialspoint.com/execute_tcl_online.php?PID=0Bw_CjBb95KQMNmd4QkxvQUFsTnM

You need to provide multiple programs (both a diff equivalent and a patch equivalent). If string compare diffs strings, it violates the "no builtins" rule. If it only compares strings (like the name suggests), it doesn't leave enough information to recreate a patch.

@ais523: builtins I understood it as command line commands. I know that string compare does not generate info to create a page, but there is no place in the question asking for it.

From the question, "2. Input A and C, and output B". This is something that your submitted program can't do, and that in fact no program could do (as it doesn't have enough information).

@ais523: OK I misunderstood.

@ais523: I don't think your statement is correct "in fact no program could do".  If C is the diff between A and B, then given C and A, B is calculable.  Maybe I missed your exact point

@Seth: Sergiol's definition of a "diff" destroys data, so it isn't reversible (and isn't really a diff). That was the point I was trying to get at. The "write a program to reverse the diffing operation" part of the question is a nice objective way to ensure that the diff actually is a diff.

@ais523: That makes sense.  Agreed.


text:
Move platforms!
The Challenge
Given either a string (may have newlines), or a two dimensional array, and a positive integer n, output the position of the platforms n turns after the
initial position.

U, D, R, L are platforms.
^, v, >, < are arrows that change the directions of the platforms.
U, D, R, L move up, down, right and left, respectively. When an arrow is in front of a platform, it changes the direction.
Affects platform:
R<

D
^

v
U

>L

>L
 <

(top arrow will affect top L, but bottom arrow won't affect top L)
Won't affect:
 <
R

>
 L

v
 U

D
 ^

<R

(R is going right, so < won't affect the R)

For example, if this was the string:
>R   <

The platform R would move right until it's nearly touching the arrow:
>   R<

After, it would change the direction and start going left:
>  R <

(even though now it's going left, the letter won't change.)
There are some cases when the platform won't move, such as
>R<

or
v
U
^

Last example:
v   >
D    Rv
   ^U
^    <

After one turn,
v   >
    U v
D  ^ R
^    <

After one turn,
v   >
D    Uv
   ^R
^    <

And one more turn:
v   >
    R v
D  ^ U
^    <

You can assume that the platforms, after n turns, won't overlap, that the platforms won't go out of bounds, and that a platform won't touch an arrow that's pointing to the same direction as the platform.

Test Cases
Input:
">R   <", 4
Output:
">  R <"

Input:
">R   <", 6
Output:
">R   <"

Input:
">R<", 29
Output:
">R<"

Input:
"v
 U
 ^", 5
Output:
"v
 U
 ^"

Input:
"v

 D
 ^", 1
Output:
"v
 D

 ^"

Input:
"v

 D
 ^", 4
Output:
"v

 D
 ^"

Input:
"v   >
 D    Rv
    ^U
 ^    < ", 2
Output:
"v   >
 D    Uv
    ^R
 ^    <

Input:
">RL<", 3
Output:
">LR<"

Input:
">L  R<", 4
Output:
"> RL <"

Input:
"> RR<
 >L  R <", 6
Ouput:
">RR <
 > RL  <"

Input:
"R   <", 4
Output:
"  R <"

Input:
"R   <", 6
Ouput:
"R   <"

Rules

This is code-golf, so shortest answer in bytes wins!
Standard loopholes are disallowed.

@closevoters: what is unclear about this challenge?

Time to make an esoteric programming language based on this.

Also, what happens if a platform goes off of the grid?

@Quelklef you can assume that the platforms won't go off of the grid after n turns.

C#, 1245 bytes
(i,n)=>{string q="RlherLHEfquDFQUd",D="><v^",H="Rlhe",E="LrHE",X="Dufq",Y="UdFQ",S="#v<>";Func<string,char,int>I=(v,L)=>v.IndexOf(L);Func<char,int,char>z=(y,m)=>q[I(q,y)+m*4];Func<string,char,bool>_=(s,F)=>s.Contains(F);var g=((i as char[][])??((string)i).Split('\n').Select(f=>f.ToCharArray())).ToList();int w=g[0].Length,h=g.Count,u;g=g.Select((r,o)=>r.Select((t,p)=>'R'==t&&w>p+1&&0<=(u=I(D,r[p+1]))?z(t,u):'L'==t&&0<=p-1&&0<=(u=I(D,r[p-1]))?z(t,-1+u):'D'==t&&h>o+1&&0<=(u=I(D,g[o+1][p]))?z(t,-2+u):'U'==t&&0<=o-1&&0<=(u=I(S,g[o-1][p]))?z(t,-u):t).ToArray()).ToList();for(var j=0;j<n;j++){bool L,R,T,B;g=g.Select((r,o)=>r.Select((t,p)=>_(D,t)?t:(R=0<=p-1)&&_(H,r[p-1])?w>p+1&&0<=(u=I(D,r[p+1]))?z(r[p-1],u):r[p-1]:(L=w>p+1)&&_(E,r[p+1])?0<=p-1&&0<=(u=I(D,r[p-1]))?z(r[p+1],-1+u):r[p+1]:(B=0<=o-1)&&_(X,g[o-1][p])?h>o+1&&0<=(u=I(D,g[o+1][p]))?z(g[o-1][p],-2+u):g[o-1][p]:(T=h>o+1)&&_(Y,g[o+1][p])?0<=o-1&&0<=(u=I(S,g[o-1][p]))?z(g[o+1][p],-u):g[o+1][p]:(L&&_(H,t)&&!_(D,r[p+1]))||(R&&_(E,t)&&!_(D,r[p-1]))||(B&&_(Y,t)&&!_(D,g[o-1][p]))||(T&&_(X,t)&&!_(D,g[o+1][p]))?' ':t).ToArray()).ToList();}return string.Join("\n",g.Select(s=>new string(s))).ToUpper().Replace("H","U").Replace("E","D").Replace("F","R").Replace("Q","L").Replace("V","v");};

It seemed simpler at first, but then I just kept writing more code. :D
LINQ to enumerate and update the board, changing the character to indicate the direction it's moving. The characters are reverted back before returning. Also assumes that the board is square (so had to modify some of the multi-line test cases to fit this restriction).
Expanded:
// Casts to Func<object, int, string> so as to accept both string and char[][] input
(i, n) =>{
    // Shorten constants/functions
    string q = "RlherLHEfquDFQUd", D = "><v^", H = "Rlhe", E = "LrHE", X = "Dufq", Y = "UdFQ",S="#v<>";
    Func<string, char, int> I = (v, L) => v.IndexOf(L);
    Func<char, int, char> z = (y, m) => q[I(q,y) + m * 4]; // Updates the direction of the platform
    Func<string, char, bool> _ = (s, F) => s.Contains(F);

    // Convert either string or char[][] input into common format
    var g = ((i as char[][]) ?? ((string)i).Split('\n').Select(f => f.ToCharArray())).ToList();

    // Get board dimensions
    int w = g[0].Length,h = g.Count,u;

    // Update platforms to reflect the direction they're initially moving
    g = g.Select((r, o) => r.Select((t, p) =>
        'R' == t &&w>p+1&&0<=(u=I(D,r[p+1]))?z(t,u):
        'L' == t &&0<=p-1&&0<=(u= I(D, r[p-1]))?z(t,-1+u):
        'D' == t &&h>o+1&&0<=(u= I(D, g[o+1][p]))?z(t,-2+u):
        'U' == t &&0<=o-1&&0<=(u= I(S,g[o-1][p]))?z(t,-u):t
    ).ToArray()).ToList();

    // Go through each timestep
    for (var j=0;j<n;j++)
    {
        bool L,R,T,B;
        g = g.Select((r, o) => r.Select((t, p) =>
            // Don't change <>^v characters
            _(D,t) ? t :

            // Move platforms going right
            (R=0 <= p - 1) && _(H,r[p-1]) ? w > p+1 && 0<=(u= I(D, r[p+1])) ? z(r[p-1],u) : r[p - 1] :

            // Move platforms going left
            (L=w > p + 1) && _(E,r[p+1]) ? 0 <= p-1 && 0<=(u= I(D, r[p-1])) ? z(r[p+1],-1+u) : r[p + 1] :

            // Move platforms going down
            (B=0 <= o - 1) && _(X,g[o-1][p]) ? h > o+1 && 0<=(u= I(D, g[o+1][p])) ? z(g[o - 1][p],-2+u) : g[o-1][p] :

            // Move platforms going up
            (T=h > o + 1) && _(Y,g[o+1][p]) ? 0<=o-1&&0<=(u= I(S, g[o-1][p]))?z(g[o + 1][p],-u) :g[o+1][p]:

            // Erase platforms that moved
            (L&&_(H,t)&&!_(D,r[p+1]))||
            (R&&_(E,t)&&!_(D,r[p-1]))||
            (B&&_(Y,t)&&!_(D,g[o-1][p]))||
            (T&&_(X,t)&&!_(D,g[o+1][p]))
            ? ' ':

            // Maintain whatever character this was
            t
            ).ToArray()).ToList();
    }

    // Replace direction characters with platform label and join into string return value.
    return string.Join("\n",g.Select(s=>new string(s))).ToUpper().Replace("H", "U").Replace("E", "D").Replace("F", "R").Replace("Q", "L").Replace("V", "v");
};