Skip to content

Commit

Permalink
factors: classifying numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Aug 28, 2011
1 parent acf77de commit 5c873b3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions factors/factors.factor
@@ -0,0 +1,26 @@
! Copyright (C) 2011 John Benediktsson.
! See http://factorcode.org/license.txt for BSD license.

USING: kernel math math.functions math.ranges math.vectors
sequences sets ;

IN: factors

: factor? ( m n -- ? )
mod zero? ;

: factors ( n -- seq )
dup [1,b] [ factor? ] with filter ;

: factors' ( n -- seq )
dup sqrt ceiling >integer factors
[ n/v ] keep append members ;

: check-factors ( n quot: ( m n -- ? ) -- ? )
[ [ factors sum ] [ - ] ] dip tri ; inline

: perfect? ( n -- ? ) [ = ] check-factors ;

: abundant? ( n -- ? ) [ > ] check-factors ;

: deficient? ( n -- ? ) [ < ] check-factors ;

0 comments on commit 5c873b3

Please sign in to comment.