Inane Patterns

I was just screwing around in ghci, playing with the pattern:

> sum [1..1000]
500500
> sum [1..100]
5050
> sum [1..10]
55
> sum [1..1]
1

And it was unfortunate to see the pattern “break” at [1..1]. The pattern being, sum [1..10^n] = 5 followed by (n-1) zeros followed by 5 followed by (n-1) zeros.

But check this out:

 5050 = (5 * 10^1) * 10^2 + (5 * 10^1)
 55   = (5 * 10^0) * 10^1 + (5 * 10^0)

Continuing the pattern…

 (5 * 10^-1) * 10^0 + (5 * 10^-1) = 0.5 * 1 + 0.5 = 1

So 1 is 5 followed by -1 zeros (itself zero digits, 1 for the 5 and -1 for the zeros, which is why we multiply by 10^0), followed by 5 followed by -1 zeros, and the pattern didn’t break. Woah…

Yeah, not mathematically deep, just kinda funny.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s