Grupos de Google ya no admite nuevas publicaciones ni suscripciones de Usenet. El contenido anterior sigue siendo visible.

Programming exercises/challenges

Visto 3 veces
Saltar al primer mensaje no leído

btk...@email.unc.edu

no leída,
18 nov 2008, 19:39:1618/11/08
a pytho...@python.org
Hi guys,

I'm learning Python by teaching myself, and after going through several
tutorials I feel like I've learned the basics. Since I'm not taking a
class or anything, I've been doing challenges/programs to reinforce the
material and improve my skills. I started out with stuff like "Guess my
number" games, hangman, etc. and moved on to making poker and card
games to work with classes. For GUIs I created games like minesweeper,
and a GUI stock portfolio tracker. I am out of ideas and am looking for
programming projects, challenges, or programs that have helped you'll
learn. I'm working on the project Euler problems, but I find that they
don't really help my programming skills; they are more math focused.
Suggestions? What has been useful or interesting to you? I'd also
welcome sources of textbook type problems, because the ones provided in
tutorials tend to be repetitive.

Thanks,
Ben

Mensanator

no leída,
18 nov 2008, 20:39:0718/11/08
a
On Nov 18, 6:39�pm, btk...@email.unc.edu wrote:
> Hi guys,
>
> I'm learning Python by teaching myself, and after going through several
> tutorials I feel like I've learned the basics. Since I'm not taking a
> class or anything, I've been doing challenges/programs to reinforce the
> material and improve my skills. I started out with stuff like "Guess my
> number" games, hangman, etc. and moved on to making poker and card
> games to work with classes. For GUIs I created games like minesweeper,
> and a GUI stock portfolio tracker. I am out of ideas and am looking for
> programming projects, challenges, or programs that have helped you'll
> learn. I'm working on the project Euler problems, but I find that they
> don't really help my programming skills; they are more math focused.
> Suggestions? What has been useful or interesting to you?

Math problems. :-)

> I'd also
> welcome sources of textbook type problems, because the ones provided in
> tutorials tend to be repetitive.

I read rec.puzzles regularly and always approach each puzzle
in a "how would I solve this with a program" way. Not all
lend themselves to computer solutions, some of the regulars
there frown on computer answers and some are simply math
problems in disguise. I follow sci.math for the same reason.

And alt.math. And alt.math.recreational.

