in reply to Re^2: Perl6 Contest: Test your Skills
in thread Perl6 Contest: Test your Skills

This is my point:
# Assumption: @hand[0]<val> == 5; sub is_good( @hand ) returns Bool { # If you have a 10, J, Q, or K anywhere in @hand, you win. if any(@hand<val>) == 10 { return true; } # If you have more than one of anything, you win. my %cardvals; %cardvals{ @hand[0..4]<num> }++; if any( %cardvals.values ) > 1 { return true; } # If you have 3+ cards in a row, you win. for 1 .. 11 -> $start { if all( @cardvals{ ($start, $start+1, $start+2) } ) { return true; } } # If +%suit{@hand[0..3]} == 1, you win. # Note: The suit of the cut-card is irrelevant. my %suits; %suits{ @hand[0..3]<suit> }++; if +%suit == 1 { return true; } # Alternately, this could have been written: # if all( @hand[0..3]<suit> ) == any( @hand[0..3]<suit> ) { # return true; # } return false; }

  • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
  • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"

Replies are listed 'Best First'.
Re^4: Perl6 Contest: Test your Skills
by Limbic~Region (Chancellor) on May 19, 2005 at 19:45 UTC
    dragonchild,
    Right. With all due respect to thor, I believe the original problem was poorly stated (as perhaps was my challenge). I know the ultimate goal was only to determine if such a hand existed, but the process outlined by which to do it was to actually score each hand:

    What I want to do is write a program that brute forces the issue. That is to say that I want to create a program that scores all 5-card hands that have a 5 in them and see what happens.

    I would prefer that the actual score be tabulated since it is a harder problem, but I am fine with aborting from score() early if you know the score is going to be > 1. This is afterall not about verifying something we already know - it is about exposure to Perl6.

    Cheers - L~R

      Just as the point of the head post in this thread was to tackle the problem with p6, the point of my initial post was to create a scenario against which I could try creating an iterator. Unfortunately, eveyone got caught up in cribbage semantics. Oh well...I got out of it what I wanted...kind of.

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        thor,
        If you would like an explanation of how my iterator works (either the p5 or p6 version), I would be happy to explain. It may not be very clear because I translated a process of doing it by hand on paper to code. There is also the tutorial (How To: Make An Iterator) on building iterators I wrote recently and Roy Johnson's recent Recursively-generated Iterators.

        Cheers - L~R