add MAIN: run-unix-factor to math.primes.factors

db4
Doug Coleman 2009-12-12 23:39:59 -06:00
parent 4cea294cfd
commit ae9bca2b1e
1 changed files with 15 additions and 1 deletions

View File

@ -1,7 +1,8 @@
! Copyright (C) 2007-2009 Samuel Tardieu.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays combinators kernel make math math.functions
math.primes math.ranges sequences sequences.product sorting ;
math.primes math.ranges sequences sequences.product sorting
io math.parser ;
IN: math.primes.factors
<PRIVATE
@ -49,3 +50,16 @@ PRIVATE>
group-factors [ first2 [0,b] [ ^ ] with map ] map
[ product ] product-map natural-sort
] if ;
: unix-factor ( string -- )
dup string>number [
[ ": " append write ]
[ factors [ number>string ] map " " join print ] bi*
] [
"factor: `" "' is not a valid positive integer" surround print
] if* ;
: run-unix-factor ( -- )
[ readln [ unix-factor t ] [ f ] if* ] loop ;
MAIN: run-unix-factor