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
Related challenges about Hofstadter sequences: 1, 2, 3
– Martin Ender – 2016-08-02T06:43:43.3634And I still think you should reference GEB... – Martin Ender – 2016-08-02T06:43:55.003
1How is [tag:number-theory] relevant here? – flawr – 2016-08-02T09:56:00.097
1
@flawr facepalm Let me try that again: Gödel, Escher, Bach: An Eternal Golden Braid
– Stig Hemmer – 2016-08-02T10:18:57.1501
@StigHemmer Actually facepalm has its own Emoji now: http://emojipedia.org/face-palm/
– Tobias Kienzler – 2016-08-03T11:50:49.973