[DFW.pm] new homework. fizz this buzz (advanced difficulty)

Tommy Butler dfwpm at internetalias.net
Tue Sep 30 19:35:16 PDT 2014


I'm calling this one advanced because it might be time intensive in Perl
6 (bait set).  I'll publish an easier assignment in a couple days or
so.  This is a variation on an old riddle.

Tackle one part or all parts of this problem in Perl or Perl 6.  The
only argument to your program is a single integer, representing the
number of members in your traveling party.

With a group of any random number of members, no less than 3,
represented by exactly three /*types*/ of members, design the most
efficient algorithm that gets each member safely from one side of a
Bifröst bridge to the other.

The laws of probability apply in the distribution of types to members. 
You have to create the type-assignment mechanism that properly
determines types based on these laws.  The only violation of this
principle is that there must be at least one member of each type
present.  Once you've determined your types, you start crossing your
members over the bridge.  This is a problem in and of itself.

One member may cross at a time, because the way is dark, narrow, and
only wide enough for 1 guide and 1 traveler to pass at a time.  You are
the guide, you hold Mjölnir, and no one crosses without you.  Traveling
members can never get across unaided.

Let (d) stand for duration.
Traveling member type one (Fortran programmer) is slow and withered with
age.  It takes this member 3d time to cross the Bifröst
Type two (mouse) is faster than the others and can cross in 1d time
Type three (cat) crosses in 2d and poses a danger to type two travelers
if left unsupervised with them on the FAR SIDE of the bridge.  On the
near side, Heimdallr is guarding the mice.
You are allowed to "sacrifice" some of your members to this danger. 
Leaving one cat on the far side with any number of mice results in a (m)
mortality.
A cat will only kill once.
A mortality incurs a duration penalty equal to the (d) value of the
member that was sacrificed, because a proper viking burial will have to
be carried out for the fallen warrior, resulting in heavy hearts, and
more delay.

The winning algorithm will do this in the lowest (d) duration time and
with the lowest (m) mortality rate.  The type-assignment and
bridge-crossing algorithms must be correct.

Expected input: 100 (suggested starting point)

Expected output:

Total Fortran programmer duration: __d
Total Cat duration: __d
Total Mouse duration: __d
Total traveler duration: __d

You can add statistics about which category took up the most time, etc. 
It's all for fun.  The answer could be ridiculously easy.

-- 
Tommy Butler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/dfw-pm/attachments/20140930/43f1e76c/attachment.html>


More information about the Dfw-pm mailing list