On 2012-04-01, Florian Anderiasch <m...@anderiasch.de> wrote:
> Hey there,
> due to the widespread acceptance of binary number format (0b1010101) and
> the growing demand for backwards compatibility I've started to work on
> support for Roman Numerals (I, II, III, ...)
>
> As you might know, this format cannot be strictly parsed from left to
> right or right to left, as several number values need a look-ahead
> before being able to compute them (like IV), so my naive first
> implementation splits the string into tokens (like in 1990 = MCMXC =>
> M,CM,XC => 1000,900,90) then simplifying those 3 on their own, then
> adding the results, but I'm not sure this could kill performance if
> calculated inside zend_language_scanner.l.
Thanks for the work on it. I really appreciated and would love
to see roman numberes finally get implemented.

I think a fair asusmption is that there is a certain ordering.
First add numbers unless you encouter a higher or lower number:

 (1) in case current number == previous number, add it to your temp buffer
 (2) in case current number < previous number, add it to your temp buffer
 (3) in case current number > previous number, substract it from temp buffer

Obviously you need to check if hte number is valid too: IIVM is obviously wrong
But i think this is a good start.


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to