News for hackers. Stuff that matters.
Re:Will the real programmers please stand up? by jast on Tuesday June 29, 2010 @05:56PM (#1473000)
Funny, I also fired textmate and started solving the problem in C :-)

It took me around 20 minutes to write all the extra code and 9 to write the reverse function (including the testing and all).

The problem was not knowing how to solve it but more the pressure of looking at the clock and seeing the time flying away. Because of that, some minor mistakes were done and naturally you start to get nervous and waste more time. In a phone interview I would probably even do more minor mistakes and fail it.

Re:Will the real programmers please stand up? by swolchok on Tuesday June 29, 2010 @06:32PM (#1473133)
What extra code? I've got a struct definition, a print_list function, cons, and a really dumb testing driver that builds the list [1 2 3], reversing and printing it a few times throughout its construction. The line count of all that [EDIT: I meant "everything except the testing driver"] is about equal to the line count of my reverse.
Re:Will the real programmers please stand up? by jast on Tuesday June 29, 2010 @07:11PM (#1473224)
That extra code :-) First I wrote everything to manipulate a linked list and test it and then I wrote the reverse function. Since I wrote a insert at front function, the reverse function is small. I must add that I am not a fast typer.
Re:Will the real programmers please stand up? by cabalamat on Tuesday June 29, 2010 @07:39PM (#1473282)
How long is your reverse? Mine is 14 lines (see below), and I doubt I could code the rest in that length.

   struct LinkedList {
      LinkedList* next;
      int data;
   }

   void reverseLL(linkedList* ll){
      if (ll==NULL) return NULL;
      LinkedList* newList;
      prev = NULL;
      for (;;) {
         newList = malloc(LinkedList);
         newList->data = ll->data;
         newList->next = prev;
         if (ll->next==NULL) break;
         prev = newList;
         ll = ll->next;
      }
      return newList;
   }
Re:Will the real programmers please stand up? by swolchok on Wednesday June 30, 2010 @02:09PM (#1475638)
http://scott.wolchok.org/listrev.c is what I was satisfied with yesterday. I seem to have exaggerated slightly about the non-driver code being the same length as the reverse, but it's close.