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
************************

# 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

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

#!/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

if you like the previous code, I'll put it in the code snippets :)

For question 2:
decrypted by using:

str =  "UMTPORMHTRNSDCYTDTIEPREITIPATAGRAIBS"
count = 0
length = len(str)/2
while count<length:
    print str[len(str)-1-count],
    print str[count],
    count+=1

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

I give my solution for PROBLEM 3 in obfuscated python

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

This is for problem 3.

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.

if you like the previous code, I'll put it in the code snippets :)

Yeah that was awesome, i had 2 adjust it for the comp but it helped THANX!!! lol noob i am ha ha :)

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 :P
Im still learning and im a first year coder so be nice

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.