Jump to content

Daniel0

Staff Alumni
  • Posts

    11,885
  • Joined

  • Last visited

Everything posted by Daniel0

  1. Excellent server administration skills.
  2. This is known as the Knapsack problem. It's not impossible, but pretty difficult to solve (probably at least without advanced knowledge in computer science or mathematics).
  3. That's why e.g. the "birthday paradox" is called like it is. Using the above function, [imath]p_{365}(23) \approx 0.5[/imath], so there is just above 50% chance that at least two people will have the same birthday when there are 23 people if all days are equally likely as birthdays and you ignore leap years. It's not a mathematical paradox, but it's the underlying probability theory that is not intuitively clear until you go through the math. The reason why it uses factorials is to get rid of the [imath]\cdots[/imath]. If you have n!, but want to get rid of the last k terms (counting downwards), then you just divide by (n-k)! because of the way you can cancel out factors in a fraction.
  4. I believe that is incorrect. Say you have a set of distinct elements [imath]X[/imath] with [imath]|X|=k[/imath]. How many elements do you need to pick before you have a 50% chance of picking the same number again? Let [imath]p_k(n)[/imath] be the function determining the probability of picking a duplicate when selecting exactly [imath]n[/imath] elements. By the pigeonhole principle, you are guaranteed to pick duplicates if you pick [imath]n > k[/imath] elements. When determining the probability, it's easier looking at the opposite in this case: what is the probability that all the elements are distinct (i.e., there are no duplicates)? We'll denote this by [imath]p_k'(n)[/imath] and then [imath]\forall n > k : p_k'(n) = 0[/imath]. Now, when selecting the first element we have all [imath]x \in X[/imath] available, so [imath]p_k'(1) = \frac{k}{k} = 1[/imath]. Next time we have one less, so by the multiplication principle [imath]p_k'(2) = \frac{k}{k} \cdot \frac{k-1}{k}[/imath], [imath]p_k'(3) = \frac{k}{k} \cdot \frac{k-1}{k} \cdot \frac{k-2}{k}[/imath]. Indeed for [imath]n \leq k[/imath]: [math]\begin{split} p_k'(n) &= \frac{k}{k} \cdot \frac{k-1}{k} \cdot \frac{k-2}{k} \cdots \frac{k-n+1}{k} \\ &= \frac{k \cdot (k-1) \cdot (k-2) \cdots (k-n+1)}{k^n} \\ &= \frac{k!}{(k-n)! \cdot k^n} \end{split}[/math] Thus our probability [imath]p_k(n)[/imath] must be given by: [math] p_k(n) = \begin{cases} 1 &\text{if } n > k \\ 1 - \frac{k!}{(k-n)! \cdot k^n} & \text{if } 0 < n \leq k \end{cases} [/math] Then we'll see that [imath]p_{100}(12) = 0.4968[/imath] and [imath]p_{100}(13) = 0.5572[/imath]. This is of course assuming that selecting any number is equally likely to selecting any other number. By the way, what's up with all the line breaks?
  5. If it's not crucially important, I would just use a cookie to check if they've clicked it. Sure, it can easily be circumvented, but it will also be much easier on the database.
  6. Split it up and use dechex. By the way, you've chosen a really bad format for storing it in. Take for instance this: 11211222. It could be either 11,211,222 or 112,11,222 or 112,112,22. Edit: Ah, never mind. I didn't notice that it was just the way you were outputting it. In that case, just call dechex() on all of them.
  7. Instead of relying on randomness, why not create an algorithm that is deterministic. If you develop a good hashing algorithm you could easily use that. Just for reflecting on randomness, there is a sorting algorithm called bogosort. It's extremely simple (and stupid): check if your dataset is sorted, if it isn't, shuffle it and start the algorithm again, otherwise stop. Because shuffling is reliant on randomness, this algorithm has a worst case running time of O(∞); you might never get it sorted. It's the same thing here. There is a chance that finding a unique random number will take unreasonably long time, and there is even the (small) chance that you will never find one. Of course as your collection of bar codes increases in size, this probability becomes larger and larger.
  8. See bold part:
  9. I've got a VPS. A dedicated server would be overkill for my needs.
  10. That's quite a surprise to me. As I said, it is something I would expect from any web host. Then again, I've never purchased shared hosting.
  11. I would expect all webhosts to have that.
  12. That doesn't necessarily mean you cannot write a TDD primer.
  13. What do you mean with "doing .htaccess on a folder"? .htaccess files just contain Apache configuration directives. Not only does it have nothing to do with PHP whatsoever, but it can all be looked up in the Apache documentation.
  14. Here is yet another alternative: http://devzone.zend.com/article/4571-Fetching-multiple-random-rows-from-a-database
  15. A sub query returns a result, like all queries do, and you can use that result as a variable in your query. That's it, essentially.
  16. http://web.archive.org/web/20080209154336/http://www.phpit.net/article/simple-mvc-php5/
  17. A login script is essentially so simple that it's not even worth dedicating a tutorial for that. Stuff involved is essentially form processing, database access and sessions/cookies. We have a tutorial for sessions and cookies and we have one for database access and another one focusing on joins and unions. Then you have form processing, but that's fairly straightforward. You simply read from the $_GET or $_POST superglobal. You might also be interested in this blog post that talks about breaking a script/application down into logical elements the same way I just did.
  18. You mean like this? http://www.phpfreaks.com/tutorial/debugging-a-beginners-guide
  19. Please do not post links to download copyrighted material that you do not have the right to redistribute yourself.
  20. I'll sticky this for further reference and in case other people might know books that people might find useful.
  21. I can't remember when I've last used FTP. I always use SSH, SCP and SVN.
  22. I've read some of SitePoint's Simply JavaScript. At the time I read it I found it pretty good.
  23. [quote author=lukkyjay link=topic=119433.msg728404#msg728404 date=1193718287] I'm just now starting to learn php for a project on my own site.  I don't understand how a WYSIWYG would work with php, but that would be awesome if it were actually possible.  Can you get specific about the best WYSIWYG for a beginner? [/quote] WYSIWYG is for HTML only. Best is a matter of personal preference and hence the reason why this and [url=http://www.phpfreaks.com/forums/index.php/topic,54859.0.html]this[/url] topic are created.
  24. http://zend.com/studio (Zend Studio)
  25. And for those who don't know how to use Google: FileZilla SmartFTP CuteFTP (Pro - Home - Mac Pro) RightFTP CoreFTP JFtp FireFTP
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.