Hofstadter H-sequence Definition

\$a(0) = 0\$
\$a(n) = n-a(a(a(n-1)))\$ for integer \$n &gt; 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
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]
-- =&gt; [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!