Aliquot sequence classifications: Difference between revisions

m
(J solution)
Line 114:
aliquot =: [: +/ proper_divisors ::0:
rc_aliquot_sequence =: aliquot^:(i.16)&>
rc_classify =: [: {. ([;.1' terminate non-terminating perfect amicable sociable aspiring cyclic') #~ (6 > {:) , (([: +./ (2^47x)&<) +. (16 = #@:~.)) , (1 = #@:~.) , ((8&= , 1&<)@:{.@:(#/.~)) , ([: =/ _2&{.) , 1:
rc_classify =: 3 : 0
rc_display_aliquot_sequence =: (":,~' ',~_15{.rc_classify)@:rc_aliquot_sequence
assert 16 = # y
if. 6 > {: y do. 'terminate' return. end. NB. sequence ends in 0--5, strictly test for 0 only, but seriously...
COUNTS =: (#,{.)/.~ y
if. (+./ (2^47x) < y) +. 16 = # COUNTS do. 'non-terminating' return. end.
if. 1 = # COUNTS do. 'perfect' return. end.
if. 8 = (<0 0) { COUNTS do. 'amicable' return. end.
if. 1 < (<0 0) { COUNTS do. 'sociable' return. end.
if. =/ _2 {. y do. 'aspiring' return. end.
'cyclic'
)
rc_display_aliquot_sequence =: (":,~' ',~_15{.rc_classify)@:rc_aliquot_sequence
</lang>
<lang J>
rc_display_aliquot_sequence&> >: i.10
terminate terminate 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate terminate 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate terminate 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate terminate 4 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate terminate 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
perfect perfect 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
terminate terminate 7 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate terminate 8 7 1 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate terminate 9 4 3 1 0 0 0 0 0 0 0 0 0 0 0 0
terminate terminate 10 8 7 1 0 0 0 0 0 0 0 0 0 0 0 0
 
rc_display_aliquot_sequence&>11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488, 15355717786080x
terminate terminate 11 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
terminate terminate 12 16 15 9 4 3 1 0 0 0 0 0 0 0 0 0 ...
perfect perfect 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 ...
perfect perfect 496 496 496 496 496 496 496 496 496 496 496 496 496 496 496 496 ...
amicable amicable 220 284 220 284 220 284 220 284 220 284 220 284 220 284 220 284 ...
amicable amicable 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 ...
sociable sociable 12496 14288 15472 14536 14264 12496 14288 15472 14536 14264 12496 14288 15472 14536 14264 12496 ...
sociable sociable 1264460 1547860 1727636 1305184 1264460 1547860 1727636 1305184 1264460 1547860 1727636 1305184 1264460 1547860 1727636 1305184 ...
aspiring aspiring 790 650 652 496 496 496 496 496 496 496 496 496 496 496 496 496 ...
aspiring aspiring 909 417 143 25 6 6 6 6 6 6 6 6 6 6 6 6 ...
cyclic cyclic 562 284 220 284 220 284 220 284 220 284 220 284 220 284 220 284 ...
cyclic cyclic 1064 1336 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 ...
non-terminating 1488 2480 3472 4464 8432 9424 10416 21328 22320 55056 95728 96720 236592 459792 881392 882384 ...
non-terminating 15355717786080 44534663601120 144940087464480 471714103310688 1130798979186912 2688948041357088 6050151708497568 13613157922639968 35513546724070632 74727605255142168 162658586225561832 353930992506879768 642678347124409032 1125102611548462112510261154846...
</lang>
 
Anonymous user