Another hobby I have is tracking movie box-office receipts
(where you can make interesting graphs comparing Titanic
to Harry Potter or how well the various sequels do, if Pierce
Brosnan saved the James Bond franchise, what can you say about
Daniel Craig?). Lots of potential database problems there.
Not to mention automating the data collection from the Internet
Movie Database by writing a web page scraper than can grab
six months worth of data in a single session (you probably
wouldn't need this if you cough up a subscription fee for
professional access, but I'm not THAT serious about it).

There is nothing like such a hobby to provide motivation to
learn programming.

Here's something interesting: take a films opening weekend
box-office receipts and multiply it by Pi. You'll get the
film's total gross.

>
> Thanks,
> Ben

sk...@pobox.com

no leída,
18 nov 2008, 20:54:4018/11/08
a btk...@email.unc.edu,pytho...@python.org
Ben> I'm learning Python by teaching myself, ... I'm working on the
Ben> project Euler problems, but I find that they don't really help my
Ben> programming skills; they are more math focused.

I've found quite the opposite to be the case. I've been programming in
Python for quite awhile and I find Project Euler helps me explore both the
math side of the problems (reminding me of all I've forgotten) but also
forces me to exercise various Python programming techniques and data
structures in ways I typically wouldn't in my day-to-day programming
existence. Some of the problems while conceptually simple to solve are
intractable computationally with naive algorithms.

Here are four of the five (I think) basic ways to solve Problem 1 (find the
sum of all numbers below 1000 which are multiples of 3 or 5). If you run it
notice the wide range of runtimes. Which ones degrade badly as N increases?

#!/usr/bin/env python

import time

N = 1000

t = time.time()
print sum([(n % 3 == 0 or n % 5 == 0) and n or 0 for n in xrange(N)]),
print "%.6f" % (time.time() - t)

t = time.time()
print (sum(xrange(3, N, 3))
+ sum(xrange(5, N, 5))
- sum(xrange(15, N, 15))),
print "%.6f" % (time.time() - t)

t = time.time()
print sum([n for n in xrange(N) if n % 3 == 0 or n % 5 == 0]),
print "%.6f" % (time.time() - t)

t = time.time()
print reduce(lambda x,y: x+y,
filter(lambda n: n%3==0 or n%5==0, xrange(N))),
print "%.6f" % (time.time() - t)

t = time.time()
print sum(set(xrange(3, N, 3)) | set(xrange(5, N, 5))),
print "%.6f" % (time.time() - t)

--
Skip Montanaro - sk...@pobox.com - http://smontanaro.dyndns.org/

Tomasz Rola

no leída,
18 nov 2008, 21:01:0918/11/08
a btk...@email.unc.edu,pytho...@python.org,Tomasz Rola
On Tue, 18 Nov 2008, btk...@email.unc.edu wrote:

[...]
> challenges, or programs that have helped you'll learn. I'm working on the
> project Euler problems, but I find that they don't really help my programming


> skills; they are more math focused.

Project Euler and others focus more on the so called algorithmic side of
programming. You may find it a big fun later. For now, they probably look
bizarre to you.

> Suggestions? What has been useful or

> interesting to you? I'd also welcome sources of textbook type problems,


> because the ones provided in tutorials tend to be repetitive.

I would say, start looking for something in your own life, that can be
improved with the use of a program. This requires a bit of thinking in a
specific way, kind of awareness. Once you spot your own ideas, you will
probably run out of time to implement them all. If you have some interests
beyond programming :), finding them should not be that hard. If there are
some books related to those interests, they should be a good start. The
way you do it now, I think it is much better to connect your newly gained
knowledge with real-life activity rather then to solve yet another
"imagined" problem from a book, writing throwaway programs to prove that
you can write them. I am quite sure, that for every domain there is a lot
of big and small ideas waiting for a programmer. So you can start with
simple things and as you learn, try your luck with bigger ones. Writing
real life programs will give you an opportunity to learn some python
libraries, which is a good thing too.

Nice attitude :-).

Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature. **
** As the answer, master did "rm -rif" on the programmer's home **
** directory. And then the C programmer became enlightened... **
** **
** Tomasz Rola mailto:tomas...@bigfoot.com **

Mr.SpOOn

