## Kentucky Lottery Pick 3 Expected Payout

The expected payouts for the Kentucky Lottery Pick 3 game have an interesting idiosyncrasy. Playing the special "Straight Box" play pays out better than a separate 50¢ straight and 50¢ box play.

All other plays average 60¢ per dollar played, but the straight box seems to be 65¢ and 70¢, depending on the numbers played. Maybe my spreadsheet is wrong somewhere in here:

## Entropy of iPhone headphone cables (an excuse to experiment with WP-LaTeX)

Why is it that iPhone earbuds seem to tangle with so many more hopeless tangles than any other cables?
$displaystyle frac{dS_{iPhoneCable}}{dt} gg frac{dS_{genericCables}}{dt}$

Of course, this whole exercise was an excuse to play with LaTeX and the WP-LaTeX plugin.

I also managed to find a nice LaTeX cheat sheet in the process.

I just found an awesome site describing some of the features in Google while looking for info on Google Calculator:  Google Guide

My first find was the Quick Reference: Google Calculator (Cheat Sheet).

I like this tip from Google Guide solutions to Calculator problems:

Compute the probability of your winning the lottery if you buy 1,000 tickets each bearing five distinct independently randomly chosen integers between 1 and 99.

The following answer was contributed by Nelson Blachman (Nancy's father).

You might try [ 1 - (1 - 1/(99 choose 5))^1000 ], but this is well approximated by [ 1000/(99 choose 5) ], which is roughly 0.00001 . If each ticket costs \$1, the prize had better be at least \$100 million to be fair to you — and higher if you might have to share the prize with other winners.

While I was on that train of thought, I found the Lottery Mathematics entry on Wikipedia.

Also...  I've always wanted to figure out the probability calculation for various poker hands.

## Optimized prime number generator

Same specs as previous system, 8 hours to find all primes to ULONG_MAX.

`#include <stdio.h>#include <malloc.h>#include <limits.h>#include <math.h>struct linked_list{    unsigned long number;    struct linked_list *next;};int main(int argc, char **argv){    unsigned long divisor, max_divisor, prime_test;    unsigned long max_prime_to_store;    struct linked_list *first=NULL, *current=NULL, *last=NULL;    first=(struct linked_list *)malloc(sizeof(struct linked_list));    first->number = 2L;    first->next = NULL;    last = first;    printf("%lun", 2L);    max_prime_to_store = 1L + sqrt(ULONG_MAX);    for(prime_test = 3L; prime_test < ULONG_MAX; prime_test+=2L)    {        max_divisor=1L+sqrt(prime_test);        for(current = first; current && current->number <= max_divisor; current = current->next)        {            if(prime_test % current->number == 0)            {                break;            }        }        if(!current || current->number > max_divisor)        {            if(prime_test <= max_prime_to_store)            {                last->next = (struct linked_list *)malloc(sizeof(struct linked_list));                last = last->next;                last->next = NULL;                last->number = prime_test;            }            printf("%lun", prime_test);        }    }    return 0;}`

## I miss C programming. Program to find prime numbers

Uses unsigned long long, goes up to ULONG_LONG_MAX.

Intel Core Duo 2 processor, running Cygwin on Windows XP, and compiled using gcc 3.4.4. Stops at first million results due to time. Can reasonably get to 10 million, if you're willing to wait.

`#include <stdio.h>#include <math.h>#include <limits.h>int main(int argc, char **argv){    unsigned long long divisor, max_divisor, prime_test;    int break_time = 0;    printf("%llun", 2LL);    for(prime_test = 3LL; prime_test < ULONG_LONG_MAX; prime_test+=2LL)    {        max_divisor=1LL+sqrt(prime_test);        for(divisor=3LL;divisor <= max_divisor; divisor+=2LL)        {            if(prime_test % divisor == 0)            {                break;            }        }        if(divisor >= max_divisor)        {            printf("%llun", prime_test);        }        else        {            continue;        }        break_time++;        if(break_time == 999999)        {            break;        }    }    return 0;}`