Hi Ben, I see that you can do the tennis score with just (server, receiver) pairs mapping to what happens when the server wins the point. With a bit of code you can then reverse the order of the lookup to work out what happens when the receiver wins the point. However I'd be tempted to redundantly add more data to make the code more expressive. What if the data structure was a dictionary mapping to two tuples, one for the server winning and one for the receiver wining? I'd argue this is easier to read. The a few elements of the data structure would be:
(0, 0) : ((15, 0), (0, 15)) (15, 0) : ((30, 0), (15, 15)) ... (40, 40) : ((A, 40) , (40, A)) (A , 40) : ((GAME), (40, 40)) (40, A) : ((40, 40), (GAME)) What do you think? Dave. On 13 December 2012 10:52, Ben Nuttall <[email protected]> wrote: > Hi Safe > > The tennis scoring is interesting. Robie and I coded a simple > implementation each since the last meet, using a dictionary of tuples > mapping one score to the next (for player one scores) and reversing for > player two. It removes the logic code you would otherwise need to write and > test. > > Another example of good use of data structure we've found recently is in > Conway's Game of Life. I've written a number of implementations of this, > particularly at XP Man and the Code Retreat. When pairing with C# and Ruby > types, they want to either set up multiple classes and introduce > inheritance, or have a grid and store the 'alive' state as 0s and 1s in > each position in the grid. I saw a video from PyCon recently (Stop Writing > Classes [1]) where it was suggested that these usual approaches are > overkill and that it can be simplified with a sensible data structure and > by removing the logic using set theory: e.g. a set of tuples (only the live > cells) therefore storing all the information you need in much less data. > Your code become more readable too - (1, 2) in alive_cells returns whether > or not that cell is alive, rather than having to loop over the values in a > nested list. > > We could pair up and code one of these exercises in a Pythonic way, and > compare outcomes? Or discuss data structures? I've coded with people > recently who, it turns out, didn't know what things like dictionaries, > tuples and sets are. I'd love to find out if there are any useful ones I > don't know! > > I'll be at the Madlab Christmas Party - hope to see a few Pythons there! > I've donated a Raspberry Pi as a raffle prize. If any of you would like to > donate a prize, or some food for the party - that would be much appreciated > by Madlab. I'm feeling particularly grateful for Madlab at the moment as > the Sheffield GIST Lab (the organisation that eased me in to the tech > community with Sheffield GeekUp) has just announced it is closing down, > which is really sad. Thanks to Daley for his contribution to the GIST Lab. > > See you all next week > > Ben > > > [1] Stop Writing Classes - http://www.youtube.com/watch?v=o9pEzgHorH0 > > > > On Wednesday, 12 December 2012 11:50:09 UTC, Safe wrote: >> >> Hi All, >> >> Python Northwest will be getting together again for a coding meeting at >> 7pm on Thursday 20th December at MadLab. It would be great to get an idea >> or two together in preparation for the meeting. As a starter for 10, >> possibilities include: >> >> - On the way out of English Lounge last time, there was some discussion >> about how you might go about coding a tennis scoring application. It might >> be interesting to compare approaches, and with a bit of effort, perhaps >> find point-by-point histories of classic games on the interweb, feed them >> into our scorers and see how well they do. >> >> - In the past we've run a coding dojo style session where we make >> suggestions of what we might code then take a vote and get cracking. Past >> suggestions have included a crossword generator, a poker hand scorer and a >> DVD database. >> >> Other ideas? >> >> fyi ... MadLab is also holding an End of Year party on Tuesday 18th >> December to which we're cordially invited! Details here: >> http://madlab.org.uk/**content/madlab-end-of-year-**party/<http://madlab.org.uk/content/madlab-end-of-year-party/> >> >> Best, >> >> Safe >> >> >> Safe Hammad >> http://safehammad.com >> @safehammad >> > -- > To post: [email protected] > To unsubscribe: [email protected] > Feeds: http://groups.google.com/group/python-north-west/feeds > More options: http://groups.google.com/group/python-north-west > -- To post: [email protected] To unsubscribe: [email protected] Feeds: http://groups.google.com/group/python-north-west/feeds More options: http://groups.google.com/group/python-north-west