no leída,
19 nov 2008, 7:12:2219/11/08
a Mensanator,pytho...@python.org
On Wed, Nov 19, 2008 at 2:39 AM, Mensanator <mensa...@aol.com> wrote:
> Another hobby I have is tracking movie box-office receipts
> (where you can make interesting graphs comparing Titanic
> to Harry Potter or how well the various sequels do, if Pierce
> Brosnan saved the James Bond franchise, what can you say about
> Daniel Craig?). Lots of potential database problems there.
> Not to mention automating the data collection from the Internet
> Movie Database by writing a web page scraper than can grab
> six months worth of data in a single session (you probably
> wouldn't need this if you cough up a subscription fee for
> professional access, but I'm not THAT serious about it).

This is really interesting. What would one need to do such a thing?
The only program web related I did in Python was generating a rss feed
from a local newspaper static site, using BeautifulSoup. But I never
put it on an online host. I'm not even sure if I could run. What
requisites should have the host to run python code?

Thanks and sorry for the meddling.

Mr.SpOOn

no leída,
19 nov 2008, 7:44:2019/11/08
a Jeremiah Dodds,pytho...@python.org
On Wed, Nov 19, 2008 at 1:35 PM, Jeremiah Dodds
<jeremia...@gmail.com> wrote:
>
> Personally, I prefer a host that gives me root on a box (or virtual
> machine). I've had a great time with slicehost (http://slicehost.com).

Yes, I knew about slicehost, but it is expensive for what I need to
do, that is just experimentin a bit.

> There are a few hosts that specialize in, or explicitly offer python
> hosting, http://wiki.python.org/moin/PythonHosting has an overview of them.

Thanks for the link, seems useful.

greg

no leída,
19 nov 2008, 7:47:0719/11/08
a
On Nov 18, 6:39 pm, btk...@email.unc.edu wrote:

You night look at "Useless Python" (you'll have to Google for the
site). It has tons of problems from trivial to complex.
--greg

Mr.SpOOn

no leída,
19 nov 2008, 8:00:1619/11/08
a Jeremiah Dodds,pytho...@python.org
On Wed, Nov 19, 2008 at 1:50 PM, Jeremiah Dodds
<jeremia...@gmail.com> wrote:
> If you need to do it on the extremely cheap, you can host on your own
> machine on a port other than 80, make sure your router / firewall is
> forwarding the port to your machine, and use dyndns (http://dyndns.com) to
> give yourself a domain name. CherryPy (http://cherrypy.org) makes the python
> side of hosting a simple service or app quite painless. I use this method to
> host a little app for downloading Ubuntu packages and their dependencies as
> a tarfile on my personal machine.

Thanks, I'll try.

To turn back in topic, there is the python challenge:
http://www.pythonchallenge.com/
I started it when I was learning Python, but since the beginning it is
not as simple as they say on the site. It maybe stimulating.

Philip Semanchuk

no leída,
19 nov 2008, 9:41:3819/11/08
a pytho...@python.org

On Nov 19, 2008, at 7:12 AM, Mr.SpOOn wrote:

> On Wed, Nov 19, 2008 at 2:39 AM, Mensanator <mensa...@aol.com>
> wrote:

>> Another hobby I have is tracking movie box-office receipts
>> (where you can make interesting graphs comparing Titanic
>> to Harry Potter or how well the various sequels do, if Pierce
>> Brosnan saved the James Bond franchise, what can you say about
>> Daniel Craig?). Lots of potential database problems there.
>> Not to mention automating the data collection from the Internet
>> Movie Database by writing a web page scraper than can grab
>> six months worth of data in a single session (you probably
>> wouldn't need this if you cough up a subscription fee for
>> professional access, but I'm not THAT serious about it).
>

> This is really interesting. What would one need to do such a thing?
> The only program web related I did in Python was generating a rss feed
> from a local newspaper static site, using BeautifulSoup. But I never
> put it on an online host. I'm not even sure if I could run. What
> requisites should have the host to run python code?

I'm not sure why you'd need to host the Python code anywhere other
than your home computer. If you wanted to pull thousands of pages from
a site like that, you'd need to respect their robots.txt file. Don't
forget to look for a crawl-delay specification. Even if they don't
specify one, you shouldn't let your bot hammer their servers at full
speed -- give it a delay, let it run in the background, it might take
you three days versus an hour to collect the data you need but that's
not too big of deal in the service of good manners, is it?

You might also want to change the user-agent string that you send out.
Some sites serve up different content to bots than to browsers.

You could even use wget to scrape the site instead of rolling your own
bot if you're more interested in the data manipulation aspect of the
project than the bot writing.

Enjoy
Philip

Mr.SpOOn

no leída,
19 nov 2008, 12:23:1619/11/08
a Philip Semanchuk,pytho...@python.org
On Wed, Nov 19, 2008 at 3:41 PM, Philip Semanchuk <phi...@semanchuk.com> wrote:
> I'm not sure why you'd need to host the Python code anywhere other than your
> home computer. If you wanted to pull thousands of pages from a site like
> that, you'd need to respect their robots.txt file. Don't forget to look for
> a crawl-delay specification. Even if they don't specify one, you shouldn't
> let your bot hammer their servers at full speed -- give it a delay, let it
> run in the background, it might take you three days versus an hour to
> collect the data you need but that's not too big of deal in the service of
> good manners, is it?

Mmm, I didn't really mean the possibility to just host the code, but
to run. I mean, like server side code, so that my programs keep
running and updating, in my case, the RSS feed, without the need for
me to be online and run it.

Stef Mientki

no leída,
19 nov 2008, 14:07:5719/11/08
a btk...@email.unc.edu,pytho...@python.org
hi Ben,

btk...@email.unc.edu wrote:
> Hi guys,
>
> I'm learning Python by teaching myself, and after going through
> several tutorials I feel like I've learned the basics. Since I'm not
> taking a class or anything, I've been doing challenges/programs to
> reinforce the material and improve my skills. I started out with stuff
> like "Guess my number" games, hangman, etc. and moved on to making
> poker and card games to work with classes. For GUIs I created games
> like minesweeper, and a GUI stock portfolio tracker. I am out of ideas
> and am looking for programming projects, challenges, or programs that
> have helped you'll learn. I'm working on the project Euler problems,
> but I find that they don't really help my programming skills; they are
> more math focused. Suggestions? What has been useful or interesting to
> you? I'd also welcome sources of textbook type problems, because the
> ones provided in tutorials tend to be repetitive.
>
> Thanks,
> Ben

> --
> http://mail.python.org/mailman/listinfo/python-list

I'm working on an open source alternative for MatLab / LabView (math
again ;-)
and there's still a lot to do
- (re-)design of the core engine (multi thread ?)
- implementation of webkit under wxPython
- integration of Scintilla and rpdb2
- Vpython integration under Linux / Mac (Windows works)
- something like Okular, but then platform independant
- integrating of data acquisition hardware, soundcard, National
Instruments AD-converters, ...
here is a somewhat older version of my notes
http://mientki.ruhosting.nl/data_www/pylab_works/pw_manual.pdf
all separate notes until now can be seen under the paragraph PyLab works
here
http://pic.flappie.nl


cheers,
Stef

Edwin

no leída,
19 nov 2008, 20:54:2819/11/08
a
On Nov 18, 6:39 pm, btk...@email.unc.edu wrote:
> Hi guys,
>
> I'm learning Python by teaching myself, and after going through several
> tutorials I feel like I've learned the basics. Since I'm not taking a
> class or anything, I've been doing challenges/programs to reinforce the
> material and improve my skills. I started out with stuff like "Guess my
> number" games, hangman, etc. and moved on to making poker and card
> games to work with classes. For GUIs I created games like minesweeper,
> and a GUI stock portfolio tracker. I am out of ideas and am looking forprogrammingprojects, challenges, or programs that have helped you'll

> learn. I'm working on the project Euler problems, but I find that they
> don't really help myprogrammingskills; they are more math focused.

> Suggestions? What has been useful or interesting to you? I'd also
> welcome sources of textbook type problems, because the ones provided in
> tutorials tend to be repetitive.
>
> Thanks,
> Ben

I'm also learning Python by myself, downloading open ebooks, reading
tutorials, reading other people's code, etc. and in order to put my
knowledge into practice I've been writing small programs to solve my
everyday computer problems: a simple email client (because sometimes
it seems to me that email clients now have so many features and
preferences) that reads my fetchmailrc, a diary manager compatible
with my Emacs diary file (sometimes I don't want to open Emacs for a
quick note)... in general I try to solve problems related to my own
workflow.

I also try to play with some of my girlfriend's ideas on computer use:
she came up with an idea for a calculator with which she could easily
keep track of our bills (but found financial software a bit
complicated for simple tasks, once again, too many features and
preferences) so I started to code a small multi-touch app as
"intuitive" as possible (and still working on it).

What I'm saying is that I've found useful not to think about
programming itself but just think of it as a medium to solve my own
(common) problems.

Best regards,
E.

Arnaud Delobelle

no leída,
20 nov 2008, 1:39:0520/11/08
a
Edwin <exp...@gmail.com> writes:

[...]


> a diary manager compatible with my Emacs diary file (sometimes I don't
> want to open Emacs for a quick note)

You mean that you sometimes don't have emacs open?

--
Arnaud

Edwin

no leída,
20 nov 2008, 5:35:4220/11/08
a

heh... I believe in the potpourri style mate (and I don't mean petals
and spices).
After all I'm no expert.

sk...@pobox.com

no leída,
20 nov 2008, 7:28:3620/11/08
a Arnaud Delobelle,pytho...@python.org

>> a diary manager compatible with my Emacs diary file (sometimes I
>> don't want to open Emacs for a quick note)

Arnaud> You mean that you sometimes don't have emacs open?

I am constantly amazed at work that people open a separate emacs for each
file they want to edit. Most of them seem not to even know that find-file
exists.

Skip

r0g

no leída,
20 nov 2008, 17:11:2020/11/08
a

Spotted this on facebook t'other day, don't know if it's still active
and don't have time to check really.

http://www.facebook.com/jobs_puzzles/index.php

I've found writing your own servers can be an good hands on way of
learning languages and various internet protocols, just make sure you
have Wireshark to hand for debugging!

Roger.

Edwin

no leída,
20 nov 2008, 22:29:0020/11/08
a

Come on mate... it's already a bit hard to post in a non-native
language. As a beginner in Python it's just "my two pennies worth",
really.

Cheers,
E.

sk...@pobox.com

no leída,
20 nov 2008, 23:32:3020/11/08
a Edwin,pytho...@python.org

>> I am constantly amazed at work that people open a separate emacs for
>> each file they want to edit.  Most of them seem not to even know that
>> find-file exists.

Edwin> Come on mate... it's already a bit hard to post in a non-native
Edwin> language. As a beginner in Python it's just "my two pennies
Edwin> worth", really.

No knock on you at all, just an observation about the work patterns many of
my colleagues have. The people I work with are professional software
engineers, engineers, quantitative analysts, etc. Many not at all new to
Python, C++, Unix or Emacs. And it's not like I haven't shown them how to
do it. I showed one guy how to exchange two adjacent words today with M-t.
He about fell off his chair.

Come to think of it, the one other person I work with who always keeps an
Emacs open is a vi user who likes it for sql mode. Nothing else. He runs
viper mode and keeps an sql mode buffer open continuously with all his
little sql snippets ready to submit to our Sybase server. When he uses vim
to edit? One vim session per file. I'm pretty sure that vim allows you to
open multiple files at once as well. Go figure.

Skip

Edwin

no leída,
21 nov 2008, 18:47:5121/11/08
a

No worries. I actually agree. I've found myself in situations like the
ones you describe, finding new commands and realizing there's more to
it than I thought. I have to point out that I myself use Vim more than
Emacs. Not because I think it's better (I'm not a religious person)
but because it has better integration with my Mac... and actually, I
use them for different programming tasks.

As a newcomer to Unix (I've come from Web related fields) I've been
learning not only how to use the operating system, but also Python,
Emacs, Vim, bash, etc. This hasn't been easy, of course, but it has
been quite interesting and as I'm learning a specific topic (say
learning readline commands, how to access command history, etc.) I
don't always keep my editor open; sometimes I want to learn how an
editor does its stuff and then I 'hack' a script for manipulating a
relevant text file (like my diary).

I know you can run your favorite shell inside Emacs and learn from
there, but being the only computer at home (and not the fastest) I
don't want to be opening programs all the time (maybe my girlfriend
has several programs running) so being able to write some beginners'
scripts to solve common tasks has been a good learning experience for
me.

Greetings from the third world (or is it underdeveloped? ;))
E.

Arnaud Delobelle

no leída,
22 nov 2008, 3:15:5722/11/08
a
Edwin <exp...@gmail.com> writes:

> I have to point out that I myself use Vim more than
> Emacs. Not because I think it's better (I'm not a religious person)
> but because it has better integration with my Mac... and actually, I
> use them for different programming tasks.

