Posts

Showing posts from 2016

Shortest Code For Generating Prime Numbers

<?php for ($i = 1; $i < 1000; $i++) {     $print = TRUE;        // Optimized till square roots     for ($j = 2; ($j*$j) <= $i; $j++)     {         $print = FALSE;         if ($i % $j == 0)             break;                $print = TRUE;     }     if ($print)         print $i.','; } ?>

The Essence of Computer Programming

Computers are basically for the automation of repetitive work. So programming computers is essentially the art of automation of repetitive work using loops. Thus, the most essential thing one needs to understand to program computers is how to write loops. That covers everything essential. PS: Recursion is assumed here to just be a more advanced form of a loop, which is just a more elegant solution for certain types of problems.

C Code for Numerology 9999

Got a strange request from a friend: Generate all 4 digit numbers whose recursive sums evaluate to nine, and whose non-zero digits are in ascending order. Anyway, here's the code. First run as usual :-) Apart from a few syntax corrections. No logical errors. <?php for ($i = 9; $i < 10000; $i++) {     if (isAsc($i))     {         if (isSumNine($i))         {             if ($i < 10)                 print '000'.$i.PHP_EOL;             else if ($i < 100)                 print '00'.$i.PHP_EOL;             else if ($i < 1000)                 print '0'.$i.PHP_EOL;             else                 print $i.PHP_EOL;         }     } } function isSumNine($num) {     $temp = $num;     $sum = 0;     while ($temp > 0)     {         $sum += $temp % 10;         $temp = floor($temp / 10);     }     if ($sum > 9)         return isSumNine($sum);     else         return ($sum == 9); } function isAsc($num)

Easiest Way To Run Code on Mac OSX

Most links will tell you to install XCode so that you can use GCC to run C / C++ code. You don't need to. The easiest way is to use the existing PHP program on your Mac OSX.

The Software Industry and Computer Programmers

A google employee once wrote an article in which he said something like: "Often we would interview a programmer who had an incredible amount of knowledge on a wide range of subjects, but couldn't program Hello World in any language." It's really amazing how many people in the software industry simply know nothing about programming computers. We're talking about core technical people such as Product Managers - not people in unrelated departments such as marketing - who have big plans and strong opinions on everything related to technology, but lack basic technical skills. To put it in perspective, imagine an entire department of road planning where no one really knows to drive.

Tradeadexchange virus on Android - Only Solution

None of the other solutions online seem to work. The only solution seems to be: 1. Clear all browser caches completely (both in settings and in app info, to be sure) 2. Reset modem 3. Reset router (if different from the modem) ALL AT THE SAME TIME. The virus settles in the browser, and the modem + router. If any of the three is not clean, the virus seems to infect all three. There's no need to uninstall the browser or reset the phone.

The Flaw in AI Doomsday Predictions

  The first logical flaw in most AI doomsday prediction scenarios is the assumption that any AI will have the same instincts for survival that biological life does. The second is to underestimate man's own instinct for — and past record of — survival. The instinct for survival and procreation — and even the very idea of self or of a vast collection of cells as a single entity — is an artificial construct. It's just the software that enables the life form to maximize its ability to perform as the carrier and refiner of its genetic code. In fact, the very reason biological life forms have a finite lifespan is to allow for the continuous refinement of genetic code. Intelligence vs Survival Instincts Raw intelligence on its own is simply the ability to recognize and predict patterns. Biological life forms simply use this ability to implement their genetic programming. In fact, a number of biological species have no physical brain at all. They rely solely on their ge

Excerpts from Seth Klarman's preface to Security Analysis

  A curated list of the best quotes from Seth Klarman's 2008 Preface to the sixth edition of Benjamin Graham's book, Security Analysis . On Technology "In an era of rapid technological change, investors must be ever vigilant, even with regard to companies that are not involved in technology but are simply affected by it. In short, today's good businesses may not be tomorrow's." "Good businesses are generally considered those with strong barriers to entry, limited capital requirements, reliable customers, low risk of technological obsolescence, abundant growth possibilities, and thus significant and growing free cash flow." On Alternative Investments "In recent years, some people have attempted to expand the definition of an investment to include any asset that has recently-or might soon-appreciate in price: art, rare stamps, or a wine collection. Because these items have no as

The 12 best interactive Google Doodles

Image
1. Les Paul's 96th Birthday