POV-Ray : Newsgroups : povray.text.scene-files : Weird Loop Behavior : Re: Weird Loop Behavior Server Time
15 Aug 2022 09:31:14 EDT (-0400)
  Re: Weird Loop Behavior  
From: Dave Blandston
Date: 12 Jul 2022 04:45:00
Message: <web.62cd3407a05c0a6d4907a549607c1b34@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> need to do more/better tests of "Issue number two" but didn't see a difference
> with conditional commented out.

Hey jr, thanks for taking a look at this! I did some more testing with issue
number two and it's really weird. Commenting out the #if () conditional does not
change the results, even with thousands of iterations, which suggests that it
doesn't affect the execution flow. BUT... replacing the "#local Dummy = 0;" line
with this "#debug concat ("Comparing: ", str (J, 0, 0), ", " str (Box
[WhichBox], 0, 0), "\n")" produces interesting/bazaar results. The purpose of
this line is to make sure that the "loop" described in the video is being
followed correctly, which it is. The "J" variable represents each prisoner so it
should go from 0 to N - 1 since each prisoner gets a turn at looking for his
number. The "Box [WhichBox]" variable represents the number on the slip of paper
inside each box.

With the #if () conditional in place, here are the results of the new #debug
statement for six prisoners and random seed 12:

Comparing: 0, 0

Comparing: 1, 4
Comparing: 1, 3
Comparing: 1, 1

Comparing: 2, 2

Comparing: 3, 1
Comparing: 3, 4
Comparing: 3, 3

Comparing: 4, 3
Comparing: 4, 1
Comparing: 4, 4

Comparing: 5, 5

This is exactly the output that I want. It shows that comparisons are made until
the correct number is found, and if it's found before the maximum allowed number
of attempts, the remaining allowed comparisons are skipped.

Here is the output with the #if () conditional commented out:

Comparing: 0, 0

Comparing: 1, 4
Comparing: 1, 3
Comparing: 1, 1

It appears that without the #if () conditional, when the maximum allowed number
of comparisons are made, then the outer loop is exited inappropriately by the
#break instruction. Values for J = 2 through 5 are totally missing, yet the
final computed result is the same! Madness! Here's some more diagnostic
information indicating that the program execution is being affected - for values
of 100 prisoners and 10000 iterations, there was a 16-second difference in
processing times and a large difference in the "Parsing ____K tokens" number
that POV displays. It would take a mathematical genius to figure out why the
final result is unaffected by this issue (I may have inadvertently discovered
something significant and am about to become famous - ha ha) but the issue with
the #for (J...) loop being exited prematurely (in my opinion) does seem to be a
real issue - unless that's how it's supposed to work.

I've attached a file to demonstrate the issue more clearly. The #if ()
conditional with the comment "//Why is this test necessary?" can be commented
out for comparison purposes.

Kind regards,
Dave Blandston

Post a reply to this message

Download 'riddle2.pov.dat' (4 KB)

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.