[Chicago] Throw those dice!!!!
Brian Ray
brianhray at gmail.com
Mon Aug 3 03:24:27 CEST 2015
Consider using xrange instead of range. Also, please use four spaces for
the love of other developers!
Concerning speed there are always two ways to do repetitive tasks:
recursively and iteratively
I see you are using the recursive method. Fine, but you are relying on your
python stack. Similarly, thinking stacklessly (yes I invented this word and
would appreciate full credit moving forward), you could conquer this same
problem iteratively. If you want to drop to a more metal on metal
approach, you can simply start using things like numpy. That would allow
you to handle the data a little closer to the the machine.
I realize you have a busy week; however, consider a couple alternative
approaches outlined above.
Cheers, Brian
On Sun, Aug 2, 2015 at 9:04 PM, Lewit, Douglas <d-lewit at neiu.edu> wrote:
> Hey guys,
>
> I will admit that I'm rather proud of this little Python program that I
> wrote, but for values larger than 6 either the program crashes because of a
> stack overflow or the program becomes really painfully SLOW!
>
> Let me explain what this program does. Let's say that you roll two dice.
> What are all the possible sums. If both dice land with the one-side face
> up, that's a sum of 2. If both dice land with the six-side face up, that
> is 6 + 6, which gives you a sum of 12. Then you have all the sums in
> between. Any student of statistics will tell you that these sums are NOT
> all equally probable or equally likely. For example, in the case of two
> dice, the most probable sum is 7 because there are several ways to get that
> sum. First die = 3, second die = 4, {3, 4} or {4, 3} or {5, 2} or {2, 5}
> or {1, 6} or {6, 1} or ..... get the idea?
>
> But why limit ourselves to just two dice? What about three dice? Or four
> dice? Or five dice? Or six dice? Or any number of dice that we choose to
> throw?
>
> My approach works pretty well for any number of dice from 1 to 6. Beyond
> 6 however, that's when I run into some real problems.
>
> Is there an "easy" way to fix this? Probably not, but I thought I would
> check with people who are more experienced in Python than I am.
>
> I appreciate the feedback, but may not be able to reply until next
> weekend. I'm VERY busy this week! But still I appreciate any constructive
> feedback that you can provide.
>
> Many thanks,
>
> Douglas Lewit
>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>
--
Brian Ray
@brianray
(773) 669-7717
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20150802/34565261/attachment.html>
More information about the Chicago
mailing list