#1
  1. Put a potato on it!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Location
    Maryland
    Posts
    304
    Rep Power
    971

    Critical thinking


    I'm posting here because it's a pretty basic/general question. I found this story and after laughing at the logic behind it, thought it'd be fun to try the puzzle myself. I've figured out some of the meatier logic and what I have so far actually works pretty well, here's an overview:

    1. Ask for the number to convert
    4. Try to look up the digit in a dictionary of values (using python to write this), if the value is there, just return that, if not continue to step 4
    4. Break the digit down, so 23 would be 20 and 3, or XXIII.

    And here is where I'm getting stuck. When I look at a number like 23, I realize that that's really 10 + 10 + 3 and then I can write out XXIII. But to write that programmatically I need a way to tell the program to break it down similarly. I thought about just working in 10's. For example:

    Divide the number by 10, output the number of X's that would result from that. 44 / 10 would be 4.4 and that would be XXXX and then I'd have to deal with the remaining .4.

    This seems like a messy way to go and as I can go up to M or 1000, I would probably want to start by dividing by 1000?

    I guess critical thinking is not my strength here, and that's partly why I wanted to try and solve the problem. If anyone has some advice that'd be great. I might end up figuring this out through experimentation, but thought I'd ask.
    "Those who can make you believe absurdities can make you commit atrocities."
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Do it the same way you do "display the amount of time elapsed in days, hours, minutes, and seconds as necessary." Keep doing subtraction, starting from the largest value.

    So for 23:

    23 >10? yes

    print X, subtract 10.

    13 > 10? yes

    print X, subtract 10.

    3 > 10? no

    3 > 5? no

    print III


    Now, you have to figure out what to do for IV and VX and whatever. You can post-process a string, turning IIII into IV, or you can have a special case for "one unit of this less than the amount of one unit up from this"
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    I tried to do this, and then got distracted by work. You have to also note that the rules are contradictory. IX is 9, meaning 10-1. However, 99 is NOT IC, like you'd think, it's XCIX. But then 45 is VL. So good luck. Roman->arabic is much easier than arabic->roman.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. Put a potato on it!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Location
    Maryland
    Posts
    304
    Rep Power
    971
    Haha, work can be distracting. Thank you for the tip, I'll go with the subtraction and post-processing, something I tend to forget about when I work. I think as long as I can make my way through this part, I can do the rest, I just needed a different perspective.

    Yeah, Roman->Arabic is way easier, I was doing both conversions at the beginning than got stuck here.
    "Those who can make you believe absurdities can make you commit atrocities."
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    The inconsistent rules is why I gave up. Once I realized "99" is not represented the same as "9" and "49" I just said screw it and deleted what I had (which wasn't right anyway)
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. Put a potato on it!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Location
    Maryland
    Posts
    304
    Rep Power
    971
    Yeah, seeing as in the story it was a way to see how new hires think and work and in my case just for fun, I'm not going to lose sleep over it if I can't get it. At the very least I got more familiar with python syntax in the process.
    "Those who can make you believe absurdities can make you commit atrocities."

IMN logo majestic logo threadwatch logo seochat tools logo