For the best experience on desktop, install the Chrome extension to track your reading on news.ycombinator.com
Hacker Newsnew | past | comments | ask | show | jobs | submit | history | kunqiana's commentsregister


I been working on easyinfograph.com for a few months now. Plan on featuring it for product hunt when I am done with a few more features.


It would be nice if I can search for projects using specific programming languages. Also why can't I just upload the project I need people to contribute without using github?


Thank you for the feedback! We are going to support the "search by programming language" feature, soon. We also plan to provide a more generic way on how to add an open source project. The current state is a quick and dirty prototype due to the limitations of the participation in the rails rumble competition (a 48 hours hackathon).


I tried to recode what you did in scheme for practice

    (define (pascal n)
      (if (= n 0) (list 1)
       (begin
       (let ((L (pascal (- n 1)))
           (ret (list 1))) 
       (do ((i 0 (+ i 1)))
           ((= i (- (length L) 1)))
           (begin (set! ret (append ret (list (+ (list-ref L    i) (list-ref L (+ i 1))))))))
       (append ret (list 1))
        ))))


This is very, very, very bad scheme. set! and list-ref are no-no.

This is better scheme:

(define (pascal n) (if (= n 0) (list 1) (let ((L (pascal (- n 1)))) (append (list 1) (map + (cdr L) L) (list 1)))))


Thanks for the tip, but when I tried to run it under mzscheme I got the error: map: all lists must have same size; arguments were: #<procedure:+> () (1). Also could you explain why set! and list-ref are bad?


You are doing yourself a great service by learning Scheme - that can fundamentally change how you think about programming. Reading the first chapter of SICP[0] will change you forever. Yet right now you're using Scheme as a Python/C/Ruby with a strange syntax, while it's a totally different language with its own idioms. You should learn them to master Scheme.

As for your particular questions:

1. map yields an error under mzscheme

I'm at work, and didn't have access to a proper scheme, so I used an online REPL[1], which apparently is more forgiving. Regardless, you can write your own map (a good exercise!) that stops as soon as one of the arguments is exhausted. Make it tail-recursive[2] as well!

2. list-ref is bad

Lists are beautiful data structures designed for recursive algorithms. If you are using lists and not using recursion (or a hidden recursion in the form of map), you're doing something wrong. list-ref uses list as a vector, which has a performance implications - your algorithm is O(n^3) while mine is O(n^2).

3. set! is bad

Margins are too small for a proper explanation :), but basically set! has side-effects[3], and functional programming should avoid having them.

Have fun learning Scheme!

[0] http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-9.html#... [1] http://www.bluishcoder.co.nz/jsscheme/ [2] http://en.wikipedia.org/wiki/Tail_call [3] http://en.wikipedia.org/wiki/Side_effect_(computer_science)


Just out of curiosity did you learn scheme primarily through books? Do you actually use the language on a daily basis? Maybe you are a lisp hacker?


Using (map + (cdr L) L) doesn't work since they're different sizes (with DrRacket that I used, I see that it worked for you in your other comment, it is a very nice solution!). I'm not sure of an easy constant time way to append a zero to the end of (cdr L). The way I did it is similar to how you did it without map:

