Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old July 15th, 2003, 01:26 AM
Wizard2003's Avatar
Wizard2003 Wizard2003 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 206 Wizard2003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 29 m 24 sec
Reputation Power: 6
convert numbers from roman to arabic

Hi all,

the first goal is to write a programm in Python that conerts numbers from roman to arabic.
The second goal is that the program should be as short as possible.
I've written a program with a size of 206 byte.
Is it possible to write a shorter one?

Reply With Quote
  #2  
Old July 15th, 2003, 01:57 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
I wouldn't know of the top of my head, if you attach the program, maybe it can be optamised. Could you also give a brief explination of how the progam works.

Have fun,
Mark.

Reply With Quote
  #3  
Old July 15th, 2003, 02:48 AM
Wizard2003's Avatar
Wizard2003 Wizard2003 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 206 Wizard2003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 29 m 24 sec
Reputation Power: 6
OK ... here it is:

Code:
import sys;d={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}
l=[];r=0;l=map(lambda x:d[x],list(sys.argv[1]))
for n in range(len(l)-1):
  if l[n]<l[n+1]:
   l[n]=-l[n]
for m in l:
 r+=m
print r

Reply With Quote
  #4  
Old July 15th, 2003, 03:55 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
inline

You'll be hard pressed, that's a very compact pieces of code.

Code:
import sys;d={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}
l=[];r=0;l=map(lambda x:d[x],list(sys.argv[1]))
for n in range(len(l)-1):if l[n]<l[n+1]:l[n]=-l[n]
for m in l:r+=m
print r


try that, all ive really done is make some of the staments inline rather than using indented blocks. dont think ur gonna get much better. I havnt tested it so it doesnt work let me know. Why was the size so important anyway?

Hope this helps,
Mark.

Reply With Quote
  #5  
Old July 15th, 2003, 04:15 AM
Wizard2003's Avatar
Wizard2003 Wizard2003 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 206 Wizard2003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 29 m 24 sec
Reputation Power: 6
That doesn't work :-(
Code:
    for n in range(len(l)-1):if l[n]<l[n+1]:l[n]=-l[n]
                              ^
SyntaxError: invalid syntax


The size was important because it was a compitition on a Linux convention.
I was not there but a friend told me.
I just wanted to see if it is possible to write a shorter programm.
By the way every programming language was allowed.
The winner wrote a progamm that had less then 100 byte (with Haskell). With C++ I wrote a programm with 164 byte.

Reply With Quote
  #6  
Old July 15th, 2003, 04:25 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
This should work.

Ok, sorry, obviously you can't do more than one inline block that way. Oops, im sure there is a way of doing it but anyway, they this

Code:
import sys;d="I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}
l=[];r=0;l=map(lambda x:d[x],list(sys.argv[1]))
for n in range(len(l)-1):
  if l[n]<l[n+1]: l[n]=-l[n]
for m in l: r+=m
print r


If your going for size may i sugest perl, I've seen entire pages of code crushed down into a couple of lines. I don't see you getting this program much smaller. however if you were being clever you could write a module and call that (assuming they dont count modules as part of the programs).

This one should work, as before, let me know if it doesn't.

Hope this helps,
Mark.

Last edited by netytan : July 15th, 2003 at 04:27 PM.

Reply With Quote
  #7  
Old July 16th, 2003, 03:20 AM
Wizard2003's Avatar
Wizard2003 Wizard2003 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 206 Wizard2003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 29 m 24 sec
Reputation Power: 6
OK. It works ... the size is excactly 200 byte.
A friend of mine programmed it in perl.
His program has a size of 104 byte.
I thought you could code it in a smaller size in python but seeming impossible :-(

Reply With Quote
  #8  
Old July 16th, 2003, 09:16 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
The problem is that python relies on white space to denote blocks. i'm sure there is a way to write inline code but i couldnt tell you how off the top of my head simply because most people us python because of its easy to read style and maintainablity, by writing inline code you make the code less readable. On a size front perl will win, but then as i said i've seen a whole page smashed down into a few lines! it was nearly unreadable but for size.. you can obviously use modules in your code, it maybe be a bit of a cheat but write a module, plug it into your python version, and then call that, could get it under 20 bytes i think if you did it that way. if its against the rules for you to write the module, then ill pack it for u, so u "didnt write" the module lol. just an idea

Anyway have fun,
Mark.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > convert numbers from roman to arabic


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway