Please post solutions under here. I have included a framework....

sub yoursubhere { my $p = shift; my $v = shift; my $check = shift; my @lastresults = (0, 0); my $try; while ($lastresults[1] < $p) { #... @lastresults = $check->($try); } $try; }

I have a harness here as well that you can use to test.

use strict; use warnings; { my $solution = ''; my $p = 0; my $v = 0; my $counter = 0; sub reset_counter { $counter = 0; } sub inc_counter { $counter++; } sub get_counter { $counter; } sub setup_game { $p = shift; $v = shift; $solution = shift; } sub get_places { return $p; } sub get_dictsize { return $v; } # Very simple check function # # In particular, this does not check if characters are repeated, # characters are in the proper alphabet, nor does it handle any # timing of results. sub check_solution { my $try = shift; my ($pico, $fermi) = (0,0); inc_counter(); foreach my $i (0 .. $p-1) { foreach my $j (0 .. $p-1) { if (substr($try,$i,1) eq substr($solution,$j,1)) { if ($i == $j) { $fermi++; } else { $pico++; } } } } ($pico, $fermi); } } sub yoursubhere { my $p = shift; my $v = shift; my $check = shift; my @lastresults = (0, 0); my $try; while ($lastresults[1] < $p) { # ... @lastresults = $check->($try); } $try; } my $solutions = { yoursubhere => sub { yoursubhere(@_) }, }; my @games = ( { p => 2, v => 36, sol => 'PM' }, { p => 4, v => 36, sol => 'JAPH' }, ); foreach my $game (@games) { setup_game($game->{p}, $game->{v}, $game->{sol}); foreach my $solutionname (sort keys %$solutions) { my $solution = $solutions->{$solutionname}; reset_counter; print join(":", $solutionname, get_places, get_dictsize, $solution->(get_places, get_dictsize, sub { check_solution(@_) }, ), get_counter, ), "\n"; } }

--MidLifeXis

Please consider supporting my wife as she walks in the 2009 Alzheimer's Walk.


In reply to Re: Challenge: Optimal Bagels Strategy (Solutions) by MidLifeXis
in thread Challenge: Optimal Bagels Strategy by Limbic~Region

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.