Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Programming challenges

  1. #1

    Programming challenges

    If anyone needs any programming challenges to try, check out the ones myself and the rest of the CS-Club at my Univ. had for some high school students in January:

    Anyway, they are harder than the ones we had last year, and the students made that known. We wanted to make sure that no team solved all the problems in the five hours allotted them, but that some of them were solved by all of them.

    It kind of worked, it kind of did not. The best teams solved four problems, and two teams solved none. Three problems were never solved (six, seven, and nine.)

    If you have any questions on the interpretation of the problem descriptions, please ask. I know that for one of the problems, the sample output for the sample input is incorrect, but I am not sure which one it is off the top of my head right now.

  2. #2
    Good Guru
    Schotty's Avatar
    Join Date
    Jul 2001
    Milwaukee, WI

    Re: Programming challenges

    I am going to try frist the three that nobody passed. I need to brush up on a few languages (c/c++/perl/lisp to be more specific).

    6,7,9 Here we go baby - YEAH!!

  3. #3

    Re: Programming challenges

    I'm on the Postfix calculator. I'll continue today and post the code when everthing works.

  4. #4

    Re: Programming challenges

    Here's my solution. *Not exactly the most elegant thing (I don't like the calculate function right now), but it works. *If I get a cuter version, I'll post it as well, but I don't think I'll rework on it though.

    #!/usr/bin/env python
    from __future__ import division
    import sys
    import string
    # This function takes every argument the user gave and: removes illegal
    # characters
    def correct(l):
     operators = ['+', '-', '/', '*']
     i = 0
     while i < len(l):
      if l[i].isdigit():
       i += 1
      elif l[i] in operators:
       i += 1
     return l
    # This functions makes sure that the last characyer is an operator, that the
    # first 2 characters are numbers and that there is one more number than
    # operators.
    def check(l):
     operators = ['+', '-', '/', '*']
     if not l[-1] in operators:
      print "Invalid Syntax"
      return 1
     if not (l[0].isdigit() and l[1].isdigit()):
      print "Invalid Syntax"
      return 1
     n_count, o_count = 0, 0
     for i in l:
      if i.isdigit():
       n_count += 1
       o_count += 1
     if not (n_count == o_count + 1):
      print "Invalid Syntax"
      return 1
    # This function will calculate the result of the equation and returns it
    def calculate(l):
     operators = ['+', '-', '/', '*']
     result = None
     # While loop here
     while l != [result]:
      new_l = []
      new_l.append(l[0]) # Append first number
      pos_op = len(l)
      for op in operators:
        if l.index(op) < pos_op:
         pos_op = l.index(op)
       except ValueError:
      new_l.append(l[1]) # Append second number
      del l[pos_op]
      del l[0]
      del l[0]
       result = str(eval("%s %s %s" % (new_l[0], new_l[1], new_l[2])))
      except SyntaxError:
       print "Invalid syntax"
      l.insert(0, result)
     return result
    if __name__ == '__main__':
     while 1:
       equation = raw_input('> ')
      except KeyboardInterrupt:
      except EOFError:
      if equation == "$":
      eq = equation.split(' ') # Make an list
      eq = correct(eq) # Remove unwanted chars
      # If eq is empty, ask for input again
      if eq == []:
      incorrect = check(eq)
      if incorrect: continue
      ans = calculate(eq)
      print ans
    EDIT: POsted cleaner version

  5. #5

    Re: Programming challenges

    Any comments?

  6. #6

    Re: Programming challenges

    Any comments?
    w00t... I don't understand a word of that code Vince... but it looks cool. My C++ teacher would kill you for not including flowcharts and design note

  7. #7

    Re: Programming challenges

    My C++ teacher would kill you for not including flowcharts and design note
    What is a flowchart? And design notes, you mean, how I solved the problem?

  8. #8

    Re: Programming challenges

    What is a flowchart? *And design notes, you mean, how I solved the problem?

  9. #9

    Re: Programming challenges

    Any comments?
    I just got done grading some assignments, and if I graded yours, I'd take five points off for having un-meaningful variable names (i.e. they need to be longer than a single letter), and five points off for not having your name, date, and program description. I'd also take a point off for having very few comments inside your functions.

  10. #10

    Re: Programming challenges

    Oh, I wasn't aware of these specifications. Anyway, I don't really care since I wasn't part of the contest and that I am doing it for fun.

Similar Threads

  1. Need Help with Network Programming
    By omidkamangar in forum Programming
    Replies: 1
    Last Post: 05-01-2006, 03:23 PM
  2. Microsoft Search Engine Challenges Google
    By genesis in forum Windows - General Topics
    Replies: 10
    Last Post: 02-04-2005, 09:21 PM
  3. Programming
    By imported_n00b in forum Announcements and Suggestions
    Replies: 12
    Last Post: 09-17-2004, 06:35 PM
  4. Programming
    By Asbenson in forum General Chat
    Replies: 34
    Last Post: 06-19-2004, 04:54 AM
  5. Programming Challenges
    By ndogg in forum Programming
    Replies: 1
    Last Post: 12-12-2001, 12:27 PM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts