Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #42478
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Decoding Roman numerals |
| Date | 2015-10-09 06:09 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <mv7lls$luf$1@dont-email.me> (permalink) |
| References | <mepsj9$ufr$1@dont-email.me> |
WJ wrote:
> Oforth:
>
> func: char-val {| i |
> toUpper "IVXLCDM" indexOf -- -> i
> 5 i 2 rem pow 10 i 2 / pow * }
>
> func: sign(n, prev) { n prev - ++ sgn n * }
>
> func: think( n, prev, total ) { prev n sign total + n prev max }
>
> func: decode {
> reverse map( #char-val )
> 0 0 rot apply( #think )
> drop }
Updated for OFORTH version V0.9.21.
: char-val {| i |
toUpper "IVXLCDM" indexOf 1 - -> i
5 i 2 mod pow 10 i 2 / pow * }
: sign(n, prev) { n prev - 1 + sgn n * }
: think( n, prev, total ) { prev n sign total + n prev max }
: decode {
reverse map( #char-val )
0 0 rot apply( #think )
drop }
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Decoding Roman numerals "WJ" <w_a_x_man@yahoo.com> - 2015-10-09 06:09 +0000
Re: Decoding Roman numerals "WJ" <w_a_x_man@yahoo.com> - 2015-10-09 06:19 +0000
Re: Decoding Roman numerals Doug Hoffman <glidedog@gmail.com> - 2015-10-09 07:36 -0400
Re: Decoding Roman numerals Doug Hoffman <glidedog@gmail.com> - 2015-10-09 08:05 -0400
csiph-web