The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Other
> Beginner Programming
|
Critical thinking
Discuss Critical thinking in the Beginner Programming forum on Dev Shed. Critical thinking Beginner Programming forum discussing problems and solutions for just about any issue. Experienced programmers offer their help to those just starting out.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 19th, 2012, 02:04 PM
|
 |
We're trapped inside a game!
|
|
Join Date: Jul 2008
Location: Maryland
|
|
|
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."
|

April 20th, 2012, 10:54 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

April 20th, 2012, 12:46 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

April 20th, 2012, 03:06 PM
|
 |
We're trapped inside a game!
|
|
Join Date: Jul 2008
Location: Maryland
|
|
|
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.
|

April 20th, 2012, 03:38 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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)
|

April 20th, 2012, 04:02 PM
|
 |
We're trapped inside a game!
|
|
Join Date: Jul 2008
Location: Maryland
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|