OK. Anyway, I'm working on Snaggy's list right now. It looks much tougher.
The assignments were seperate from the contest. *We didn't look at any code during the contest. *I was just making a point on coding style. *I am trying to root out as much bad coding style in this world as I can. This is often the first step to debugging.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.
OK. Anyway, I'm working on Snaggy's list right now. It looks much tougher.
going to atempt the postfix calc now, the only way I know how: PHP
I don't realy hold out much hope, but it'll be fun (and yes Lovechild, I have a flowchart :P)
Heh! I took me 2 minutes to solve a problem from 1996 (the n! one)
Code:#!/usr/bin/env python def fact(number): total = 1 for i in xrange(1, number+1): total *= i return total def count(number): return len(str(number)) if __name__ == '__main__': num = None while num != 0: num = input("Enter a number: ") print count(fact(num))
Leap year is done too:
Code:#!/usr/bin/env python import time def leap(year): if year % 400 == 0: return "%d is a leap year" % year elif year % 100 == 0: return "%d is not a leap year" % year elif year % 4 == 0: return "%d is a leap year" % year else: return "%d is not a leap year" % year if __name__ == '__main__': current_year = int(time.strftime("%Y")) year = None while year != current_year: year = input("Enter a year: ") print leap(year)
The barred entry program:
Code:#!/usr/bin/env python if __name__ == '__main__': entries = [None]*8 for i in xrange(8): entries[i] = input("Enter #%d: " % (i+1)) for entry in entries: print "W"*entry
Bounding primes:
I'm on fire, am I not? ;DCode:#!/usr/bin/env python import math, sys def isPrime(n, sqroot): *for x in xrange(2, sqroot+1): * *if n % x == 0: * * *return 0 *return 1 def find_lower(n): *test = n-1 *is_prime = 0 *while not is_prime: * *if isPrime(test, math.sqrt(test)): * * *is_prime = 1 * * *break * *test -= 1 *return test def find_higher(n): *test = n+1 *is_prime = 0 *while not is_prime: * *if isPrime(test, math.sqrt(test)): * * *is_prime = 1 * * *break * *test += 1 *return test if __name__ == '__main__': *number = input("Enter a number: ") *low = find_lower(number) *high = find_higher(number) *print "%d is bounded by the prime numbers %d and %d." % (number, low, high)
1999, squares problem:
Code:#!/usr/bin/env python def squares(size): number = 0 for i in xrange(1, size+1): number += i*i return number if __name__ == '__main__': size = None while size != 0: size = input("Enter board size: ") if size == 0: break print "A %dx%d board contains %d squares of any size" % (size, size, squares(size))
Vince, you're a machine!
I'm still ironing out bugs from 1 + 2 >![]()
You guys ought know that these high schoolers have only five hours to solve as many problems as they can. *Last year, we presented them with eight problems total, and one team (they can have teams of up to three persons each team) solved all eight problems in the alotted time.
Now, I go to an intercollegiate contest (the ACM Intercollegiate Programming Contest to be precise) and these are relatively simple in comparison.
This past year, my team took fifth place in our region. Here is a link where you guys will be able to see our standings (the UW-Oshokosh Binary Trees.) You'd be able to see the problems if that page wasn't screwed up.
Bookmarks