It's part of the proceedings of the 2nd Web Audio conference which are now available:
In particular, the two most consonant (best-sounding) intervals are the octave and the fifth. The frequencies of the two pitches in an octave have a ratio of 2.0, and the frequencies of the two pitches in a pure fifth have a ratio of 1.5.
We would like the pitches we obtain from powers of these two ratios (stacking these intervals on top of each other) to be the same. However, since the integers are a unique factorization domain, they will never be (except for 2^0 = 1 = 1.5^0, of course). 
Thus, we pick powers of the two that are 'close enough' and call those the same pitch. The following Python (3) code subtracts the log-base-two of the powers of 1.5 from the integer they round to in order to find the closest ones:
from math import log
fifth = log(3/2, 2.0)
minDist = 0.08
for i in range(1,100):
pow = i* fifth;
dist = abs(pow - round(pow))
if dist < minDist:
minDist = dist
print(i, pow, dist)
5 2.924812503605781 0.07518749639421918
12 7.019550008653875 0.019550008653874684
41 23.983462529567404 0.01653747043259557
53 31.003012538221277 0.003012538221277339
(As an aside, a scale with 5 notes is also common around the world, called the pentatonic scale )
 For an explanation of this, see http://blogs.scientificamerican.com/roots-of-unity/the-sadde...
There are two main reasons. The first is a matter of switching between scales, as in, many songs will modulate to out-of-scale-but-mathematically-related chords. As 12TET has each scale using the same notes, one doesn't have to tiptoe around shared notes which are 'slightly' off. The second is pure convenience: using a set of notes for each key (or pushing the root note a few Hz up or down) would be a laborious process.
With that being said, an interesting direction some electronic producers take is to experiment with scales, given how ubiquitous waveforms with integer harmonics are. Here's an example from Richard D James:
Instead of tuning perfect fifths, you just make every half step the same. That means that your other intervals are all out of tune, but it is small enough that you don't have some keys that are horrible. Bach's 24 preludes and fugues (in each major and minor key) was partly a demonstration of a similar tuning system--well tempered, also known as Werkmeister.
Other music traditions such as indian classical/raga, use different tunings.
I'll also add that the all-key tunings like equal and well tempered are hugely important for the development of music from back to today, its not mere esoterica. Look at something like a late Beethoven piano sonata. In the course of a single piece, it may modulate a hundred times through a half dozen keys. The development of all key tunings, while they made 5ths worse, made it possible for a pieces of music on a fixed tuning instrument like a piano to range through any key, and that was huge to the development of music.
"Nice-sounding" intervals have small integer frequency ratios.
It so happens that 3/2 = 1.5 is very close to 2^(7/12) = 1.498, 4/3 = 1.333 is very close to 2^(5/12) = 1.335, and 5/4 = 1.25 is very close to 2^(4/12) = 1.260. So 12 works very well as the number of pitches to divide an octave into.
The fact that 12 is highly divisible is handy for certain aspects of music composition. For example, if you have a diminished seventh chord, which consists of every third pitch, due to its symmetry you can think of it as being in any of four different keys. So it is easy to use it to pivot from one key to another. But none of that has to do with the reasons that it sounds good.
1. Harmonic intervals in 12TET are good enough to sound okay with no obvious sour notes.
2. Hand and finger size.
Factors and primes aren't the issue - it's how closely the octave divisions approximate perfect whole-number interval ratios.
12TET hits the sweet spot. The tuning is close enough for practical keyboard and fretted instruments to cover a wide pitch range but still fit human hand and finger sizes. So they're not impossibly difficult to make, tune, and learn, but you can still make complicated music on them.
Finer subdivisions like 19TET - or more - are closer still to the ratios, but you need computers and electronics to make practical instruments. Or highly skilled string players:
It's too in-depth to summarize, but worth a read.
You don't even need to compute new samples. Merely repeat the last sample while lowering its volume until you reach zero.
Z-R-V-Z-R-B-Z-R-N-Z-R-B-Z-R-V is a nifty little arrangement.
Made me look it up: https://en.wikipedia.org/wiki/Perlin_noise