This is play, so I post it here.
Interesting task (not yet approved as a task):
http://rosettacode.org/wiki/Paraffins
Two aspects:
1. Generating OEIS sequence A000602 in a more functional way then the C
solution
(I made a translation of the C solution)
NumOfParaffins 11
1 1 1 1 2 3 5 9 18 35 75
2. Showing the molecules in some 1D representation. For a start: here's
a list of the first radicals
radicalGen 3
┌─────┬────────┬──────────────┐
│┌───┐│┌──────┐│┌────────────┐│
││┌─┐│││┌────┐│││┌───┬──────┐││
│││H│││││CHHH│││││CHH│┌────┐│││
││└─┘│││└────┘││││ ││CHHH││││
│└───┘│└──────┘│││ │└────┘│││
│ │ ││└───┴──────┘││
│ │ │└────────────┘│
└─────┴────────┴──────────────┘
Someone interested?
Here's my translation of the C-solution for generating the sequence.
tree=: 3 :0
'mx br n rdc sum l'=. y
bs=. br+1
k=. n{ra
for_b. bs+i.4+1-bs do.
if. mx <: s=. sum + n*t=. b-br do. return. end.
c=. rdc *t !t+k-1
if. s > 2*l do. unr=: s (c+{)`[`]} unr end.
if. b=4 do. return. end.
ra=: s (c+{)`[`]} ra
for_m. (-i.)n-1 do. tree mx, b, m, c, s, l end.
end.
)
bicenter=: 3 :0
c=. -:(*>:) ra {~ -:y
unr=: y (c+{)`[`]} unr
)
NumOfParaffins=: 3 :0
if. 3>y do. y{.1 1 return. end.
ra=: 1 1, 0$~ y-2
unr=: 1 1, 0$~ y-2
(]`bicenter@.(0=2&|) [ tree@:(y, 0, ], 1,1,]))"0 >: i.y-1
unr
)
--
Met vriendelijke groet,
@@i = Arie Groeneveld
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm