Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion RTX2000 optimization
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bernd Paysan  
View profile  
 More options Nov 4 2012, 12:41 pm
Newsgroups: comp.lang.forth
From: Bernd Paysan <bernd.pay...@gmx.de>
Date: Sun, 04 Nov 2012 18:40:57 +0100
Local: Sun, Nov 4 2012 12:40 pm
Subject: Re: RTX2000 optimization

Marcel Hendrix wrote:
> The online version is around 35 lines, so I am really curious how
> Bernd got less than 16. Also, the online version does not work
> 'in reverse' and can't use HOLD, so I guess it was reworked.
> Below is my take.

That was my take on it (the timestamp is my last change to it which was
using <<# #> #>> nestable pictured numeric output):

\ roman numbers                                        07aug10py

Variable column#
: symbol ( off -- ) column# @ + s" IVXLCDM  " drop +  c@ hold ;
: oner   ( -- )    0  symbol ;
: fiver  ( -- )    1  symbol ;
: almost ( q -- )  1+ symbol  oner ;

: oners  ( n -- )  0 ?DO  oner  LOOP ;
: digit ( digit -- )  5 /mod over 4 =  IF  almost drop
  ELSE  swap oners  IF  fiver  THEN  THEN ;
: #r  ( digit -- digit' )  10 /mod swap  digit  2 column# +! ;
: roman ( number -- )
  column# off  <<# #r #r #r #r 0 #>  type #>> ;

This is slightly overfactored, so if you just want to have a low number
of lines, it becomes:

Variable column#
: symbol ( off -- ) column# @ + s" IVXLCDM  " drop +  c@ hold ;
: digit ( digit -- )  5 /mod over 4 =  IF  1+ symbol 0 symbol drop
  ELSE  swap 0 ?DO 0 symbol LOOP  IF  1 symbol  THEN  THEN ;
: #r  ( digit -- digit' )  10 /mod swap  digit  2 column# +! ;
: roman ( number -- )
  column# off  <<# #r #r #r #r 0 #>  type #>> ;

--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.