I'm only a very occasional user of vi, so I don't really know how vim
integrates with MacOS X but have you tried aquamacs
(http://aquamacs.org/)?

--
Arnaud

Ken

no leída,
22 nov 2008, 4:11:5522/11/08
a

How about this: http://www.pythonchallenge.com/

<btk...@email.unc.edu> wrote in message
news:mailman.4215.1227057...@python.org...

Michele Simionato

no leída,
22 nov 2008, 6:16:3122/11/08
a

There is a colleague of mine who keeps open a single
Emacs for weeks, with up to fifty buffers open at
the same time; he thinks using multiple
instances of Emacs is an aberration.
I myself usually keep open 3 or 4 instances of Emacs at
the same time. One instance could keep the
bunch of Python files I am editing at the moment, another
instance a bunch of SQL files, another instance
my journal, another the documentation files, etc. I feel
uncomfortable with more than three or four buffer per
Emacs, so I tend to close and reopen them often, or
to use a different Emacs instance.
I mantain my personal journal as a Python script opening
a ReST file with Emacs according to today's date.
Since the code is short, I can as well post it here:

echo $diario.py
# -*- coding: utf-8 -*-
"""
usage: %prog [options]
-p, --publish: publish the journal as a web page
"""

import os, sys, time, datetime, calendar, re, locale
try: # set italian locale
locale.setlocale(locale.LC_ALL, 'it_IT')
except:
locale.setlocale(locale.LC_ALL, 'it_IT.UTF8')
from ms.optionparser import OptionParser

if sys.platform == 'darwin':
EMACS = '/Applications/Aquamacs\ Emacs.app/Contents/MacOS/Aquamacs
\ Emacs'
else:
EMACS = 'emacs'
ROOT = os.path.join(os.environ['HOME'], 'md/diario')
if not os.path.exists(ROOT): os.mkdir(ROOT)
OUTPUT = '/tmp/diario'
DATE = re.compile('\d\d\d\d-\d\d-\d\d.txt$')
today = datetime.date.today()
current_year = today.isoformat()[:4]
templ = """\
%s
---------------------------
"""

def open_today_page():
today_page = os.path.join(ROOT, str(today)) + '.txt'
if not os.path.exists(today_page):
print >> file(today_page, 'w'), templ % today.strftime('%A %d-
%b-%Y')
os.system('%s +4 %s &' % (EMACS, today_page))

def filter_pages_per_month_year(pages, theyear):
yield '.. contents::'
oldmonth = None
for pagename in sorted(pages):
year = pagename[:4]
if year != theyear:
continue
month = pagename[5:7]
if month != oldmonth:
yield '%s %s\n============================' % (
calendar.month_name[int(month)], year)
yield file(os.path.join(ROOT, pagename)).read()
oldmonth = month

def publish_journal():
import docutils.core, webbrowser
print >> file(OUTPUT + '.txt', 'w'), '\n\n'.join(
filter_pages_per_month_year(
[f for f in os.listdir(ROOT) if DATE.match(f)], current_year))
docutils.core.publish_cmdline(
writer_name='html',
argv=[OUTPUT + '.txt', OUTPUT + '.html'])
webbrowser.open('file://%s.html' % OUTPUT)

if __name__ == '__main__':
option, args = OptionParser(__doc__).parse_args()
if option.publish:
publish_journal()
else:
open_today_page()


(the OptionParser comes from this recipe: http://code.activestate.com/recipes/278844/)

Edwin

no leída,
8 dic 2008, 21:01:388/12/08
a
On Nov 22, 2:15 am, Arnaud Delobelle <arno...@googlemail.com> wrote:
> I'm only a very occasional user of vi, so I don't really know how vim
> integrates with MacOS X but have you tried aquamacs
> (http://aquamacs.org/)?
>
> --
> Arnaud

I've tried it but I ended up using original (I'm sure there's a better
adjective) Emacs compiled --with-ns... it's very nice (at least for
what I do, in the little experience I've gained).

Cheers,

0 mensajes nuevos