Count the number of books of each color on the shelf. If you search the bookshelf, you will get an order of colors(which is randomized each time). That should give you a 4-digit code.
Let me know if that's not enough and I'll give you a better hint! (Also I just realized I should probably add a walkthrough.txt file in the next update ^^; )