(define next (lambda (l) (if (null? (cdr l)) '(1) (cons (+ (car l) (cadr l)) (next (cdr l))))))

(define pascal (lambda (n) (cond ((< n 1) '()) ((= n 1) '(1)) (else (cons 1 (next (pascal (- n 1))))))))


Ah, (map + (cdr L) L). That's excellent!


Here's my version in C:

    int main(int argc, char ** argv) 
    { 
    	long *n1,*n2;
    	int row,i;

    	row=0; N1[0]=1L; print_row(row,N1);

    	while(row++ < MAX_ROWS)
    	{
    		for(i=0, n1 = N1, n2=N2; i<MAX_BUF && *n1; i++)
    		{
    			if (i==0 )        n2[i] = 0       + n1[i];
    			else if(n1[i]==0) n2[i] = n1[i-1] + 0;
    			else              n2[i] = n1[i-1] + n1[i];
    		}
    		print_row(row,N2);
    		for(n1=N1,n2=N2; *n2; ) *n1++ = *n2++;
    	}
    }

    void print_row(int row,long*n)
    {
        printf("row #%d",row);
        while(*n) { printf(" %ld ", *n++);}
        printf("\n");
    }
This works through the size of long int (at least 50 rows).


I think some of your code is missing (like where N1 and MAX_ROWS are defined).

Here's mine:

  #include <stdio.h>
  #include <stdlib.h>

  long *pascal(int row) {
    long *ret = (row == 1 ? NULL : pascal(row - 1));
    ret = realloc(ret, sizeof(long) * row);
    ret[row - 1] = 1;
    for (int i = row - 2; i > 0; i--)
      ret[i] += ret[i - 1];
    return ret;
  }

  int main(int argc, char *argv[]) {
    int row = atoi(argv[1]);
    long *data = pascal(row);
    for (int i = 0; i < row; i++)
      printf("%ld ", data[i]);
    printf("\n");
    free(data);
    return 0;
  }


Hi,

I ran your code and it does run well. However fails for large cases such as pascal(200000).

You mentioned you worked for Google and Amazon, how can you modify the code to get an answer for pascal(200000)


Yeah, for large cases the long will overflow (also it will do a lot of realloc()). Your two main options for this are:

  1. use double to get approximately-correct answers
  2. use an abitrary-precision library like GMP


What if I wanted an exact precision. Could I use a custom data type to get better precision? If I used a custom data type, how could I make the code work for a distributed system to get parallel behavior?


upvoted for realloc trick


This inspired me to write one that is even shorter and doesn't heap-allocate any memory at all. What can I say, I'm a sucker for minimal C.

  #include <stdio.h>
  #include <stdlib.h>

  int main(int argc, char *argv[]) {
    int row = atoi(argv[1]);
    long data[row];
    for (int i = 0; i < row; i++) {
      data[i] = 1;
      for (int j = i - 1; j > 0; j--) data[j] += data[j - 1];
    }
    for (int i = 0; i < row; i++) printf("%ld ", data[i]);
    printf("\n");
    return 0;
  }


When did C start accepting non-constants for array size declarations?


Variable-length arrays were added in C99.


I was wondering the same thing. But I can confirm it compiles and runs, though I had to supply a -std=c99 flag to gcc.


Ahhh, useful tip. I've just been using alloca instead...


Best solution I've seen here so far.


If row is too big you can bust your stack frame when you define your data array.


True, though in this example integer overflow would happen first.


I think your code is off by 1.


I have a question, why did git grow so popular? What was better about it?

Edit: To down voters I think this question is important because it helps us understand why certain softwares are successful despite other successful competitors. I am not trying to start a flame war on which version control system is better.


This is an interesting question. I'd say it's a mix of technical and social factors. Technically it's a solid abstraction (versioned directories), it's ridiculously fast (specially when compared to most alternatives at the time, even local ones), and somewhat space efficient (if you're not keeping binaries around). Because the format has been specified from the beginning it's easy to build all sorts of tools on top of it and add as much knowledge as you want, including line-by-line diffs, rename tracking, etc. It also ignores some hard problems people were focusing on at the time (merges, for example).

Socially, it first had a big userbase because the kernel is a large enough project and the switch was made top-down as far as I remember (not everybody was forced to do it but it was much easier if you could). This means a lot of people had to get acquainted with it, and this set of people turned out to be somewhat competent at changing it to make it faster, more stable, and easier to use (up to a point). Linus's personality played an important role here, as he entertainingly made a case for why it was good, which created a certain "cool factor". Second, there was the github factor which allowed this user base to explode exponentially by making it really cheap and easy to use.


Some ideas:

1. By being "stupid", git doesn't treat the user as stupid.

2. git allows repositories to be uploaded or transferred anywhere for others to use with a single, simple command.

3. git is efficient and fast. No one likes waiting for their computer to do a seemingly easy task -- especially software developers/hackers who know something should be O(1) complexity and could be written in X lines of code.

4. Merging/branching is easy.


I have a question, why did git grow so popular?

1. Celebrity nerd Torvalds creates a vcs. It is not terrible.

2. Linux development moves to git.

3. Rails development moves to git.

4. Github.


People are probably downvoting you because it's totally off-topic, in addition to be a really well-worn question. This is something you can easily Google and get hundreds of answers for.

That said, the answer IMO seems to have something to do with the fact that some very important communities ready for a different VCS model, and some very good and influential developers answered that call at roughly the right time. For example, both Mercurial and Git were started in direct response to the Linux Kernel having their bitkeeper license revoked.

Github is really a killer app for git, and that's probably one reason it's gotten as popular as it has.


I think it is a legitimate question.

I picked up git because I know I needed to use SOMETHING for version control. Looking around a few years back I saw CVS, SVN, and the rest.

So I Google/ask around. I see that git is getting mentioned pretty regularly. I also see Hg being mentioned. I basically search for free hosting for both. Github just seemed more friendly. The UI was bigger and easier to read than bitbucket. So I just went with git.

Often it is the stupid reasons that people adopt something: it looks nicer, my friends are using it, I can pronounce the name.


GitHub may be one reason.

Maybe less but still important IMHO is that it's far more pronounceable than e.g. SVN. That could help build the hype.


I remember when I was first introduced to version control - I was told "we're using 'subversion' for XYZ". I thought that meant we were doing something sneaky that I shouldn't talk about.

"Git" is definitely a nice name.


I have no idea where urbandictionary.com is from, but its page on `git' describes the meanings it's always had for me, and indeed probably most UK (and Australian?) readers:

http://www.urbandictionary.com/define.php?term=git

This is partly why I have, so far, not joined the "Git Hub".

All in all, I think a better name could have been chosen. But, most of the time, I only type it - and it IS certainly nicer to type than `svn', I'll give it that.


hi I got his error, on ubuntu 11.04. I moved the base folder to the neo folder but it still didn't work. Is it because it's missing the game data?

  DOOM 1.3.1.1304-debug linux-x86 Nov 24 2011 00:27:04
  found interface lo - loopback
  found interface eth0 - 10.0.0.19/255.255.255.0
  ------ Initializing File System ------
  Current search path:
  /home/xx/.doom3/base
  /home/xx/doom3.gpl/neo/base
  game DLL: 0x0 in pak: 0x0
  Addon pk4s:
  file system initialized.
  --------------------------------------
  ----- Initializing Decls -----
  ------------------------------
  ------- Initializing renderSystem --------
  idRenderSystem::Shutdown()
  Sys_Error: _default material not found


I got a similar error on linux. How did you get it to work?


Anyone got this error?

  DOOM 1.3.1.1304-debug linux-x86 Nov 24 2011 00:27:04
  found interface lo - loopback
  found interface eth0 - 10.0.0.19/255.255.255.0
  ------ Initializing File System ------
  Current search path:
  /home/xx/.doom3/base
  /home/xx/doom3.gpl/neo/base
  game DLL: 0x0 in pak: 0x0
  Addon pk4s:
  file system initialized.
  --------------------------------------
  ----- Initializing Decls -----
  ------------------------------
  ------- Initializing renderSystem --------
  idRenderSystem::Shutdown()
  Sys_Error: _default material not found


I am getting the error, "scons: * [build/debug/core/sys/scons/doom] Source `/usr/lib/libz.a' not found, needed by target `build/debug/core/sys/scons/doom'. scons: building terminated because of errors." Anyone knows what I should install?


zlib

or zlib-dev if your distribution separates out development packages


we definitely need more stories like these to balance out the belief that doing a start-up is some how "easy". The reason is not to discourage people but to let them know what they are in for so that they can prepare better. It would also give some CS undergrads second thoughts about dropping out of college with the attitude that start-ups are easier.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search:

HN For You