[Purdue-pm] Efficiency, was: my 2015-08-12 challenge problem solution
Mark Senn
mark at ecn.purdue.edu
Sun Aug 9 14:21:16 PDT 2015
Rick Westerman <westerman at purdue.edu> wrote on 2015-08-09 at 11:18 -04:
| my $data = ‘aaa:b:cccc’ ;
|
| my ($one) = reverse grep { $_ } split ‘:’, $data ;
|
| my @twoarr = split ‘:’, $data ;
| my $two = $twoarr[-1] ;
|
| my $pos = rindex $data , ':' ;
| my $three = substr($data, $pos + 1) ;
(I'm not sure what what will happen with input encoding when I send this
message but I doubt if the code above will be runnable.)
When I save the above code in a file named "t.pl" and type "perl t.pl"
(using Perl 5 version 5.22.0 on a Intel x86_64 Redhat Linux 6.6 system)
I get
Unrecognized character \xE2; marked by <-- HERE after y $data = <-- HERE near column 12 at f01.pl line 1.
The quotes in the
my $pos ...
line look ok though. Did the original code from Rick run for anyone?
FOLLOWUP CHALLENGE QUESTION (that I'm not going to do)
In the original problem, identify all characteristics of possible input
data that could affect the runtime (when using only ASCII characters)
and write an O(n)-like expression to describe it. Plot the predicted
runtime and real runtime vs. the number of unique first names (n) for
n from one to a billion.
-mark
More information about the Purdue-pm
mailing list