Paraffins
The purpose of this task is to count how many different paraffin molecules there are for a given number of carbon atoms. The molecules must be topologically different, so all reflections, etc. are counted once.
The input is just the number 'n' of carbon atoms of a molecule, like 17.
The output is how many different different paraffins there are with 'n' carbon atoms (like 24_894 if n = 17).
The sequence of those results can be seen in the Sloane encyclopedia.
The sequence is (the index starts from 1, and represents the number of carbon atoms):
1, 1, 1, 1, 2, 3, 5, 9, 18, 35, 75, 159, 355, 802, 1858, 4347, 10359, 24894, 60523, 148284, 366319, 910726, 2278658, 5731580, 14490245, 36797588, 93839412, 240215803, 617105614, 1590507121, 4111846763, 10660307791, 27711253769, ...
Extra credit: show the paraffins in some way. A flat 1D representation, with arrays or lists is enough, like:
<lang haskell>
- Main> all_paraffins 1
[CCP H H H H]
- Main> all_paraffins 2
[BCP (C H H H) (C H H H)]
- Main> all_paraffins 3
[CCP H H (C H H H) (C H H H)]
- Main> all_paraffins 4
[BCP (C H H (C H H H)) (C H H (C H H H)),CCP H (C H H H) (C H H H) (C H H H)]
- Main> all_paraffins 5
[CCP H H (C H H (C H H H)) (C H H (C H H H)),CCP H (C H H H) (C H H H) (C H H (C H H H)),CCP (C H H H) (C H H H) (C H H H) (C H H H)]
- Main> all_paraffins 6
[BCP (C H H (C H H (C H H H))) (C H H (C H H (C H H H))),BCP (C H H (C H H (C H H H))) (C H (C H H H) (C H H H)),BCP (C H (C H H H) (C H H H)) (C H (C H H H) (C H H H)),CCP H (C H H H) (C H H (C H H H)) (C H H (C H H H)),CCP (C H H H) (C H H H) (C H H H) (C H H (C H H H))]
</lang>
Showing a basic 2D ASCII-art representation of the molecules is even better.
A Scheme implementation: http://www.ccs.neu.edu/home/will/Twobit/src/paraffins.scm
A Haskell implementation: http://darcs.brianweb.net/nofib/imaginary/paraffins/Main.hs
An old paper that explains the functional code, with some molecules shown too: http://www.cs.wright.edu/~tkprasad/courses/cs776/paraffins-turner.pdf
There is a Fortress implementation too (turnersParaffins0.fss).