Login | Register

Nerd Paradise

a2 = b2 + c2 - 2bc * cos(θ)
The Forum > Technology > NP Python Olympiad
I've created a #npcc on IRC. I'll be watching this channel for any clarifying questions or technical issues you may have.

Contest begins in 27 minutes.
[Quote] [Link]
Omni is the winner!

Final scores

Thanks to everyone who participated!
[Quote] [Link]
Why does Deckmaster have a higher score?

Edit: Are those penalties or something?
[Quote] [Link]
Yeah, winner is the lowest penalty among the highest problems-solved.
[Quote] [Link]
I see. Looks like it was a close competition!
[Quote] [Link]
The score is the total number of seconds it took to solve all the problems you got correct + 600 for each wrong answer submitted. So lower is better.
[Quote] [Link]
Blake, this was a ton of fun. Thank you!
[Quote] [Link]
It looked like it was fun. I might participate if there is another one.
[Quote] [Link]
It does look cool. I think I would, too.
[Quote] [Link]
I would have to review what little Python I've learned and probably learn a lot more. Right now I'm only really familiar with C++ (and TI-Basic :P).
[Quote] [Link]
Those challenges are quite a good way to learn the basics of a new programming language. I think I'll make most of them :)
[Quote] [Link]
Depending on the problem set, they can also be very good for learning to estimate. You'll typically find at least one problem which is impossible, and one that is possible but will likely take so long that you'd be better off working on something else.
[Quote] [Link]
gws said:
Depending on the problem set, they can also be very good for learning to estimate. You'll typically find at least one problem which is impossible, and one that is possible but will likely take so long that you'd be better off working on something else.


The one I wasted all of my time on was the stupid ransom note one, which I eventually did correctly, but not without more debugging than I wanted to over spacing. :/

If anyone is interested in seeing the code I wrote, here are my solutions:

"Go the distance"
#!/usr/bin/python

import sys
import math

data = sys.stdin.readlines()

coords = []
for line in data[1:]:
  coords.append(line.split("\t"))

length=0
for i in range(int(data[0])-1):
  length += math.sqrt((int(coords[i][0])-int(coords[i+1][0]))**2 + (int(coords[i][1])-int(coords[i+1][1]))**2)

print length


Claustrophobia (unfinished)
#!/usr/bin/python

import sys

data = sys.stdin.readlines()

x = data[0]
y = data[1]

edges = []
for line in data[2:-1]:
  edges.append(line.split("\t"))

interior = data[-1].split("\t")

size=1

visited=[interior]
tested=[]

keepgoing = False

while (keepgoing): 
  for i in visited:
    if i[0]
#at this point I gave up because I was wasting time


"Piecing together a ransom note"
#!/usr/bin/python

import sys

data = sys.stdin.readlines()

letters = []
for i in data:
  letters.append(i.split("\t"))

for i in range(len(letters)):
  if len(letters[i]) > 1:
    letters[i][0] = int(letters[i][0])
    letters[i][1] = int(letters[i][1])
    letters[i][2] = letters[i][2][:-1]
  else:
    letters = letters[:i]
    break

maxx = 0
maxy = 0
for i in letters:
  if i[0] > maxx:
    maxx = i[0]+1
  if i[1] > maxy:
    maxy = i[1]+1


coords = [ [" "] * (maxx + 1) for i in range(maxy+1)]

for i in letters:
  coords[i[1]][i[0]] = i[2]

message = ""

for i in coords:
  lastspace = False
  firstletter = True
  for j in i:
    if j != " ":
      message += j
      lastspace = False
      firstletter = False
    elif (not lastspace and not firstletter):
      message += " "
      lastspace = True

print message


Prime means first
#!/usr/bin/python

import sys
import math
 
data = sys.stdin.readlines()

for i in data:
  try:
    i = int(i)
    factors = []
    for j in range(i):
      j+=2
      while (i%j == 0):
        factors.append(j)
        i /= j
    for r in range(len(factors)):
      if r+1 < len(factors):
        print "%d," % factors[r],
      else:
        print factors[r]
  except:
    pass


