[Tutor] problem solving with lists: preliminary solution

dn PythonList at DancesWithMice.info
Wed May 25 16:01:56 EDT 2022


Hi Marcus,

This is a bit of 'blast from the past' - and I haven't gone 'back' to
look at our previous correspondence/this message hasn't "threaded".

May I offer a few criticisms and suggestions:-


On 26/05/2022 05.19, marcus.luetolf at bluewin.ch wrote:
> ....sorry, forgott correct e_mail address.....
> 
> Hello Experts, hello dn,

and not forgetting @wlfraed who mentioned university research papers
dealing with the intricacies (and insolubles) of the "SGP". Did you try
following-up on any of those?


> In resuming my task to write code for a special constellation of the 
> "SocialGolferProblem" (SGP) :
> number_of_days  (number_of_weeks) = 5
> number_of_flights (number_of_groupings)  = 4
> seize of flight (players_per_grouping) = 4

Criticism: although each of these terms is perfectly understandable, and
easily converted into a 'readable' pythonic identifier, later the code
uses "n" (for example) - which of the two values commencing "*n*umber_"
is it?


> and given the solution below (draws for week 1 through 5) I've come up with 
> a code of which I only post part of it (for it gets to big):
> for day 1( hardcoded)  and for day 2 (as a function to be used through day 
> 5).

The word "hardcoded" immediately stopped me in my tracks!

The whole point of using the computer is to find 'repetition' and have
the machine/software save us from such boredom (or nit-picking detail in
which we might make an error/become bored).

That said, may I suggest that you grab a whiteboard/blackboard, or a
convenient wall and a bunch of Post-It notes, and try to solve the
problem manually - first for week-one (which is largely trivial), but
then recording the 'history' and moving-on to the extra decision-layer
for week-two. If your brain doesn't go 'click'*, go on to deal with
week-three and see how the algorithm develops...

* keeping my 'pocket handkerchief' lawn tidy doesn't require 'heavy
machinery', but after many years of service my little electric mower
'died'. I bought a new Bosch model which needed to be partly assembled
from the box. The accompanying manual featured explanations in dozens of
languages. However, the (single/all-language) diagram showing where the
back-wheels were to be joined to the axles featured (only) the English
explanation: "Click". Perhaps other languages do use the word
(?spelling), but the term "going click in your mind" has long been used
for the idea explained in today's idiom as an "ahah! moment".


> The crucial part of my functions for day 2 to 5 are the conditional 
> statements. These conditional statements do not follow a consistent pattern.
> This inconsistency casts some doubt on the effectiveness of my code below 
> and I'd appreciate critical comments.
> 
...
>     a_flight_day_1 = []
>     b_flight_day_1 = []
>     c_flight_day_1 = []
...
>     history = {'a':[],
>
'b':[],'c':[],'d':[],'e':[],'f':[],'g':[],'h':[],'i':[],'j':[],'k':[],'l':[],'m':[],'n':[],'o':[],'p':[]}
...

Following-on from talking about looping (repetition), yes we need to use
multiple conditional expressions to ensure that history is taken into
account (consistently).

The other 'side' of both of these code-constructs is the data-construct.
Code-loops require data-collections! The hard-coded "a" and "day_1" made
me shudder.
(not a pretty sight - the code, nor me shuddering!)

Would you benefit from spending a little time, putting aside the SGP for
a moment, and looking at a tutorial on "nesting" lists (and
dictionaries) in Python?


Again, the above-mentioned 'whiteboard' exercise may help 'reveal' the
patterns in the data, as well as identifying an algorithm.


Sadly, the 'hard-coded' parts may 'help' sort-out week-one, but (IMHO)
have made things impossibly-difficult to proceed into week-two (etc).

(and I'm back to mentioning that I haven't searched for our previous
discussions - specifically whether we talked-about a data-construct for
'history', and also to referring-back to the 'whiteboard' suggestion)


We were warned!

The SGP can be made to work for this particular combination of
weeks/flights/players. Which gives credence to the first-thought: "it
looks so easy". However, the wider problem is more complex than one
at-first imagines!

This is the reason why 'combinatorial problems' are so interesting. Did
I say "interesting"? Perhaps "frustrating" and/or "frustratingly
difficult to solve" - or even: 'cannot (always) be solved'!

This is no 'little kitten' or some old piece of rope, you have "a tiger
by the tail"...
-- 
Regards,
=dn


More information about the Tutor mailing list