•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 402,793 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,860 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 335 | Replies: 7
![]() |
•
•
Join Date: Aug 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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
************************
# 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 : 29 Days Ago at 3: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
Let's Go Pens!
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:
Rep Power: 0
Solved Threads: 2
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 : 29 Days Ago at 1:57 pm.
•
•
Join Date: Aug 2008
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 1
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 Blog - paulthom12345.blogspot.com
Check out my Blog - paulthom12345.blogspot.com
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- 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 and Software Design)
- where to start with perl? (Perl)
Other Threads in the Python Forum
- Previous Thread: Convert " to \" and ' to \'
- Next Thread: Editing an image


Linear Mode