"Omni will like this one"
For the record, this is the one I had the most failed attempts on. :(
#!/usr/bin/python

import sys

def makecollatz(a):
  result = [a]
  value = a
  while(value != 1):
    if (value % 2 == 0):
      value = value/2
      result.append(value)
    else:
      value = 3*value+1
      result.append(value)
  return result

def main():
  data = sys.stdin.readlines()
  tests = []
  for i in data:
    tests.append(i.split("\t"))

  for i in tests:
    if len(i) > 1:
      a = makecollatz(int(i[0]))
      b = makecollatz(int(i[1]))
      k = -1
      while (a[k] == b[k] and -1*k != len(a) and -1*k != len(b)):
        k -= 1
      if (-1*k == len(a) or -1*k == len(b)):
        print a[k]
      else:
        print a[k+1]

if __name__ == "__main__":
  main()


"This one's easy, too"
#!/usr/bin/python

import sys

def main():
  data = sys.stdin.readlines()

  for i in range(len(data)-1):
    for j in data[i+1:]:
      if (j == data[i]):
        print j
        return
       
if __name__ == "__main__": 
  main()


"No Sally, I don't want your stinkin beans"
#!/usr/bin/python

import sys

data = sys.stdin.readlines()

for i in data:
  ops = i.split(" ")
  if len(ops) > 1:
    result = int(ops[0])
    for j in range((len(ops)-1)/2):
      if ops[j*2+1] == "+":
        result += int(ops[j*2+2])
      elif ops[j*2+1] == "-":
        result -= int(ops[j*2+2])
      elif ops[j*2+1] == "*":
        result *= int(ops[j*2+2])
      elif ops[j*2+1] == "/":
        result /= int(ops[j*2+2])
    print result


Any questions I'll explain.
[Quote] [Link]
What's that if-name-is-main business? Why wrap all the main logic up like that instead of just doing it?
[Quote] [Link]
gws said:
What's that if-name-is-main business? Why wrap all the main logic up like that instead of just doing it?


I should have two functions in that one. It didn't really save on typing, but it's good coding practice and takes like half a second.
[Quote] [Link]
Currently, I'm making a text-based adventure in Python. It's a scene-branching style, mainly because I don't know how to make a parser or want to make one
[Quote] [Link]
I like the prime factorization problem!
[Quote] [Link]
Cosman246 said:
Currently, I'm making a text-based adventure in Python. It's a scene-branching style, mainly because I don't know how to make a parser or want to make one

Parsers are a very interesting field to get into.
[Quote] [Link]
gws said:
Cosman246 said:
Currently, I'm making a text-based adventure in Python. It's a scene-branching style, mainly because I don't know how to make a parser or want to make one

Parsers are a very interesting field to get into.

I'm sure they are, but this is just a small project done in a bottom-up style. I suppose that if I figure out how to, I could write an elementary parser for basic tasks, like checking the inventory, but not much for now.
[Quote] [Link]
gws said:
Cosman246 said:
Currently, I'm making a text-based adventure in Python. It's a scene-branching style, mainly because I don't know how to make a parser or want to make one

Parsers are a very interesting field to get into.

Very hard.

Time flies like an arrow.
Fruit flies like a banana.

Is "Time" an adjective or noun? How do we know that? What about "Fruit"? Is "flies" a noun or a verb? Is "like" a verb or the beginning part of a simile phrase?

Time flies like a banana.
[Quote] [Link]
A simple mathematical experssion parser is a good place to start. Like this one, except honoring the order of operations.
[Quote] [Link]
How do you round something down to the closest integer?
[Quote] [Link]
Edit: Disregard what I said here previously.

Are you talking about truncation?
[Quote] [Link]
The Forum > Technology > NP Python Olympiad
Current Date: 13 Ineo 10:2Current Time: 8.86.92Join us in IRC...
Server: irc.esper.net
Channel: #nerdparadise
Your IP: 54.234.42.16Browser: UnknownBrowser Version: 0