September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,28 +1,14 @@
|
|||
USING: math kernel combinators math.ranges math.parser
|
||||
sequences io ;
|
||||
IN: nth
|
||||
USING: io kernel math math.order math.parser math.ranges qw
|
||||
sequences ;
|
||||
IN: rosetta-code.nth
|
||||
|
||||
: tens-digit ( n -- n ) 10 [ /i ] [ mod ] bi ;
|
||||
: 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 ;
|
||||
|
||||
: teens? ( n -- ? ) tens-digit 1 = ;
|
||||
|
||||
: non-teen-suffix ( n -- str )
|
||||
10 mod {
|
||||
{ 1 [ "st" ] }
|
||||
{ 2 [ "nd" ] }
|
||||
{ 3 [ "rd" ] }
|
||||
[ drop "th" ]
|
||||
} case ;
|
||||
|
||||
: ordinal-suffix ( n -- str )
|
||||
dup teens? [ drop 0 ] when non-teen-suffix ;
|
||||
|
||||
: join-suffix ( n -- str ) dup ordinal-suffix
|
||||
[ number>string ] dip append ;
|
||||
|
||||
: main ( -- )
|
||||
: n'th-demo ( -- )
|
||||
0 25 250 265 1000 1025 [ [a,b] ] 2tri@
|
||||
[ [ join-suffix ] map ] tri@
|
||||
[ [ bl ] [ write ] interleave nl ] tri@ ;
|
||||
[ [ n'th write bl ] each nl ] tri@ ;
|
||||
|
||||
MAIN: main
|
||||
MAIN: n'th-demo
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue