Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

dpuu (6090)

dpuu
  (email not shown publicly)
http://dave.whipp.name/
Yahoo! ID: dave_whipp (Add User, Send Message)
+ -

  Comment: Re:refining the "show" function (Score 1) on 2010.02.04 15:23

by dpuu on 2010.02.04 15:23 (#71618)
Attached to: Blast from the past: E02
And actually I made a horrible error in my code: the way I wrote it the traversal order is actually undefined, because the order of iteration of hyper operators is undefined. So, although I'd say that having a concurrent traversal ordering would be a nice addition, the last line of my sub should probably be something like: ".() for @actions;"
Read More 5 comments
Comments: 5
+ -

  Comment: refining the "show" function (Score 1) on 2010.02.04 11:32

by dpuu on 2010.02.04 11:32 (#71615)
Attached to: Blast from the past: E02
Nice work, but still something lacking in the "show" function: both your version and SF's have too much repetition. What we really want to to say that there's a list of three actions to perform in one of three orders, with only one of the blocks moving. something like:

sub show(%tree, Traversal $method) {
    return unless %tree;
    my @actions = (
        { show %tree<RIGHT>, $method },
        { show %tree<LEFT>, $method },
    );
    @actions.=splice( $method.value, 0 ) <== { take %tree<VALUE> };
    @actions>>.();
}

Perhaps losing a bit of readability ... but I think we can remove even the last bit of repetition here:

sub show(%tree, Traversal $method) {
    return unless %tree;
    my @actions = <RIGHT LEFT>.map: -> $way { show %tree<$way>, $method }.assuming( $^way );
    @actions.=splice( $method.value, 0 ) <== { take %tree<VALUE> };
    @actions>>.();
}
Read More 5 comments
Comments: 5
+ -

  Comment: but just one thing more (Score 1) on 2009.03.03 18:07

by dpuu on 2009.03.03 18:07 (#67679)
Attached to: RPN Take 4

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 [+]= () },

Read More 3 comments
Comments: 3
+ -

  Comment: Re:Suboptimal (Score 1) on 2008.12.26 21:37

by dpuu on 2008.12.26 21:37 (#66628)
Attached to: The Bowling challenge

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

Read More 2 comments
Comments: 2
+ -

  Journal: Instant runoff voting... on 2008.12.24 17:16

Journal by dpuu on 2008.12.24 17:16
User Journal

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...

Read More 0 comments

+ -

  Journal: Blackjack! on 2008.12.24 15:37

Journal by dpuu on 2008.12.24 15:37
User Journal

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.

Read More 0 comments

+ -

  Journal: plus a couple of one-liners on 2008.12.24 13:38

Journal by dpuu on 2008.12.24 13:38
User Journal

event 6 asks us to generate the prime numbers from 1 to 200:


% ./perl6 -e 'my @primes; for 2 .. 200 -> $n { @primes.push($n) unless $n % any(@primes)==0 }; .say for @primes'

and event 7 asks for a random scheduling of a round-robin tournament with 6 teams:

Read More 0 comments

+ -

  Journal: Phone Numbers to Words on 2008.12.24 13:07

Journal by dpuu on 2008.12.24 13:07
User Journal

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.mspx

The actual challenge uses a file that contains the list of words: I decided to hard code the array:

Read More 0 comments

+ -

  Journal: The Bowling challenge on 2008.12.23 23:13

Journal by dpuu on 2008.12.23 23:13
User Journal

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;

Read More 2 comments
Comments: 2
+ -

  Comment: Re:Reduction operator (Score 1) on 2008.12.23 18:25

by dpuu on 2008.12.23 18:25 (#66600)
Attached to: My first experiment with Perl6
Having thought it through, my "diagonal cross" should almost certainly be prefix, not infix -- I can't think what a diagonal cross with a different array would mean. So:

say [+] %eq% @x

if I can figure out how to implement it!

Read More 2 comments
Comments: 2
+ -

  Journal: My first experiment with Perl6 on 2008.12.23 14:40

Journal by dpuu on 2008.12.23 14:40
User Journal
So Patrick suggested on rakudo.org that playing with Microsoft's "Winter Scripting Games" would be a good way to get started with Rakudo.

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.

Read More 2 comments
Comments: 2