Post Meet up Autopsy

2 views
Skip to first unread message

Graeme Glass

unread,
Mar 31, 2008, 8:06:11 AM3/31/08
to ct...@googlegroups.com
Well the meet up was pretty darn cool. Before the meet up, in my mind
it was turning out to be a little bit of a non-event, with only one
talk offered (mine and only 10 minutes at that), but I was pleasantly
surprised. All in all attendance was 9 pythoneers (approx), and
although the official part of the meeting was short, 3 informal
sessions spontaneously happened and that is where the coolness
happened.

First, Simon discussed his reading of the proof of the colouring graph
problem, touching on Congruence relation, which was really
interesting!

Jeremy also put up a very interesting problem on the board, where a
plain text file contains lines of - operator: items, then read in the
lines, apply the operations to the items, and return back all ordered
max to min. The fun of it was to get the solution in as few bytes as
possible. I am now also prodding him, to post his solution.

I then asked if it would be possible for the question asked here
http://groups.google.com/group/comp.lang.python/browse_thread/thread/2a30583d59f639e8?hl=en
(Daniel is a work colleague of mine and the problem is one I worked on
a while ago and offered to him to help him in his quest to learn
python with interesting problems), could be put into a list
comprehension, as the smallest I got it down to was a function. Simon
then took the drivers seat behind my laptop (on an environment that
was for lack of a better word was, 'special') with everyone crowding
around, and with suggestions shouted out by Adriana, Neil, Jeremy and
most everyone else, this gem came to life

S = 'abcdef'
["".join([s[j] for j in range(len(s)) if x & (1 << j)]) for x in
range(1,2**len(s)) ]


This informal session was enjoy by all, and Jeremy suggested also
trying out some http://projecteuler.net/ problems, so he will bring
some to the next CTPUG.

