Hofstadter Q-sequence Definition


a(1) = 1
a(2) = 1
a(n) = a(n-a(n-1)) + a(n-a(n-2)) for n > 2 where n is an integer


Task

Given positive integer n, generate a(n).

Testcases

n  a(n)
1  1
2  1
3  2
4  3
5  3
6  4
7  5
8  5
9  6
10 6
11 6
12 8
13 8
14 8
15 10
16 9
17 10
18 11
19 11
20 12


Reference


Obligatory OEIS A005185
Haskell, 35 33 bytes

a n|n&lt;3=1|b&lt;-a.(-)n=b(b 1)+b(b 2)


Defines a function a.