| | |
Python challenge help
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 35
Reputation:
Solved Threads: 1
Hey guys im doing the NCSS python challenge and I need help!!
ok so here's my current problems (p.s. my teach cant even help)
PROBLEM 1
************************
I need code 2 ouput this .....
fibonacci
decrypt
helper
so pretty much i need help on callin function names ( I think)
PROBLEM 2
****************
UMTPORMHTRNSDCYTDTIEPREITIPATAGRAIBS
Hint
Yes, that is the whole question.
A very simple technique has been used to encrypt the message. When you decrypt it, you will know how to solve the problem.
It is not a substitution cipher. It's even simpler than that.
UHHHHHH HELP!!!
PROBLEM 3
***********************
Surprisingly, the SETI project has found alien life! They have been transmitting floating-point numbers to earth using a base-5 number system. The five characters for the digits in their system are the five English vowels, ordered alphabetically, so a=0, e=1, i=2, o=3, and u=4 (in decimal).
The aliens use a clever scheme without a separator between the integer and fractional part of the float. They use capital vowels for the integer part, followed by lowercase vowels for the fractional part.
For instance, IUae has an integer part IU and a fractional part ae. The corresponding floating point value in decimal is I*5 + U*1 + A/5 + E/25 = 2*5 + 4 + 0/5 + 1/25 = 14.04. Either the integer or fractional part may appear without the other.
Write a Python function called alien2float that converts a string in the alien number format into a Python float. When we call this function like this, this is what happens:
>>> alien2float("IUae")
14.039999999999999
Your function should return -1 when the string does not conform to the alien notation defined above.
>>> alien2float("iuAE")
-1
ok so here's my current problems (p.s. my teach cant even help)
PROBLEM 1
************************
Python Syntax (Toggle Plain Text)
# This is a Python file def fibonacci(n): return (n <= 1) and 1 or fibonacci(n-1) + fibonacci(n-2) def decrypt(s): def helper(s): return s[::-1] return helper(s)
I need code 2 ouput this .....
fibonacci
decrypt
helper
so pretty much i need help on callin function names ( I think)
PROBLEM 2
****************
UMTPORMHTRNSDCYTDTIEPREITIPATAGRAIBS
Hint
Yes, that is the whole question.
A very simple technique has been used to encrypt the message. When you decrypt it, you will know how to solve the problem.
It is not a substitution cipher. It's even simpler than that.
UHHHHHH HELP!!!
PROBLEM 3
***********************
Surprisingly, the SETI project has found alien life! They have been transmitting floating-point numbers to earth using a base-5 number system. The five characters for the digits in their system are the five English vowels, ordered alphabetically, so a=0, e=1, i=2, o=3, and u=4 (in decimal).
The aliens use a clever scheme without a separator between the integer and fractional part of the float. They use capital vowels for the integer part, followed by lowercase vowels for the fractional part.
For instance, IUae has an integer part IU and a fractional part ae. The corresponding floating point value in decimal is I*5 + U*1 + A/5 + E/25 = 2*5 + 4 + 0/5 + 1/25 = 14.04. Either the integer or fractional part may appear without the other.
Write a Python function called alien2float that converts a string in the alien number format into a Python float. When we call this function like this, this is what happens:
>>> alien2float("IUae")
14.039999999999999
Your function should return -1 when the string does not conform to the alien notation defined above.
>>> alien2float("iuAE")
-1
Last edited by Tekmaven; Aug 8th, 2008 at 4:42 pm. Reason: Code tags
Please use code tags when posting blocks of code, and icode tags when posting small snippets. This will make sure your formatting is not lost to the ether; and will also make your posts easier for us to read; thereby making it easier for us to help you. You can read up on code tags here
for PROBLEM 1, I suggest the following program
python Syntax (Toggle Plain Text)
#!/usr/bin/env python # printdef.py # prints the names of all function definitions found in a program # usage: python printdef.py myprogram.py from tokenize import generate_tokens, NAME def getDefSequence(programPath): tokens = generate_tokens(open(programPath, "r").readline) for token in tokens: if token[0] == NAME and token[1] == "def": func = tokens.next() if func[0] == NAME: yield func[1] if __name__ == "__main__": import sys programPath = sys.argv[-1] if programPath[-3:] != ".py": print "usage: printdefs.py <path to '.py' file>" sys.exit(-1) for name in getDefSequence(programPath): print name
•
•
Join Date: Jun 2008
Posts: 6
Reputation:
Solved Threads: 3
For question 2:
decrypted by using:
which give:
S U B M I T A P R O G R A M T H A T P R I N T S I D E C R Y P T E D I T
decrypted by using:
python Syntax (Toggle Plain Text)
str = "UMTPORMHTRNSDCYTDTIEPREITIPATAGRAIBS" count = 0 length = len(str)/2 while count<length: print str[len(str)-1-count], print str[count], count+=1
S U B M I T A P R O G R A M T H A T P R I N T S I D E C R Y P T E D I T
I give my solution for PROBLEM 3 in obfuscated python
python Syntax (Toggle Plain Text)
def alien2float(s): from bisect import bisect i = bisect(s, '[') seti = lambda z: reduce(lambda x, y: 5.0*x+y, map(dict(map(lambda(x, y): (y, x), enumerate("AEIOU"))).get, z)) try: if i: res = seti(s[:i]) else: res = 0.0 x = s[i:] if not x: return res elif not x.islower(): return -1 return res + seti(x.upper())/5**len(x) except TypeError: return -1
Last edited by Gribouillis; Aug 8th, 2008 at 2:57 pm.
•
•
Join Date: Aug 2008
Posts: 10
Reputation:
Solved Threads: 2
This is for problem 3.
The regular expression to catch invalid data needs to be modified. For valid data, the above code should work. It also doesn't check for "Either the integer or fractional part may appear without the other." Both must be present to work.
python Syntax (Toggle Plain Text)
import re def alien2float(n): match = re.match("([aeiou])([AEIOU])", n) if match: print "-1" exit() result = re.sub("([AEIOU])([aeiou])", "\\1.\\2", n) result = re.sub("A", "0", result) result = re.sub("E", "1", result) result = re.sub("I", "2", result) result = re.sub("O", "3", result) result = re.sub("U", "4", result) result = re.sub("a", "0", result) result = re.sub("e", "1", result) result = re.sub("i", "2", result) result = re.sub("o", "3", result) result = re.sub("u", "4", result) result = re.split("\.", result) lefthand = int(result[0], 5) righthand = list(result[1]) decimal = 0 count = 5 for a in righthand: decimal = decimal + (float(a) / (count)) count = count * 5 result = lefthand + decimal print result if __name__ == "__main__": alien2float("IUae")
The regular expression to catch invalid data needs to be modified. For valid data, the above code should work. It also doesn't check for "Either the integer or fractional part may appear without the other." Both must be present to work.
just quickly i wanted to remind Darkangel or the NCSS Challenge rules. Rule 3 stated that:
"The solutions you submit must be your own. It is fine to discuss the problems, and to read code in books or on web sites to get ideas, but you must be the author of any code you submit. It is not okay to copy anybody else's code and submit that as if it is your own."
This just means discuss it all you like but you are not allowed to directly use code that other people have made.
People at Daniweb just remember for this comp that people are not meant to do get direct answers.
"The solutions you submit must be your own. It is fine to discuss the problems, and to read code in books or on web sites to get ideas, but you must be the author of any code you submit. It is not okay to copy anybody else's code and submit that as if it is your own."
This just means discuss it all you like but you are not allowed to directly use code that other people have made.
People at Daniweb just remember for this comp that people are not meant to do get direct answers.
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
•
•
Join Date: Aug 2008
Posts: 35
Reputation:
Solved Threads: 1
•
•
•
•
just quickly i wanted to remind Darkangel or the NCSS Challenge rules. Rule 3 stated that:
"The solutions you submit must be your own. It is fine to discuss the problems, and to read code in books or on web sites to get ideas, but you must be the author of any code you submit. It is not okay to copy anybody else's code and submit that as if it is your own."
This just means discuss it all you like but you are not allowed to directly use code that other people have made.
People at Daniweb just remember for this comp that people are not meant to do get direct answers.
Thanx for the reminder but i just needed a lil help to get the jist of the solution. The questions were even alien to my teacher and he couldnt help so i had 2 ask somewhere
Im still learning and im a first year coder so be nice
![]() |
Similar Threads
- Projects for the Beginner (Python)
- Up for a challenge? Complete coding noob in need of help to code on mobile platform (Python)
- Creating a Python ANSII game (dos) (Python)
- Python Indentation (Python)
- Python for Birthday (but having tech difficulties) (Python)
- need help comparing bits (Python)
- A challenge for all newbies (Computer Science)
- where to start with perl? (Perl)
Other Threads in the Python Forum
- Previous Thread: looping through stck of images
- Next Thread: Perfect number - python
| Thread Tools | Search this Thread |
Tag cloud for Python
address anydbm app beginner cipher client code conversion coordinates curves development dictionary dynamic examples excel feet file float font format ftp function generator getvalue gui handling homework images import input ip java keycontrol line linux list lists loan loop maintain maze microcontroller millimeter mouse mysqldb newb number numbers output parsing path permissions port prime program programming projects py2exe pygame pymailer pyqt python queue random recursion recursive scrolledtext searchingfile shebang slicenotation socket split ssh string strings table terminal text thread threading time tkinter tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 variable variables vigenere web windows wx.wizard wxpython xlwt






