Today we have 15 minutes of fame, tomorrow 15 minutes of anonymity.
My Blog | Veza - Opensource TinyURL clone with sensible URLs
what time will you close the thread tomarrow
Alright, here is my solution in ruby, which is a language I just started to learn, thanks to why's (poignant) guide to ruby, which is got to be one of the most entertaining programming resources around. It's really a shame that more open source projects don't use ruby, because it's a really powerful, fun, and elegant language. In fact, the reason I chose to learn it over python is that the code looks a hell of a lot more beautiful.
Anyway, here it is:
Code:#!/usr/bin/ruby class Person @name, @age, @id = nil def setName (name) if name.kind_of? String and not name.empty? and name[0] != ' '[0] and name.length < 20 @name = name.rstrip else @name = nil end end def setAge (age) if age.kind_of? Fixnum and age>0 @age = age else @age = nil end end def setId (id) if id.kind_of? Fixnum and (1..999999) === id @id = id else @id = nil end end def name @name end def id @id end def age @age end end def xgets result = gets.chomp if result.upcase == 'EXIT' puts "Program terminated" exit else return result end end person = Person.new while person.name == nil print "Name: "; person.setName(xgets) end while person.age == nil print "Age: " person.setAge(xgets.to_i) end while person.id == nil print "ID: " person.setId(xgets.to_i) end print "You are #{ person.name }, " print "aged #{ person.age } next year you will be #{ person.age + 1 }, " puts "with user id #{ person.id }, the next user is #{ person.id + 1 }."
Last edited by xnevermore; August 8th, 2008 at 09:40 AM. Reason: Adjusted code to work for users with OLDER versions of ruby
Sweet, after looking through this thread I've realized that I'm the only one with a Ruby version! That should earn me some points, right?
Not sure. I'll wait until you are done if you want. If anyone wants me to wait, let me know as soon as possible (on this thread)
After finding all that work, I separate them by language, and try to get 10 total. If there are more than 10, I narrow down the language groups (like last time we had a lot of Python and C++, and only a few other languages. I culled the Python and C++ ones to get a top 10, although I think it ended up being only 9)
Being the only one in a language (and it works) means it won't be bumped unless it is really needed (and since I think we have less submissions this time, it will be unlikely to happen)
Fixed it so it won't crash when not typing in numbers. No award winner but it was still fun making it Last changes I will be making to it so if someone finds something wrong or a bug I would love to find out but I'll be too busy to re-do any parts
PHP Code:
#!/usr/bin/env python
#revised version, fixed bug that caused program to crash when user did not enter
#a number when asked for their Age and Forum ID
import sys
resp1 = raw_input("What is your forum name (Type quit to exit)? ")
while resp1 == "":
resp1 = raw_input("Please enter your forum name (Type quit to exit)? ")
if resp1 == "quit":
print "Goodbye"
exit()
else:
if resp1 == " ":
print "Please do not use spaces"
exit()
else:
if resp1 != "":
print "That's better"
if resp1 == "quit":
print "Goodbye"
exit()
else:
if resp1 == " ":
print "Please do not use a space"
exit()
else:
if resp1 != "":
print "Thank You"
resp2 = raw_input("What is your age (Type quit to exit)? ")
while resp2 == "":
resp2 = raw_input("Please enter either a number or quit in order to exit ")
if resp2 == "quit":
print "Goodbye"
exit()
if resp2 == "quit":
print "Goodbye"
exit()
while resp2:
try:
resp2 = int(resp2)
if resp2 == int(resp2):
break
except:
resp2 = raw_input("Please enter a valid number for your age (Type quit to exit)? ")
if resp2 == "quit":
print "Goodbye"
exit()
else:
if resp2 == "":
resp2 = raw_input("Please enter a valid number for your age (Type quit to exit)? ")
if resp2 == "quit":
print "Goodbye"
exit()
if resp2 < 1:
print "That is not a valid age, Goodbye"
exit()
else:
if resp2 > 999999:
print "That is not a valid age,Goodbye"
exit()
else:
print "Thank You"
resp3 = raw_input("What is your forum ID (Type quit to exit)? ")
while resp3 == "":
resp3 = raw_input("Please either enter your Forum ID or quit")
if resp3 == "quit":
print "Goodbye"
exit()
if resp3 == "quit":
print "Goodbye"
exit()
while resp3:
try:
resp3 = int(resp3)
if resp3 == int(resp3):
break
except:
resp3 = raw_input("Please enter a valid number for your forum ID (Type quit to exit)? ")
if resp3 == "quit":
print "Goodbye"
exit()
else:
if resp3 == "":
resp3 = raw_input("Please enter a valid number for your forum ID (Type quit to exit? ")
if resp3 == "quit":
print "Goodbye"
exit()
if resp3 < 1:
print "That is not a valid forum ID, Goodbye"
exit()
else:
if resp3 > 999999:
print "That is not a valid forum ID, Goodbye"
exit()
else:
print "Thank You"
print "You are %s, aged %s next year you will be %s, with user id %s, the next user is %s." % (resp1, resp2,resp2 + 1, resp3, resp3 +1)
i assume that goes the same for my C#?After finding all that work, I separate them by language, and try to get 10 total. If there are more than 10, I narrow down the language groups (like last time we had a lot of Python and C++, and only a few other languages. I culled the Python and C++ ones to get a top 10, although I think it ended up being only 9)
Being the only one in a language (and it works) means it won't be bumped unless it is really needed (and since I think we have less submissions this time, it will be unlikely to happen)
and thanks for waiting i should be done tomarrow afternoon
Bookmarks