Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

choroba's scratchpad

by choroba (Abbot)
on Apr 02, 2010 at 15:13 UTC ( #832496=scratchpad: print w/ replies, xml ) Need Help??

Bug in XML::LibXML

#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my @docs = ( 'XML::LibXML::Document'->createDocument('1.0', 'iso-8859- +2'), 'XML::LibXML::Document'->createDocument('1.0'), ); for my $doc (@docs) { $doc->setDocumentElement(my $root = $doc->createElement('root')); $root->appendText("\x0b"); } print $_->toString for @docs;

Lexicographic Permutations

Contest Coding

My solution:

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use constant { STRING => 'Contest Coding', SEARCH => 'tsetnoC', }; sub to_lehmer { my @seq = @_; for my $i (0 .. $#seq) { $seq[$_] > $seq[$i] and $seq[$_]-- for $i .. $#seq; } return @seq; } sub to_order { my @lehmer = @_; my $order = 0; my $fact_radix = 1; for my $i (0 .. $#lehmer) { $fact_radix *= $i if $i; $order += $fact_radix * $lehmer[-$i - 1]; } return 1 + $order; } sub find_first { my %to_characters; my %to_numbers; for my $i (0 .. length(STRING) - 1) { my $char = substr STRING, $i, 1; $to_characters{$i} = $char; push @{ $to_numbers{$char} }, $i; } my @search_num = map shift @{ $to_numbers{$_} }, split //, SEARCH; my (@prefix, @suffix); for my $remaining (sort { $a <=> $b } map @$_, values %to_numbers) + { if ($remaining < $search_num[0]) { push @prefix, $remaining; } else { push @suffix, $remaining; } } return (@prefix, @search_num, @suffix); } say to_order(to_lehmer(find_first()));

Output (claimed wrong by Lewis Cornwall):

20728471681
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-07-30 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls