Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hmmm..., looking at it again, I can see that it might be a bit confusing.

If you uncomment the print line in HisTry and MyTry, you get more verbose reporting about the results of each possibility.

Roll 1 => [0] Starting with 0
This is where we start the game, with both players @ 0.
In later rounds, the round could start with several possibilities (e.g. Roll 7 => [14, 15]), and each is explored in turn.
------ His possibles => [6]
we try all 6 possibilities for the die in HisTry But, $new = move($start,$die) will adjust the output if it is a prime or a square before returning the value, and validHim($new) knocks out any of these that won't be valid final values.

So for the first roll :

Him => 0 + 1 => 1 => 0 0 Him => 0 + 2 => 2 => 3 0 Him => 0 + 3 => 3 => 5 0 Him => 0 + 4 => 4 => 1 0 Him => 0 + 5 => 5 => 7 0 Him => 0 + 6 => 6 => 6 1 a b c d e a = start b = die roll c = start + die roll d = adjusted down for square, up for prime. e = is it a valid final number ?
Scores of 1,4 move down to the next square, and 2,3,5 move up to the next prime.

Since we have to end up with His score twice mine, his end number must be even, so this only leaves 6 from the first roll.

Do the same for Me, but matching possibilities are only those where his roll ends up as twice mine.

My Matching possibles => [3]
And carry forward to the next round the sequence of final values for Me.
In this case, I end up at the end of Roll 1 with a 3 as the only possible value that is valid under the contstraints.
Carrying Forward => [0, 3] ----- Roll 2 => [3] Starting with 3 . . . My final Sequence => [0, 3, 4, 7, 10, 12, 14, 15]
The last line means that it found exactly one final set of rolls that would meet the constraints, and Me end up with 15, and Him on 30.

Note that several of the rolls carry forward multiple possible routes to the next round where they then get eliminated, and in Roll 5,6, we can get from 10=>12=>15 or 10=>13=>15 via 2 different routes but, since the answer is the same we don't care.

Hope that helps explain it.
You can also uncomment the Data::Dumper->Dump lines if you want to see the internal tables it uses build up during the game.
--
Brovnik


In reply to Re: Re: Solver for Sunday Times teaser 2021 by Brovnik
in thread Solver for Sunday Times teaser 2021 by Brovnik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-03-29 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found