June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,27 +1,37 @@
|
|||
import: mapping
|
||||
import: quicksort
|
||||
import: math
|
||||
|
||||
Object method: sum ( coll -- m )
|
||||
#+ self reduce dup ifNull: [ drop 0 ] ;
|
||||
|
||||
Integer method: properDivs
|
||||
| i l |
|
||||
ListBuffer new dup add(1) ->l
|
||||
2 self nsqrt tuck for: i [ self i mod ifFalse: [ l add(i) l add(self i / ) ] ]
|
||||
sq self == ifTrue: [ l removeLast drop ]
|
||||
l sort ;
|
||||
Array new dup 1 over add ->l
|
||||
2 self nsqrt tuck for: i [ self i mod ifFalse: [ i l add self i / l add ] ]
|
||||
sq self == ifTrue: [ l pop drop ]
|
||||
dup sort
|
||||
;
|
||||
|
||||
: aliquot(n) // ( n -- aList ) : Returns aliquot sequence of n
|
||||
: aliquot( n -- [] ) \ Returns aliquot sequence of n
|
||||
| end l |
|
||||
2 47 pow ->end
|
||||
ListBuffer new dup add(n) dup ->l
|
||||
while (l size 16 < l last 0 <> and l last end <= and) [ l last properDivs sum l add ] ;
|
||||
Array new dup n over add ->l
|
||||
while ( l size 16 < l last 0 <> and l last end <= and ) [ l last properDivs sum l add ]
|
||||
;
|
||||
|
||||
: aliquotClass(n) // ( n -- aList aString ) : Returns aliquot sequence and classification
|
||||
: aliquotClass( n -- [] s ) \ Returns aliquot sequence and classification
|
||||
| l i j |
|
||||
n aliquot dup ->l
|
||||
l last 0 == ifTrue: [ "terminate" return ]
|
||||
l second n == ifTrue: [ "perfect" return ]
|
||||
l third n == ifTrue: [ "amicable" return ]
|
||||
3 l at n == ifTrue: [ "amicable" return ]
|
||||
l indexOfFrom(n, 2) ifNotNull: [ "sociable" return ]
|
||||
|
||||
l size loop: i [
|
||||
l indexOfFrom(l at(i), i 1 +) -> j
|
||||
j i 1 + == ifTrue: [ "aspiring" return ]
|
||||
l indexOfFrom(l at(i), i 1+ ) -> j
|
||||
j i 1+ == ifTrue: [ "aspiring" return ]
|
||||
j ifNotNull: [ "cyclic" return ]
|
||||
]
|
||||
"non-terminating" ;
|
||||
"non-terminating"
|
||||
;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue