<div dir="ltr"><font size="4">Oh my god, thank you so much!!!!!! That was unbelievably simple. I don't know why I overlooked such a stupid mistake. I just deleted that line and now the output is exactly as it should be. I was just throwing an extra line in there, and why??? Oh well..... am I the only programmer who has these problems? Sometimes the simplest and easiest bugs are the hardest to find. Maybe I was just overthinking the problem. Oh well. Thanks for the help Don. If I sell my code to a big casino in Las Vegas for a million dollars, I'll give you a cut since you were so helpful! And I also owe you a beer!!!!</font><div><font size="4"><br></font></div><div><font size="4">Oh wait a moment, the trend now is toward free software and open source. Well forget about selling my code to that casino in Las Vegas. They can get it for free! ;-) </font></div><div><font size="4"><br></font></div><div><font size="4">Thanks for your help. I just can't believe I overlooked something so simple!!!!!! Okay, I feel retarded right now! :-) </font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 23, 2015 at 12:58 PM, Don Drake <span dir="ltr"><<a href="mailto:don@drakeconsulting.com" target="_blank">don@drakeconsulting.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div>I’ll bite. It’s not a floating point issue (as it normally is), it’s that System.out.format does NOT output a new line character, so the two outputs appear on the same line.<div><br></div><div><div><br></div><div> System.out.format( "\t\tEmpirical Probability: %12.10f", probability );</div><div><br></div><div> System.out.print( Probabilities.get(Int) );</div></div><div><br></div><div><br></div><div>-Don<div><span style="border-collapse:separate;border-spacing:0px"><span style="font-family:Helvetica;font-size:12px"><div><font face="Arial"><br>--</font></div><div><font face="Arial">Don Drake</font></div><div><font face="Arial"><a href="http://www.drakeconsulting.com" target="_blank">www.drakeconsulting.com</a></font></div><div><font face="Arial"><a href="http://www.maillaunder.com" target="_blank">www.maillaunder.com</a></font></div><div><font face="Arial"><a href="tel:312-560-1574" value="+13125601574" target="_blank">312-560-1574</a></font></div><div><font face="Arial"><a href="tel:800-733-2143" value="+18007332143" target="_blank">800-733-2143</a></font></div></span></span>
</div><div><div class="h5">
<br><div><blockquote type="cite"><div>On Mar 23, 2015, at 11:42 AM, Philip Doctor <<a href="mailto:diomedestydeus@gmail.com" target="_blank">diomedestydeus@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Unless you're doing a lot of repeated math on floats, I wouldn't expect a significant precision error here. <div><br></div><div>hint: I finally looked at the code because this email chain made me grumpy, it's not a float error. It's just a bug in Douglas' code.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 23, 2015 at 11:16 AM, Garrett Smith <span dir="ltr"><<a href="mailto:g@rre.tt" target="_blank">g@rre.tt</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You're not seeing a bug - this is expected behavior.<br>
<br>
<a href="http://floating-point-gui.de/" target="_blank">http://floating-point-gui.de/</a><br>
<br>
<a href="http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html" target="_blank">http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html</a><br>
<div><div><br>
On Mon, Mar 23, 2015 at 9:59 AM, Lewit, Douglas <<a href="mailto:d-lewit@neiu.edu" target="_blank">d-lewit@neiu.edu</a>> wrote:<br>
> Not my left foot or right foot, it's my nose that's itching! ;-) I<br>
> actually went over my program and printed out the intermediate values<br>
> (values BEFORE any computation of the probability). Interestingly enough,<br>
> all the values look just fine, so I'm still scratching my head on this one.<br>
> My professor never replied to my email, so this is where I'll have to get a<br>
> little aggressive and just corner him in his office during office hours.<br>
><br>
> I actually contemplated sending my code to Oracle, but I'm sure I'll get a<br>
> reply like, "Do you think this is Homework Central? Don't bother us with<br>
> such trivia!!!" But hey, why not? Worst case scenario, they'll just ignore<br>
> me.<br>
><br>
> The only thing I found on Stack Overflow was something to the effect of<br>
> "double division can produce roundoff errors", and that was a segue into the<br>
> BigDecimal class. We'll see.<br>
><br>
> In Python, this problem is very simple to do. In Java, even a simple walk<br>
> in the park gets transformed into a Thanksgiving Day parade!<br>
><br>
> On Mon, Mar 23, 2015 at 7:43 AM, Jeremy McMillan <<a href="mailto:jeremy.mcmillan@gmail.com" target="_blank">jeremy.mcmillan@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Doug, don't throw away Java, but do abandon java questions on the Python<br>
>> mailing list.<br>
>><br>
>> Might we suggest you inquire at an appropriate forum?<br>
>><br>
>> Chicago Java Users Group (Chicago, IL) - Meetup<br>
>><br>
>><br>
>> Actually, I think your questions might get the best reception from<br>
>> <a href="http://stackoverflow.com/" target="_blank">http://stackoverflow.com/</a><br>
>><br>
>> Please repost there, and try to restrain your urges to post off topic. I<br>
>> want to help, but after not too many empirical trials the probability that I<br>
>> will discover something Python related to address in your posts gets<br>
>> vanishingly small, and I'm likely to skip them without reading them. That<br>
>> would be a waste, because you seem to spend a lot of time making them. Your<br>
>> right foot is itching, but you're scratching your left foot.<br>
>><br>
>> On Mon, Mar 23, 2015 at 1:49 AM, Lewit, Douglas <<a href="mailto:d-lewit@neiu.edu" target="_blank">d-lewit@neiu.edu</a>> wrote:<br>
>>><br>
>>> Hey guys,<br>
>>><br>
>>> I'm pretty impressed with Python's dictionary data structure, so I did<br>
>>> some research and found out that Java has something equivalent called a<br>
>>> "HashMap". (Is that the same as a hash table or lookup table? I guess it<br>
>>> is.) I'm also interested in simulating games of chance, so I decided to<br>
>>> write a couple programs to simulate the game of rolling four dice. (In<br>
>>> statistics textbooks they always talk about rolling two dice, but that gets<br>
>>> really boring after a while. Why not three or four dice, right?) If you<br>
>>> roll four dice and record the sums, the sums can range from 4 (so you rolled<br>
>>> all 1's) to 24 (which means you rolled all 6's). The domain or sample space<br>
>>> for this problem thus includes all integers from 4 to 24, inclusive. But<br>
>>> then you have to compute the probability values. I decided to compute<br>
>>> empirical probabilities by creating a random object that simulates throwing<br>
>>> a die. Pretty simple, right?<br>
>>><br>
>>> I'm attaching two different but very closely related .java files. In one<br>
>>> I just use an array to store the probabilities. In the other I use the Java<br>
>>> version of a dictionary or "HashMap". Arrays are great, but with an array<br>
>>> all the keys are sequentially ordered integers starting at 0. Well for this<br>
>>> problem I don't want to start at 0; I want to start at 4, so it makes more<br>
>>> sense to use some type of dictionary, right?<br>
>>><br>
>>> Everything compiles and runs just great! That's not the problem. The<br>
>>> problem is this. If you look at my program that uses a HashMap, check out<br>
>>> the empirical probabilities. The final digits of the decimal are just<br>
>>> screwed up! For example, let's say that I run my simulation 1,000,000<br>
>>> times, and in 1,000,000 throws of four dice I get a sum of 4 775 times,<br>
>>> okay? So the probability for rolling a 4 should be 0.000775, right? When I<br>
>>> use an array, that's exactly what I get. But with a HashMap I'm getting<br>
>>> 0.0007750000775. ????? What the hell is that? I tried using<br>
>>> System.out.printf and System.out.format but they don't work! I'm really at<br>
>>> a loss. I just don't get it. It's not a big tragedy and the program still<br>
>>> basically works, but I guess I'm disappointed because my first HashMap<br>
>>> program has a bug in it! If anyone can shed light on this bug, hey, then<br>
>>> please enlighten me cause I can't figure it out.<br>
>>><br>
>>> Take it easy and thanks for the suggestions.<br>
>>><br>
>>> Best,<br>
>>><br>
>>> Douglas Lewit<br>
>>><br>
>>> P.S. I can just hear someone out there saying, "Doug, throw Java away<br>
>>> and just stick with Python!" While that is extremely tempting, right now<br>
>>> that's not an option. I want to pass my Java course with at least a B!<br>
>>> :-)<br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> Chicago mailing list<br>
>>> <a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
>>> <a href="https://mail.python.org/mailman/listinfo/chicago" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br>
>>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> Chicago mailing list<br>
>> <a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
>> <a href="https://mail.python.org/mailman/listinfo/chicago" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> Chicago mailing list<br>
> <a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/chicago" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br>
><br>
_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/chicago" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br>
</div></div></blockquote></div><br></div>
_______________________________________________<br>Chicago mailing list<br><a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br><a href="https://mail.python.org/mailman/listinfo/chicago" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br></div></blockquote></div><br></div></div></div></div><br>_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org">Chicago@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/chicago" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br>
<br></blockquote></div><br></div>