RosettaCodeData/Task/Nth/Factor/nth.factor

15 lines
350 B
Factor
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
USING: io kernel math math.order math.parser math.ranges qw
sequences ;
IN: rosetta-code.nth
2016-12-05 22:15:40 +01:00
2019-09-12 10:33:56 -07:00
: n'th ( n -- str )
dup 10 /mod swap 1 = [ drop 0 ] when
[ number>string ]
[ 4 min qw{ th st nd rd th } nth ] bi* append ;
2016-12-05 22:15:40 +01:00
2019-09-12 10:33:56 -07:00
: n'th-demo ( -- )
2016-12-05 22:15:40 +01:00
0 25 250 265 1000 1025 [ [a,b] ] 2tri@
2019-09-12 10:33:56 -07:00
[ [ n'th write bl ] each nl ] tri@ ;
2016-12-05 22:15:40 +01:00
2019-09-12 10:33:56 -07:00
MAIN: n'th-demo