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 ]

jhuni (9050)

jhuni
  (email not shown publicly)
http://launchpad.net/gold-os/
Yahoo! ID: jhuni_x@yahoo.com (Add User, Send Message)

Journal of jhuni (9050)

Friday March 19, 2010
06:21 AM

More Rosetta code written in Perl6

[ #40253 ]
http://rosettacode.org/wiki/Dot_product#Perl_6

I added a solution to the dot product, which it turns out was very easy knowing Perl6 meta operators:

[+] ( @a <<*>> @b )

http://rosettacode.org/wiki/Find_the_missing_permutation#Perl_6

Another problem I worked on is this missing permutations problem, which I solved using cross operators, yet it still doesn't feel that elegant to repeat things four times:

[X~] @letters = @letters X~ @letters X~ @letters X~ @letters

I would've used the [X~] operator, however, it does not seem to work in any implementation yet, so instead I wrote things like on the right hand side, which is quite messy. The only other thing which is sort of interesting is the code to check duplicates. I forget about the uniq function for a while so I wrote this messy code to check for duplicates:

sub lacksDuplicates($str) {

    my @chars = $str.split('');
    my @pastValues;

    for @chars -> $char {

        return ?(0) if $char eq any @pastValues;
        @pastValues.push($char);

    }

    return ?(1);

}


Fortunately we have uniq so I wrote something more pleasant instead:

.chars == .split('').uniq.elems
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.