Post Reply 
Little explorations with HP calculators (no Prime)
12-29-2018, 04:06 PM
Post: #336
RE: Little explorations with HP calculators (no Prime)
(12-28-2018 03:41 PM)Albert Chan Wrote:  Yes, using random.shuffle may be overkill.
With only 2 kinds of balls, random.sample may be faster.
...

It is, noticeably. Full check of 1 million groups completed in 141s on my laptop, compared with 342s for the random.shuffle() version.

(12-28-2018 09:42 PM)brickviking Wrote:  If a 'special arrangement of the balls" is necessary, wouldn't that mean that we couldn't in fact have a randomly ordered sequence after all? I contend (again, without a rigid mathematic proof, 'cos I'm not that bright) that you can't actually arrange the balls specially to 'guarantee' that both Anna and Bertha get their required proportions of Christmas baubles. In saying that, it does appear that in a very small number of sequences, you can actually get a clear run of 70 that matches the criteria, and thereby the remainder would also match the criteria, but only when glommed together into a line; but it's a fairly small percentage of chance.

I believe you are reinforcing why I think the original problem description isn't clear enough for us to know exactly what it is we are supposed to be determining. There's a lot of room for (mis)interpretation here, due to the ambiguity of the description. @Pier: this is not meant as a criticism of your original post, it's simply that myself (and probably others) may need more clarification of exactly what problem we're supposed to solve here. As evidence to support this, see the next section.

(12-28-2018 09:53 PM)pier4r Wrote:  Maybe I should have clarified that special arrangement means "it works only with some permutations, rather than all".

I think this type of clarification is a good start, as it makes a difference in how the problem is interpreted. Another example: I'm of the belief that all permutations of ball arrangements are included in the set of "randomly ordered" arrangements. So in my mind, any arrangement (including sorted or grouped by some set of rules) needs to be considered within the domain of possible solutions. Without knowing further rules about possible assessments, how can we try to find an answer? An important example: is it valid to suggest that Anna should check every possible contiguous group of 70 balls for any given situation? Or is she only allowed to check one group for a solution? I believe the answer to that particular question changes the nature of this "puzzle" substantially.

(12-29-2018 07:35 AM)Thomas Klemm Wrote:  
(12-27-2018 11:58 PM)DavidM Wrote:  I'll need more time to analyze your implementation of match_count, though, as its use of the "blue" variable is puzzling me.

Not sure if that's still the case after Albert's version. Otherwise persist and feel free to ask questions.

Quote:Despite your code being much more compact, it was a bit slower on my laptop (506 seconds vs. 483 seconds for my original version).

Performance wasn't my primary concern. I just thought you might like the more functional approach.
I've never compared the performance differences between list comprehensions and generator functions.
But I try to use the latter when I expect huge sequences of data to avoid loading all of it into memory.

In this context I can recommend Generator Tricks for Systems Programmers.

Hey Thomas - thanks again for the pointers. Part of my confusion was cleared when I reformatted the code with fewer line breaks, which then made it easier to see the similarities with Albert's code (which was also quite helpful -- how is it possible that I had not yet seen [or possibly retained] that python booleans can be treated as 0 or 1?).

My comment about the performance was not a criticism, merely a somewhat surprising observation. I find that I more often lose patience with a long-running routine than discovering that I've run into memory constraints, and this exploration certainly fit into that category. Hence my looking at performance issues...
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Little explorations with HP calculators (no Prime) - DavidM - 12-29-2018 04:06 PM



User(s) browsing this thread: 3 Guest(s)