Paraffins: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created first draft of the Paraffins task)
 
m (Fix up description a little bit, I'm sure more could be done)
Line 1: Line 1:
{{draft task|Chemistry}}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.
{{draft task|Paraffins}}


The input is just the number 'n' of carbon atoms of a molecule, like 17.
The purpose of this Task is to count how many different paraffin molecules there are for a given number of Carbon atoms, or to actually show them. 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 [[oeis:A000602|Sloane encyclopedia]].
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 is in the Sloane encyclopaedia too, "Number of n-node unrooted quartic trees; number of n-carbon alkanes C(n)H(2n+2) ignoring stereoisomers":
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,
http://oeis.org/A000602
910726, 2278658, 5731580, 14490245, 36797588, 93839412, 240215803, 617105614, 1590507121, 4111846763,
10660307791, 27711253769, ...


The sequence is (the index starts from 1, it's the number of Carbon atoms):


'''Extra credit''': show the paraffins in some way. A flat 1D representation, with arrays or lists is enough, like:
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, ...


Stretch goal: show the paraffins in some way. A flat 1D representation, with arrays or lists is enough, like:


<lang haskell>
<lang haskell>
Line 41: Line 39:
Showing a basic 2D ASCII-art representation of the molecules is even better.
Showing a basic 2D ASCII-art representation of the molecules is even better.


A Scheme implementation:
A Scheme implementation: http://www.ccs.neu.edu/home/will/Twobit/src/paraffins.scm
http://www.ccs.neu.edu/home/will/Twobit/src/paraffins.scm


A Haskell implementation:
A Haskell implementation: http://darcs.brianweb.net/nofib/imaginary/paraffins/Main.hs
http://darcs.brianweb.net/nofib/imaginary/paraffins/Main.hs


An old paper that explains the functional code, with some molecules shown too:
An old paper that explains the functional code, with some molecules shown too: http://www.cs.wright.edu/~tkprasad/courses/cs776/paraffins-turner.pdf
http://www.cs.wright.edu/~tkprasad/courses/cs776/paraffins-turner.pdf


There is a Fortress implementation too (turnersParaffins0.fss).
There is a Fortress implementation too (turnersParaffins0.fss).

Revision as of 14:04, 30 November 2011

Paraffins is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

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).