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:
http://www.uwosh.edu/cs_club/activities/hsprog/2002/

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. ## 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. ## Re: Programming challenges

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

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.

Code:
```#!/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 &lt; len(l):
if l[i].isdigit():
i += 1
elif l[i] in operators:
i += 1
else:
l.remove(l[i])

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 &quot;Invalid Syntax&quot;
return 1

if not (l[0].isdigit() and l[1].isdigit()):
print &quot;Invalid Syntax&quot;
return 1

n_count, o_count = 0, 0

for i in l:
if i.isdigit():
n_count += 1
else:
o_count += 1

if not (n_count == o_count + 1):
print &quot;Invalid Syntax&quot;
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:
try:
if l.index(op) &lt; pos_op:
pos_op = l.index(op)
except ValueError:
continue

new_l.append(l[pos_op])
new_l.append(l[1]) # Append second number

del l[pos_op]
del l[0]
del l[0]

try:
result = str(eval(&quot;%s %s %s&quot; % (new_l[0], new_l[1], new_l[2])))
except SyntaxError:
print &quot;Invalid syntax&quot;
sys.exit(1)

l.insert(0, result)

return result

if __name__ == '__main__':

while 1:
try:
equation = raw_input('&gt; ')
except KeyboardInterrupt:
break
except EOFError:
break

if equation == &quot;\$&quot;:
break

eq = equation.split(' ') # Make an list
eq = correct(eq) # Remove unwanted chars

# If eq is empty, ask for input again
#
if eq == []:
continue

incorrect = check(eq)
if incorrect: continue

ans = calculate(eq)
print ans```
EDIT: POsted cleaner version

6. ## Re: Programming challenges

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. ## 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. ## Re: Programming challenges

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

9. ## Re: Programming challenges

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. ## 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.

#### Posting Permissions

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