Mian-Chowla sequence: Difference between revisions

(→‎{{header|Haskell}}: Point-free form of Spoon!'s excellent edit.)
Line 680:
Terms 91 to 100 of the Mian-Chowla series:
[22526,23291,23564,23881,24596,24768,25631,26037,26255,27219]</pre>
 
=={{header|J}}==
 
<lang j>
NB. http://rosettacode.org/wiki/Mian-Chowla_sequence
 
NB. Dreadfully inefficient implementation recomputes all the sums to n-1
NB. and computes the full addition table rather than just a triangular region
NB. However, this implementation is sufficiently quick to meet the requirements.
 
NB. The vector head is the next speculative value
NB. Beheaded, the vector is Mian-Chowla sequence.
 
 
Until =: conjunction def 'u^:(0 = v)^:_'
unique =: -:&# ~. NB. tally of list matches that of set
 
next_mc =: [: (, {.) (>:@:{. , }.)Until(unique@:((<:/~@i.@# #&, +/~)@:(}. , {.)))
 
 
prime_q =: 1&p: NB. for fun look at prime generation suitability
</lang>
 
<pre>
NB. generate sufficient terms of sequence
 
A =: (next_mc^:108) 1 1
 
NB. first 30 terms
(,:prime_q)30{.}.A
1 2 4 8 13 21 31 45 66 81 97 123 148 182 204 252 290 361 401 475 565 593 662 775 822 916 970 1016 1159 1312
0 1 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0
 
NB. terms 91 through 100
(,: prime_q) A {~ 91+i.10
22526 23291 23564 23881 24596 24768 25631 26037 26255 27219
0 1 0 0 0 0 0 0 0 0
</pre>
 
=={{header|JavaScript}}==
Anonymous user