During the formal part of the meeting (PSF and Python Advocacy), I
briefly ran over the idea of a buildbot, what it is and the need for
more people to helping hosting and running a build slave for python.
(http://www.python.org/dev/buildbot/) Also donating to the PSF :-)

Then came the dream section of the talk,
(http://pycon.blogspot.com/2008/03/so-you-want-to-host-pycon-2010.html),
seeing if we could attempt to offer to host PYCON 2010! But of course
it is totally not practical for the foreseeable future, but some great
ideas came out of throwing out dreams and ideas. Kevin suggested a
much more practical idea, get a group of us to go over to it! (getting
sponsorship, and a bunch of other logistics) Also Simon suggested we
start smaller and try and host and run some local python sprints.

So all in all, the meeting was enjoyable and successful.

Look forward to the next one, see you all there.

Have a fantastic 4-6 weeks.

Graeme

Jeremy Thurgood

unread,
Mar 31, 2008, 9:40:05 AM3/31/08
to ct...@googlegroups.com
Graeme Glass wrote:
> Jeremy also put up a very interesting problem on the board, where a
> plain text file contains lines of - operator: items, then read in the
> lines, apply the operations to the items, and return back all ordered
> max to min. The fun of it was to get the solution in as few bytes as
> possible. I am now also prodding him, to post his solution.

Python golf: a one-liner to solve a given problem in the fewest characters.

The problem is to take a list of lines, as in the sample data below,
apply the operation to the list of parameters and print out a
comma-separated list of results sorted in descending order.

The whitespace in the input is arbitrary (you can't rely on whether
it'll be there or how much), the operation is case-insensitive, integer
average is allowed (but not required) and you can assume that all lines
will be well-formed. An arbitrary number of lines will be provided but
only the four operations in the sample data are required. The output is
not required to have whitespace in it, but must look neat.

Sample data (in sample.txt, no trailing linefeed):
sum : 1, 2, 3,4
AVG : 1, 2, 3, 4
min : 1, 2, 3, 4
MAX : 1, 2, 3,4


$ export APP='import sys;avg=lambda x:sum(x)/len(x);print
str(sorted(eval(l.replace(":","([").lower()+"])")for l in
open(sys.argv[1]))[::-1])[1:-1]'; echo "$APP" | wc -c; python -c "$APP"
sample.txt
134
10, 4, 2, 1


Can you do better?

--J

Neil Muller

unread,
Mar 31, 2008, 12:10:22 PM3/31/08
to ct...@googlegroups.com
And for those that eren't at the meeting, we decided to move the next
meeting forward to the 26th of April, due the long weekends in early
May, and various clashes people (such as me) had later in May.

Talk offers now open (and I remember a dbus talk that was offered at
the meeting in Feb, which sounds like a excellent starting point).

On Mon, Mar 31, 2008 at 3:40 PM, Jeremy Thurgood
<jerith...@jerith.za.net> wrote:
> Sample data (in sample.txt, no trailing linefeed):
> sum : 1, 2, 3,4
> AVG : 1, 2, 3, 4
> min : 1, 2, 3, 4
> MAX : 1, 2, 3,4
>
> $ export APP='import sys;avg=lambda x:sum(x)/len(x);print
> str(sorted(eval(l.replace(":","([").lower()+"])")for l in
> open(sys.argv[1]))[::-1])[1:-1]'; echo "$APP" | wc -c; python -c "$APP"
> sample.txt
> 134
> 10, 4, 2, 1
>
> Can you do better?

You can shave 3 characters by using backticks, rather than str().

--
Neil Muller
drnlm...@gmail.com

I've got a gmail account. Why haven't I become cool?

David Fraser

unread,
Apr 1, 2008, 3:45:22 AM4/1/08
to ct...@googlegroups.com, ct...@googlegroups.com
----- "Graeme Glass" <graem...@gmail.com> wrote:
> Well the meet up was pretty darn cool. Before the meet up, in my mind
> it was turning out to be a little bit of a non-event, with only one
> talk offered (mine and only 10 minutes at that), but I was pleasantly
> surprised. All in all attendance was 9 pythoneers (approx), and
> although the official part of the meeting was short, 3 informal
> sessions spontaneously happened and that is where the coolness
> happened.

Sounds like a cool meeting

> [snip]

> I then asked if it would be possible for the question asked here
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/2a30583d59f639e8?hl=en

For reference from that URL:

> I want to take a variable length string and use it as a base for
> counting, eg. given the string 'abc' the sequence would be:
>
> a
> b
> c
> aa
> ba
> ca
> ab
> bb
> cb
> ...
> ccc
>
> Basically I want to find every possible order of every combination.
> Its easy if you know how many characters there will be in your string
> (use nested for loops), but I am stuck with the variable length
> string. I think I have to use a generator but I'm not sure exactly
> how.

Continuing...


> (Daniel is a work colleague of mine and the problem is one I worked
> on
> a while ago and offered to him to help him in his quest to learn
> python with interesting problems), could be put into a list
> comprehension, as the smallest I got it down to was a function. Simon
> then took the drivers seat behind my laptop (on an environment that
> was for lack of a better word was, 'special') with everyone crowding
> around, and with suggestions shouted out by Adriana, Neil, Jeremy and
> most everyone else, this gem came to life
>
> S = 'abcdef'
> ["".join([s[j] for j in range(len(s)) if x & (1 << j)]) for x in
> range(1,2**len(s)) ]

As mentioned on the group above, this doesn't really solve the problem.
This does but is obviously done for minimal code rather than optimized:
n=(len(s)+1)
z = s+" "
sorted(dict.fromkeys("".join(z[(x/(n**j))%n] for j in range(n)).replace(" ","") for x in range(1,n**n)))

The solution you had above gives 63 solutions, this one gives 335922 (after evaluating 823543) - for 6 characters.

I've used " " rather awkwardly there; and I'm sure there's a way around it. The basic problem is that in counting in a base, zeroes on the left are discarded; I'll try give this a bit more of a think later

Cheers
David

Basically you could have
>[snip]

Graeme Glass

unread,
Apr 1, 2008, 4:01:38 AM4/1/08
to ct...@googlegroups.com

Thanks David!
Stéfan emailed me earlier to let me know the issue as well, and
suggested a fair amount of beer might have been involved :-D
Seem that in the soluotion given at CTPUG, all possible combinations
are given, but ignoring ORDERING of the returned strings as a
different values, so only (2 ** len(string)) items are generated,
where as to get all possible permutations, (2 ** len(string)) *
length items should have been generated.

Thanks for your solution. Hopefully have you at the next meet up :-D

G

Reply all
Reply to author
Forward
0 new messages