I agree, though I think it might need a special-case for zero-arity so that could could write an arbitrary reduction:
'sum' => { @stack = [+] @stack },
hmm, can that be written as assignment-operator?
'sum' => { @stack [+]= () },
Thanks for the subset suggestion. I'd tried putting "where" clauses inline, but that was very clunky. Subsets definitely solve that.
I'm not sure, however, I like your version of the consumption logic any better than mine: using a modifier-op ("shift" in both the conditional and consequent confuses me (I like conditionals to be pure). I would tend to agree, though, that my form was equally confusing. It might be best to be explicit:
my $bowls_this_frame = @scores[0] eq "X" ?? 1 !! 2;
@scores.shift for ^$bowls_this_frame
Advanced Challenge 3...
A couple of different approaches here: one is
to maintain a list of excluded candidates, and then ignore them during
recounts. The other is to actually delete them from the ballot and then
recount. Both solutions work: the first uses junctions; the other uses the
"is rw" trait on a for loop. So both are of some interest.
First: the junctional approach...
The final challenge was blackjack. The instructions said that we
could choose to implement that aces always equal 11, but that seems
insufficiently interesting: I wanted to use junctions!
To start with, a simple definition of a deck of cards. The challenge
required humanly named cards: so I started with a list of pairs, and
then crossed this list against the list of suites. Finally, "@cards =
@deck.pick( @deck.elems )" results in a random shuffle.
event 6 asks us to generate the prime numbers from 1 to 200:
%
and event 7 asks for a random scheduling of a round-robin tournament with 6 teams:
I couldn't stop with just the "beginners" challenges. "Expert" event 1 asks use to take a phone number, and convert it to a valid word using standard mapping of digits to letters -- http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent1.msp
The actual challenge uses a file that contains the list of words: I decided to hard code the array:
Having played with the "pairs" challenge, I looked through the other beginners events. Most dealt with files and databases: I didn't want to tackle that right now. So I skipped to challenge-10: interpret a bowling game that is input as an array.
For this one, my thought was to exploit "multi" subs: there're only so many patterns to each frame: I can just code them explicitly. Lets start with my solution:
my @scores = 2,5,7,"/",8,1,"X",9,"/",5,3,7,0,4,5,"X",2,0;
say [+] %eq% @x
if I can figure out how to implement it!
I liked that idea, so I went to the first challenge (for beginners) -- simply count the number of pairs in a list. For their test data (7,5,7,7,13), the correct answer is to be "3", because "7" is paired 3 different ways.