News for hackers. Stuff that matters.
Re:Why 37signals Doesn't Hire Programmers Based on Brainteasers by ori_b on Thursday January 05, 2012 @05:54PM (#3430979)
I was going for foo as 'dlist_prepend()', not dlist_insert(), but figuring out that it's putting a node into a list is good enough for me. (Edit: to me, 'prepend' implies that there are no nodes before the head of the list you're prepending to)

That should be enough for you to figure the last 2 errors, in any case.

Re:Why 37signals Doesn't Hire Programmers Based on Brainteasers by 2arrs2ells on Thursday January 05, 2012 @06:11PM (#3431052)
Prepend is probably a better way of expressing "insert before" :P

n->p = p->p

I don't see the last one - unless foo should be returning n?

Re:Why 37signals Doesn't Hire Programmers Based on Brainteasers by ori_b on Thursday January 05, 2012 @06:21PM (#3431090)
Yes, it should be returning `n`. And the final one I was thinking of was a segfault on an empty list

     prepend(NULL, &something);
would die if you don't do;

     if (p != NULL)
         p->p = n;

I think, this would be easier in a larger problem where you had context that gave you usage examples. I probably wouldn't ask someone to debug a function floating an a vacuum like I did here. I'd use a trivial but full working program.

I don't think I'd expect everyone to get every bug without a little bit of prodding in the right direction. Being able to step through the code and show what it's doing to the data structures would be a first step that would make me happy. Recognizing that the data structure looked like it's a linked list, and finding and and fixing a couple of the bugs, and I'd be very happy.

Re:Why 37signals Doesn't Hire Programmers Based on Brainteasers by altxwally on Friday January 06, 2012 @09:57AM (#3433497)
Thanks for providing the example, this thread was very entertaining and made me become more interested in learning more about how C works.
Re:Why 37signals Doesn't Hire Programmers Based on Brainteasers by ori_b on Friday January 06, 2012 @11:21PM (#3436188)
Glad you found it interesting.