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

dragonchild,
I agree that once you know you have at least 2 points you can give up. If you look at my p5 solution in that thread, I solved the problem in 63 seconds (3 to generate a candidate list and 60 to disqualify them).

That's not the point of this challenge. The challenge is about practicing p6 features and syntax with efficiency only a secondary goal.

Cheers - L~R

Replies are listed 'Best First'.
Re^3: Perl6 Contest: Test your Skills
by dragonchild (Archbishop) on May 19, 2005 at 19:38 UTC
    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?"
      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