published on in discrete mathematics programming

Bar-sized factorial

What’s the first five digits of 1,000,000! or 1 million factorial? Let’s ask Haskell:

Prelude> take 5 $ show $ product [1..1000000] 
"82639" 
(1043.56 secs, 1,444,511,743,624 bytes) 

Neat!

But you might ask, how many digits is this rather large number, of 1 bar factorial? Let’s ask again:

Prelude> length $ show $ product [1..1000000] 
5565709 
(1103.04 secs, 1,444,845,773,000 bytes) 

Wow! 5.5 million digits! Way more than all the electrons in the universe.

Those second timings is how long it took to compute, and bytes used is sort of like the amount of memory used, but not at once, more like in batches and then garbage collected.

I set it off, then left it running on spare compute in the background; hardly noticed anything.

What is the world coming too when you can compute stuff like that with one line of code…?

Haskell is something else; definitely the most interesting and powerful language I’ve come across thus far.

To be perfectly honest, it is about the third or fourth time round for me, trying to learn and actually use Haskell. Thus far I’m rather impressed.

Things are starting to click…