Monthly Archives: May 2010

PHP: How To Get A Time Difference in Human Readable Format

A simple function to return the time since a given timestamp in the past. function time_since($timestamp) { // Init $hash = array(); $now = time(); // Breakdown the time diff $diff = $now – $timestamp; $hash['day'] = floor($diff / 86400); … Continue reading

Tagged , , , | 1 Comment

PHP: Pass By Reference vs. Pass By Value

By default, PHP is pass by value. <? function pass_by_value($param) { push_array($param, 4, 5); } $ar = array(1,2,3); pass_by_value($ar); foreach ($ar as $elem) { print "<br>$elem"; } ?> The code above prints 1, 2, 3. This is because the array … Continue reading

Leave a comment

Unusual Paragraph Problem

This is a most unusual paragraph. How quickly can you find out what is so unusual about it? It looks so ordinary that you would think that nothing is wrong with it at all, and, in fact, nothing is. But … Continue reading

Posted in Cool Problems | 1 Comment

Two Pots, One Treasure Problem

On the right, you see a silver and a golden pot. One of these pots contains a treasure and the other one is empty. Assume that you can determine from the text prints which pot contains the treasure. The text … Continue reading

Posted in Cool Problems | 1 Comment

Rich, Poor, Eating Problem

The poor have it, the rich want it, but if you eat it you will die. What is this?

Posted in Cool Problems | 1 Comment

Marble Weighing Problem

In front of you are 10 bags, filled with marbles. The number of marbles in each bag differs, but all bags contain ten marbles or more. Nine of the ten bags only contain marbles of 10 grams each. One bag … Continue reading

Posted in Cool Problems | 1 Comment

Camel Racing Problem

A long, long time ago, two Egyptian camel drivers were fighting for the hand of the daughter of the sheik of Abbudzjabbu. The sheik, who liked neither of these men to become the future husband of his daughter, came up … Continue reading

Posted in Cool Problems | 1 Comment

Death Sentence Problem

General Gasslefield, accused of high treason, is sentenced to death by the court-martial. He is allowed to make a final statement, after which he will be shot if the statement is false or will be hung if the statement is … Continue reading

Posted in Cool Problems | 1 Comment

Bridge Crossing Problem

Four men want to cross a bridge. They all begin on the same side. It is night, and they have only one flashlight with them. At most two men can cross the bridge at a time, and any party who … Continue reading

Posted in Cool Problems | 1 Comment

Pirate Ship Treasure Splitting

A pirate ship captures a treasure of 1000 golden coins. The treasure has to be split among the 5 pirates: 1, 2, 3, 4, and 5 in order of rank. The pirates have the following important characteristics: * Infinitely smart. … Continue reading

Posted in Cool Problems | 1 Comment

Colorful Dwarf Party

In a distant, dark forest, lives a population of 400 highly intelligent dwarfs. The dwarfs all look exactly alike, but only differ in the fact that they are wearing either a red or a blue hat. There are 250 dwarfs … Continue reading

Posted in Cool Problems | 1 Comment

Prisoner Hats, 3 Heads, 5 Hats

In a small village in the middle of nowhere, three innocent prisoners are sitting in a jail. One day, the cruel jailer takes them out and places them in a line on three chairs, in such a way that man … Continue reading

Posted in Cool Problems | 1 Comment

MySQL Best Data Types For Common Types Of Data

Primary Key : INT UNSIGNED – About 4.3 billion available IDs. Going unsigned gives you the extra 2 billion. Phone Number : VARCHAR – Phone numbers are identifiers that happen to use digits. – See this post. Price : FLOAT … Continue reading

Leave a comment