Mian-Chowla sequence: Difference between revisions

Add Factor
(Add Swift)
(Add Factor)
Line 550:
22526 23291 23564 23881 24596 24768 25631 26037 26255 27219
</pre>
 
=={{header|Factor}}==
<lang factor>USING: fry hash-sets io kernel math prettyprint sequences sets ;
 
: next ( seq sums speculative -- seq' sums' speculative' )
dup reach [ + ] with map over dup + suffix! >hash-set pick
over intersect null?
[ swapd union [ [ suffix! ] keep ] dip swap ] [ drop ] if
1 + ;
 
: mian-chowla ( n -- seq )
[ V{ 1 } HS{ 2 } [ clone ] bi@ 2 ] dip
'[ pick length _ < ] [ next ] while 2drop ;
 
100 mian-chowla
[ 30 head "First 30 terms of the Mian-Chowla sequence:" ]
[ 10 tail* "Terms 91-100 of the Mian-Chowla sequence:" ] bi
[ print [ pprint bl ] each nl nl ] 2bi@</lang>
{{out}}
<pre>
First 30 terms of the Mian-Chowla sequence:
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
 
Terms 91-100 of the Mian-Chowla sequence:
22526 23291 23564 23881 24596 24768 25631 26037 26255 27219
</pre>
 
=={{header|Go}}==
<lang go>package main
1,808

edits