Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Help with a Regex

by planetscape (Chancellor)
on May 07, 2005 at 04:44 UTC ( [id://454867]=note: print w/replies, xml ) Need Help??


in reply to Help with a Regex

Ok, my apologies - dyslexia has indeed caused me to make some mistakes in my desired output, as some have suspected.

Also, a few words of further explanation: I decided to use Roman Numerals because (a) it made for much shorter examples than my "real" data, and (b) I thought the "order" would be implicit (M = 1000 and comes "first", D = 500 and comes "second", etc.) I should definitely have explcitly stated why this is the "order" in which characters should be considered.

I am taking another look at my "desired" output to insure the dyslexia demons have been banished. Then I shall take a look at the proposed solutions and report back.

Thanks again for your wisdom and, of course, your patience, kind Monks!

Replies are listed 'Best First'.
Re^2: Help with a Regex
by demerphq (Chancellor) on May 07, 2005 at 11:14 UTC

    M = 1000 and comes "first", D = 500 and comes "second", etc.

    Sure, M is left most, and D is second left most. But your examples have contrary input. "XIX" => "....X.I" contradicts "IX" => "....X.." as far as I can tell.

    ---
    $world=~s/war/peace/g

      well... i got some suckie code (just woke up with a terrible hangover... too much free beer ;-) )
      but i think i understand it a bit more now... take the input string, look for the highest value (first time it's M, second time it's D), and start looking from that position for the next highest value (skipping of course the previous highest one).

      for the suckie code, here's the output:
      I => ......I ( ......I : Ok ) IV => .....V. ( .....V. : Ok ) V => .....V. ( .....V. : Ok ) VI => .....VI ( .....VI : Ok ) IX => ....X.. ( ....X.. : Ok ) X => ....X.. ( ....X.. : Ok ) XI => ....X.I ( ....X.I : Ok ) XIV => ....XV. ( ....X.I : Not Ok) XV => ....XV. ( ....XV. : Ok ) XVI => ....XVI ( ....XVI : Ok ) XIX => ....X.I ( ....X.I : Ok ) X => ....X.. ( ....X.. : Ok ) XL => ....X.. ( ...L... : Not Ok) LX => ...LX.. ( ...LX.. : Ok ) XC => ....X.. ( ..C.... : Not Ok) CLXIX => ..CLX.I ( ..CLX.I : Ok ) CDXLVI => .D..XVI ( .D..XVI : Ok ) MCMXCVI => M.C.XVI ( M.C.XVI : Ok ) MDCLI => MDCL..I ( MDCL..I : Ok )
      I think i know what to do, but my code is not really working as I expected.. or maybe I should wait till my hangover is ... over ;-)

      to ask a question is a moment of shame
      to remain ignorant is a lifelong shame

      I believe I have finally vanquished the Demons of Derval Byslexia...

      What I posted: _______________ I ......I IV .....V. V .....V. VI .....VI IX ....X.. X ....X.. XI ....X.I XIV ....XV. XV ....XV. XVI ....XVI XIX ....X.I X ....X.. XL ....X.. WRONG Should be: ...L... LX ...LX.. XC ....X.. WRONG Should be: ..C.... CLXIX ..CLX.I CDXLVI .D..XVI WRONG Should be: .D.L.VI MCMXCVI M.C.XVI MDCLI MDCL..I _______________

      Revised

      Desired Output: _______________ I ......I IV .....V. V .....V. VI .....VI IX ....X.. X ....X.. XI ....X.I XIV ....XV. XV ....XV. XVI ....XVI XIX ....X.I X ....X.. XL ...L... LX ...LX.. XC ..C.... CLXIX ..CLX.I CDXLVI .D.L.VI MCMXCVI M.C.XVI MDCLI MDCL..I _______________

      Now for me to figure out which monk-contributed code works with the revised output... I'm blind now, so...

      Updated: Fixed two relatively minor typos.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://454867]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found