Back to front pageView on Hacker News (opens in a new tab)Ask HN: What is the most beautiful piece of code you've ever read?476 pointsby seisvelas (on Hacker News)7 years agoPreferably an elegant snippet rather than an entire (well engineered) codebase.Comments (380) 116 threadsShow all commentsShowing thread 64 of 116enriquto7 years ago#the recursive "find" function on a disjoint set forest with path compression, by R.E.Tarjan. It brings tears to my eyes every time I read it. int dsf_find(int *t, int a) { if (a != t[a]) t[a] = dsf_find(t, t[a]); return t[a]; }
Ask HN: What is the most beautiful piece of code you've ever read?476 pointsby seisvelas (on Hacker News)7 years ago
enriquto7 years ago#the recursive "find" function on a disjoint set forest with path compression, by R.E.Tarjan. It brings tears to my eyes every time I read it. int dsf_find(int *t, int a) { if (a != t[a]) t[a] = dsf_find(t, t[a]); return t[a]; }
Comments (380) 116 threads
Show all comments
Showing thread 64 of 116