From mark at purdue.edu Fri Aug 7 05:28:07 2015 From: mark at purdue.edu (Mark Senn) Date: Fri, 07 Aug 2015 08:28:07 -0400 Subject: [Purdue-pm] meet on campus or downtown? Message-ID: <42359.1438950487@pier.ecn.purdue.edu> I understand I've been the only one expressing an opinion on whether they'd like Purdue Perl Monger meetings to meet at Purdue or at the MatchBox coworking studio in downtown Lafayette. Finding a working projection system during the last meeting at MatchBOX cut into the scheduled meeting time. I prefer at Purdue. If you have a preference please state it. Thanks. Mark Senn, Systems Programmer, Engineering Computer Network, Purdue University From jacoby at purdue.edu Fri Aug 7 06:45:58 2015 From: jacoby at purdue.edu (Dave Jacoby) Date: Fri, 7 Aug 2015 09:45:58 -0400 Subject: [Purdue-pm] meet on campus or downtown? In-Reply-To: <42359.1438950487@pier.ecn.purdue.edu> References: <42359.1438950487@pier.ecn.purdue.edu> Message-ID: <55C4B696.2010406@purdue.edu> On 8/7/2015 8:28 AM, Mark Senn wrote: > I understand I've been the only one expressing an opinion on whether > they'd like Purdue Perl Monger meetings to meet at Purdue or at the > MatchBox coworking studio in downtown Lafayette. Finding a working > projection system during the last meeting at MatchBOX cut into the > scheduled meeting time. > I prefer at Purdue. If you have a preference please state it. > Thanks. Thank you for your response. It was the deafening lack of response to my own request for input that has kept me from organizing August's meeting until recently. I have meetings with Michael Gribskov, where he has opined that we should repeat at the location, giving it a decent shot, before dropping back to WSLR. We'll have that room as a fall-back for the next year at least, so we won't have to struggle to return to campus. In defense of MatchBox, it was the HDMI cable, not the projector, that proved to be the problem. I will bring my own known-good HDMI cable, which should solve that issue. Michael's other issue is that we needed someone at the door to let in Mongers. I had intended this to be my role, after 5:40pm, once I proved the projectors worked and all. We know how that went. Personally, I like the location and the connection to the GLOSSY Chat social session after, but I'm one voice. I would put it as a choice between in WSLR, in MatchBox, or disbanding. I would like to hear any preferences the other mongers have. -- Dave Jacoby Developer, Purdue Genomics Core Lab http://web.ics.purdue.edu/~djacoby/ 745 days using standing desk From jacoby.david at gmail.com Fri Aug 7 07:02:19 2015 From: jacoby.david at gmail.com (Dave Jacoby) Date: Fri, 7 Aug 2015 10:02:19 -0400 Subject: [Purdue-pm] Announcement: Purdue Perl Mongers (GLOSSY Perl SIG) - 6pm Aug 12 at MatchBox Message-ID: [Cross-emailed for my purposes. Feel free to remove one or the other list in replies.] Purdue Perl Mongers will meet 6pm next Wednesday, August 12, in the MBAH Insurance room in MatchBox, followed by GLOSSY Open Source Food & Beer & Chat at Lafayette Brewing Company. The agenda includes Dave Jacoby presenting on what he learned by contributing to perlbrew, and a discussion of the future of the group. See you Wednesda! -- David Jacoby jacoby.david at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gizmo at purdue.edu Fri Aug 7 11:49:23 2015 From: gizmo at purdue.edu (Joe Kline) Date: Fri, 07 Aug 2015 14:49:23 -0400 Subject: [Purdue-pm] meet on campus or downtown? In-Reply-To: <55C4B696.2010406@purdue.edu> References: <42359.1438950487@pier.ecn.purdue.edu> <55C4B696.2010406@purdue.edu> Message-ID: <55C4FDB3.70700@purdue.edu> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I'm up for doing MatchBox for a bit longer. Maybe at the meeting next week we can think of places where to post some flyers on campus. Although there is the e-sidewalk chalk thing, or whatever it's called, which would be good, too. If MatchBox seems to not pan out we can maybe drop back to a campus location but keep the same after work time slot? Not as convenient to go to GlOSSY but it also gives a chance at catching some on campus folks. joe -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) iEYEARECAAYFAlXE/bIACgkQb0mzA2gRTpkUbACglJJlL+Q3vu9MGT2CfGIT5/YI oIIAoIQVrLWMM4UVoiQjRRWPOrarskfB =LB4E -----END PGP SIGNATURE----- From mark at purdue.edu Sat Aug 8 20:58:14 2015 From: mark at purdue.edu (Mark Senn) Date: Sat, 08 Aug 2015 23:58:14 -0400 Subject: [Purdue-pm] my 2015-08-12 challenge problem solution Message-ID: <26252.1439092694@pier.ecn.purdue.edu> PROBLEM DEFINITION SHORTEN NAMES CHALLENGE PROBLEM last improved on 2015-08-08 Write Perl 5 and Perl 6 programs to do the following. You are not allowed to use any additional Perl modules. You must only use the built-in features in Perl 5 or Perl 6. Hint: Perl 6 has sets, bags, and mixes, see http://doc.perl6.org/language/setbagmix Read the names from a Perl data section one name per line. Do error checking to make sure you aren't given duplicate first names. If there is a duplicate first name print a "duplicate(s)" line and exit. Given a list of names, shorted the first names as much as possible so they still refer unambigously to a single person. For example, THESE NAMES CAN BE SHORTENED TO ----------- ------------------- Abe Lincoln Ab Abe Alan Turing Al Ala Alan Ben Carson B Be Ben Cat Stevens Cat Cathy Rigby Cath Cathy Abe can't be shorted to A because we'd get Abe Lincoln and Alan Turing confused. Cath is not shortened to Cat because we'd get Cat Stevens and Cathy Rigby confused. The program's output should be the shortened names in sorted order like this: Ab Abe Al Ala Alan B Be Ben Cat Cath Cathy -mark COMMENT Human time costs more than computer time. I didn't bother to optimize the Perl 5 or Perl 6 solutions. PERL 5 SOLUTION #!/usr/local/bin/perl use warnings; use strict; # Originally I had an overly complex solution. After I did a Perl 6 # solution that used bags (keys are what's in the bag, values are how # many copies of that key are considered "in the bag") I changed this # program to be similar to the Perl 6 program. # Read names. my @name = ; # Get first names. my @first = grep {s/\s.*\n//} @name; # Save the original first names in %first. my %first = (); map {$first{$_} = 1} @first; # Compute all prefixes of @first. my @all = (); foreach my $first (@first) { for my $length (1 .. (length $first) - 1) { push @all, substr($first,0,$length); } } # Make a hash with keys @all and values that are the count of how many # of @all have this key. my %count = (); map {$count{$_}++} @all; # Compute results. my @result = @first; foreach my $candidate (keys %count) { # Don't save candidates that are the same as existing first names. ($first{$candidate}) and next; # Don't save candidates that are not unique. ($count{$candidate} > 1) and next; # If we get here the candidate can be saved as a result. push @result, $candidate; } # Print results. map {print "$_\n"} sort @result; __END__ Abe Lincoln Alan Turing Ben Carson Cat Stevens Cathy Rigby PERL 6 SOLUTION #!/usr/new/bin/perl6 # Complain if Perl 5 tries to run this file. use v6; # Read names. # DATA sections aren't implemented in Perl 6 yet. # I'll use a here document instead. my @name = q:to/END/.lines; Abe Lincoln Alan Turing Ben Carson Cat Stevens Cathy Rigby END # Get first names. my @first = grep {s/\s.*//}, @name; # Save the original first names in %first. my %first = (); map {%first{$_} = 1}, @first; # Compute all prefixes of @first. my @all = (); for @first -> $first { for 1 .. $first.chars - 1 -> $length { push @all, substr($first,0,$length); } } # Make a bag containing all prefixes. my $all-bag = bag @all; # Compute results. my @result = @first; for $all-bag.keys -> $candidate { # Don't save candidates that are the same as existing first names. (%first{$candidate}) and next; # Don't save candidates that are not unique. ($all-bag{$candidate} > 1) and next; # If we get here the candidate can be saved as a result. push @result, $candidate; } # Print results. map {say $_}, sort @result; -mark From mark at purdue.edu Sun Aug 9 04:48:22 2015 From: mark at purdue.edu (Mark Senn) Date: Sun, 09 Aug 2015 07:48:22 -0400 Subject: [Purdue-pm] improved 2015-08-12 challenge problem solution Message-ID: <15470.1439120902@pier.ecn.purdue.edu> PROBLEM DEFINITION SHORTEN NAMES CHALLENGE PROBLEM 2015-08-08 Write Perl 5 and Perl 6 programs to do the following. You are not allowed to use any additional Perl modules. You must only use the built-in features in Perl 5 or Perl 6. Hint: Perl 6 has sets, bags, and mixes, see http://doc.perl6.org/language/setbagmix Read the names from a Perl data section one name per line. Do error checking to make sure you aren't given duplicate first names. If there is a duplicate first name print a "duplicate(s)" line and exit. Given a list of names, shorted the first names as much as possible so they still refer unambigously to a single person. For example, THESE NAMES CAN BE SHORTENED TO ----------- ------------------- Abe Lincoln Ab Abe Alan Turing Al Ala Alan Ben Carson B Be Ben Cat Stevens Cat Cathy Rigby Cath Cathy Abe can't be shorted to A because we'd get Abe Lincoln and Alan Turing confused. Cath is not shortened to Cat because we'd get Cat Stevens and Cathy Rigby confused. The program's output should be the shortened names in sorted order like this: Ab Abe Al Ala Alan B Be Ben Cat Cath Cathy -mark COMMENT Human time costs more than computer time. I didn't bother to optimize the Perl 5 or Perl 6 solutions. PERL 5 SOLUTION #!/usr/local/bin/perl use warnings; use strict; # Originally I had an overly complex solution. After I did a Perl 6 # solution that used bags (keys are what's in the bag, values are how # many copies of that key are "in the bag") I changed this program to # be similar to the Perl 6 program. # Read names. my @name = ; # Get first names. my @first = grep {s/\s.*\n//} @name; # Save the original first names in %first. my %first = (); foreach my $first (@first) { ($first{$first}) and do { print "duplicate(s)\n"; exit 1; }; $first{$first} = 1; } # Compute all prefixes of @first. my @prefix = (); foreach my $first (@first) { for my $length (1 .. (length $first) - 1) { push @prefix, substr $first, 0, $length; } } # Save all prefixes and number of times they exist. my %prefix = (); map {$prefix{$_}++} @prefix; # Compute results. my @result = @first; foreach my $candidate (keys %prefix) { # Don't save candidates that are the same as existing first names. ($first{$candidate}) and next; # Don't save candidates that are not unique. ($prefix{$candidate} > 1) and next; # If we get here the candidate can be saved as a result. push @result, $candidate; } # Print results. map {print "$_\n"} sort @result; __END__ Abe Lincoln Alan Turing Ben Carson Cat Stevens Cathy Rigby PERL 6 SOLUTION #!/usr/new/bin/perl6 # Complain if Perl 5 tries to run this file. use v6; # Read names. # DATA sections aren't implemented in Perl 6 yet. # I'll use a here document instead. my @name = q:to/END/.lines; Abe Lincoln Alan Turing Ben Carson Cat Stevens Cathy Rigby END # Get first names. my @first = grep {s/\s.*//}, @name; # Save the original first names in %first. my %first = (); for @first -> $first { (%first{$first}) and do { say "duplicate(s)"; exit 1; }; %first{$first} = 1; } # Compute all prefixes of @first. my @prefix = (); for @first -> $first { for 1 .. $first.chars - 1 -> $length { push @prefix, substr $first, 0, $length; } } # Save all prefixes and number of times they exist. my $prefix = bag @prefix; # Compute results. my @result = @first; for $prefix.keys -> $candidate { # Don't save candidates that are the same as existing first names. (%first{$candidate}) and next; # Don't save candidates that are not unique. ($prefix{$candidate} > 1) and next; # If we get here the candidate can be saved as a result. push @result, $candidate; } # Print results. map {say $_}, sort @result; -mark From westerman at purdue.edu Sun Aug 9 08:18:04 2015 From: westerman at purdue.edu (Rick Westerman) Date: Sun, 9 Aug 2015 11:18:04 -0400 Subject: [Purdue-pm] Efficiency, was: my 2015-08-12 challenge problem solution In-Reply-To: <26252.1439092694@pier.ecn.purdue.edu> References: <26252.1439092694@pier.ecn.purdue.edu> Message-ID: > COMMENT > > Human time costs more than computer time. I didn't bother to > optimize the Perl 5 or Perl 6 solutions. I think that is a dangerous concept to hold on to. Certainly for one-off programs computer time generally does not matter over human time but if a person gets the idea that human time always trumps computer time then that person can get sloppy to the point that when does he write a production program said program performs poorly. Thinking about order-N effects is, IMHO, always a good idea especially for large data sets. In these ventures/experiments we try to explore the ?many ways to do things? that Perl offers. Some ways are more efficient than others. I am not saying that we should optimize to the last little bit but we should explore and talk about ways to make our code more efficient. For example ? and this has nothing to do with your code ? if I want the last element of parsed string there there are many ways to do that task: 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) ; All three ? $one, $two, $three ? produce the string ?cccc? but they do so with increasing efficiency. Once again not a biggie if the data set is small or if the program is being run once in a blue moon but ? IMO ? programmers who do not give thought to what they are doing when they write small programs will produce inefficient programs when speed does count for something. BTW: I do not wish to hold myself up as a paradigm of always writing efficient code ? I can be just as sloppy as the next person ? but I do try to think of what is happening in the background ? e.g., are unneeded anonymous arrays being produced? -- and the order-N effects. BTW#2: Anyone have an even more efficient way of getting the last element of a list contained in a string? BTW#3: If I have time I?ll go through your Perl5 program and see if I can tease out inefficient code. That could be instructive for all of us (and I hope not displeasing to you). If nothing else this will give me an excuse to look at the code more closely ? maybe I?ll learn something new and efficient. ? Rick From mark at ecn.purdue.edu Sun Aug 9 14:21:16 2015 From: mark at ecn.purdue.edu (Mark Senn) Date: Sun, 09 Aug 2015 17:21:16 -0400 Subject: [Purdue-pm] Efficiency, was: my 2015-08-12 challenge problem solution In-Reply-To: References: <26252.1439092694@pier.ecn.purdue.edu> Message-ID: <44210.1439155276@pier.ecn.purdue.edu> Rick Westerman 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 From westerman at purdue.edu Sun Aug 9 15:01:12 2015 From: westerman at purdue.edu (Rick Westerman) Date: Sun, 9 Aug 2015 18:01:12 -0400 Subject: [Purdue-pm] Efficiency, was: my 2015-08-12 challenge problem solution In-Reply-To: <44210.1439155276@pier.ecn.purdue.edu> References: <26252.1439092694@pier.ecn.purdue.edu> <44210.1439155276@pier.ecn.purdue.edu> Message-ID: <24095992-B65E-4518-9AE8-ADDECB58C12D@purdue.edu> I think the problem is the ? symbol. Evidently my email program made it into an odd character. Try replacing the ? with a proper single quote. -- Rick Westerman westerman at purdue.edu > On Aug 9, 2015, at 5:21 PM, Mark Senn wrote: > > Rick Westerman 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 From mark at ecn.purdue.edu Sun Aug 9 17:54:27 2015 From: mark at ecn.purdue.edu (Mark Senn) Date: Sun, 09 Aug 2015 20:54:27 -0400 Subject: [Purdue-pm] Efficiency, was: my 2015-08-12 challenge problem solution In-Reply-To: <24095992-B65E-4518-9AE8-ADDECB58C12D@purdue.edu> References: <26252.1439092694@pier.ecn.purdue.edu> <44210.1439155276@pier.ecn.purdue.edu> <24095992-B65E-4518-9AE8-ADDECB58C12D@purdue.edu> Message-ID: <24479.1439168067@pier.ecn.purdue.edu> Rick Westerman suggested: | 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) ; EXECUTIVE SUMMARY Use the code for $three. The split function is subtle and it's easy to make a mistake. As far as optimization goes, "first get it working, then make it faster---if needed". DETAILS I am assuming that you want all characters after the second ":" in $data. Call this the third field. The code for $one doesn't work if the third field is "" or "0". The code for $two doesn't work if the third field is "" unless a split with -1 is done. I added the code for $four, which is simpler than $one, and works if the third field is "" or "0", if a split with -1 is done. I added the code for $five which I find more understandable than $two---it must do a split with -1. RUN THIS CODE AND STUDY THE OUTPUT for my $data ('aaa:b:', 'aaa:b:0', 'aaa:b:cccc') { print "data ($data)\n"; my ($one) = reverse grep { $_ } split ':', $data ; my @twoarr = split ':', $data ; my $two = $twoarr[-1] ; my $pos = rindex $data , ':' ; my $three = substr($data, $pos + 1) ; my ($four) = reverse split ':', $data ; my $five = (split ':', $data)[-1]; print "split ($one) ($two) ($three) ($four) ($five)\n"; ($one) = reverse grep { $_ } split ':', $data, -1 ; @twoarr = split ':', $data, -1 ; $two = $twoarr[-1] ; $pos = rindex $data , ':' ; $three = substr($data, $pos + 1) ; ($four) = reverse split ':', $data, -1 ; $five = (split ':', $data, -1)[-1]; print "split with -1 ($one) ($two) ($three) ($four) ($five)\n"; print "----------------------------------------\n"; } # -mark From westerman at purdue.edu Mon Aug 10 05:20:54 2015 From: westerman at purdue.edu (Rick Westerman) Date: Mon, 10 Aug 2015 08:20:54 -0400 Subject: [Purdue-pm] Efficiency, was: my 2015-08-12 challenge problem solution In-Reply-To: <24479.1439168067@pier.ecn.purdue.edu> References: <26252.1439092694@pier.ecn.purdue.edu> <44210.1439155276@pier.ecn.purdue.edu> <24095992-B65E-4518-9AE8-ADDECB58C12D@purdue.edu> <24479.1439168067@pier.ecn.purdue.edu> Message-ID: <8B6D473F-A194-4CE8-B133-20AC9A828B70@purdue.edu> Mark. Thanks for pointing out the subtleties of using split() without the -1. For my example I was assuming actual data in the 3rd field but certainly in non-example real-life code you would want to take care of the edge case either before or during the split(). Your rewrite of #1 into the more simple #4 and the rewrite of #2 into the one line #5 are both valid constructs. However they are not radically different in function from the original construct. What I was trying get at, and still am, is that programmers should think about what their code does instead of just writing any old set of statements and seeing what works. In #1 ? reverse grep split (which is code I have seen in a real working program) ? the program has to (a) make an array, (b) work on each element in the array, (c) make another array, (d) extract the scalar. In #2 ? last index of split ? the program has to (a) make an array, (b) extract the scalar. In #3 ? position of element then substr ? the program has to (a) walk through the original string, (b) extract the scalar. Which construct is faster? If we know what CPU-effort it takes to create arrays or walk through strings (and, as programmers, we should) do we even have to spend a second thinking about the question? > As far as optimization goes, "first get it working, then make it > faster---if needed?. I still think that statement is a crutch for sloppy programming. Sort of akin to ?code first, comment later.? Yeah, it can be done but it isn?t good practice. IMO it takes no more effort to think about the underlying data structures and data manipulation and choose the path of close to minimal (not least) CPU time than to not think about what the computer is doing. This thought process should be second nature to any seasoned programmer just as adding explanatory comments to ones? code ? especially for regexps, IMO -- should be second nature as one is programming. Certainly one wants to avoid optimization until the code is complete. Just as one should avoid full documentation ? user guide, etc. ? until the code is complete. Doing either early will just be a waste of time. People keep quoting Knuth?s statement ?? premature optimization is the root of all evil?? without quoting the first part of that statement ?? we should forget about small efficiencies, say about 97% of the time ?? The keyword is ?small?. Knuth does not give us a license to be sloppy. -- Rick Westerman westerman at purdue.edu > On Aug 9, 2015, at 8:54 PM, Mark Senn wrote: > > Rick Westerman suggested: > | 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) ; > > > EXECUTIVE SUMMARY > > Use the code for $three. > The split function is subtle and it's easy to make a mistake. > As far as optimization goes, "first get it working, then make it > faster---if needed". > > > DETAILS > > I am assuming that you want all characters after the second ":" in $data. > Call this the third field. > > The code for $one doesn't work if the third field is "" or "0". > > The code for $two doesn't work if the third field is "" unless > a split with -1 is done. > > I added the code for $four, which is simpler than $one, > and works if the third field is "" or "0", if a split with -1 is done. > > I added the code for $five which I find more understandable than $two---it > must do a split with -1. > > > RUN THIS CODE AND STUDY THE OUTPUT > > for my $data ('aaa:b:', 'aaa:b:0', 'aaa:b:cccc') > { > print "data ($data)\n"; > > my ($one) = reverse grep { $_ } split ':', $data ; > my @twoarr = split ':', $data ; > my $two = $twoarr[-1] ; > my $pos = rindex $data , ':' ; > my $three = substr($data, $pos + 1) ; > my ($four) = reverse split ':', $data ; > my $five = (split ':', $data)[-1]; > print "split ($one) ($two) ($three) ($four) ($five)\n"; > > ($one) = reverse grep { $_ } split ':', $data, -1 ; > @twoarr = split ':', $data, -1 ; > $two = $twoarr[-1] ; > $pos = rindex $data , ':' ; > $three = substr($data, $pos + 1) ; > ($four) = reverse split ':', $data, -1 ; > $five = (split ':', $data, -1)[-1]; > print "split with -1 ($one) ($two) ($three) ($four) ($five)\n"; > > print "----------------------------------------\n"; > } > > # -mark From mark at ecn.purdue.edu Mon Aug 10 08:35:21 2015 From: mark at ecn.purdue.edu (Mark Senn) Date: Mon, 10 Aug 2015 11:35:21 -0400 Subject: [Purdue-pm] Efficiency, was: my 2015-08-12 challenge problem solution In-Reply-To: <8B6D473F-A194-4CE8-B133-20AC9A828B70@purdue.edu> References: <26252.1439092694@pier.ecn.purdue.edu> <44210.1439155276@pier.ecn.purdue.edu> <24095992-B65E-4518-9AE8-ADDECB58C12D@purdue.edu> <24479.1439168067@pier.ecn.purdue.edu> <8B6D473F-A194-4CE8-B133-20AC9A828B70@purdue.edu> Message-ID: <16355.1439220921@pier.ecn.purdue.edu> Rick Westerman wrote on 2015-08-10 at 08:20:54 -04: > Thanks for pointing out the subtleties of using split() without the -1. > For my example I was assuming actual data in the 3rd field but certainly > in non-example real-life code you would want to take care of the edge > case either before or during the split(). "" or "0" can be actual data or introduced unexpectedly on projects I work on. I learned about the weird but documented behaviour of split when debugging code if I remember right. > Your rewrite of #1 into the more simple #4 and the rewrite of #2 into > the one line #5 are both valid constructs. However they are not > radically different in function from the original construct. What I was > trying get at, and still am, is that programmers should think about what > their code does instead of just writing any old set of statements and > seeing what works. #1: my ($one) = reverse grep { $_ } split ':', $data ; #4: my ($four) = reverse split ':', $data ; >From the grep function documentation at http://perldoc.perl.org/functions/grep.html Evaluates the BLOCK or EXPR for each element of LIST (locally setting $_ to each element) and returns the list value consisting of those elements for which the expression evaluated to true. The grep in #1 is gratuitous and just takes extra time if all elements in $data evaluate to true. If $data is "a:b:0" then $one is set to $b which would be wrong for software I write. I don't do fancy logic in colon separated lists---too complicated. My guess is #4 runs faster because grep is not run. But there is no way to tell for sure without testing it. #4 works better than #1, is simpler, has 2/3 the number of function calls, and probably runs faster---I call that radically different in function. But like I said in my previous message, I liked your #3 the best. It is clear to other humans what you're trying to do and doesn't depend on weird details about how split works. > In #1 ? reverse grep split (which is code I have seen in a real working > program) ? the program has to (a) make an array, (b) work on each > element in the array, (c) make another array, (d) extract the scalar. In #4 - reverse split - the problematic and relatively time consuming grep (see above) doesn't have to run at all. > In #2 ? last index of split ? the program has to (a) make an array, (b) > extract the scalar. > > In #3 ? position of element then substr ? the program has to (a) walk > through the original string, (b) extract the scalar. > > Which construct is faster? If we know what CPU-effort it takes to > create arrays or walk through strings (and, as programmers, we should) > do we even have to spend a second thinking about the question? There is no way to be sure what will run faster without measuring it. Modern software can do lots of weird stuff internally. I once read about a computer manufacturer---I forget which one---that optimized programs that didn't do any I/O down to a noop to run benchmarks faster. But, when writing each statement I try to make a good guess for what will be understandable to humans and also run well. And avoid code that is overly complex. And ask myself if each step of the code is needed so I don't do a gratuitous grep if one is not needed. I sometimes like to string several functions together on a line to finish a thought instead of artificially breaking the line into multiple lines. Some people don't like that but it works well for me, especially in Perl 6 that lets you put function calls in left to right order. On a larger scale I try to make code understandable to a human and also to the computer. And as you suggest, think about order-N issues. When I start a program the first thing I think of is what the overall structure of the program will be and if will satisfy the run time constraints it has. > > As far as optimization goes, "first get it working, then make it > > faster---if needed?. > > I still think that statement is a crutch for sloppy programming. Sort > of akin to ?code first, comment later.? Yeah, it can be done but it > isn?t good practice. IMO it takes no more effort to think about the > underlying data structures and data manipulation and choose the path of > close to minimal (not least) CPU time than to not think about what the > computer is doing. This thought process should be second nature to any > seasoned programmer just as adding explanatory comments to ones? code ? > especially for regexps, IMO -- should be second nature as one is > programming. > > Certainly one wants to avoid optimization until the code is complete. > Just as one should avoid full documentation ? user guide, etc. ? until > the code is complete. Doing either early will just be a waste of time. I like to do statement level optimization of code along with making the code understandable to other people when I type it in. It is faster to do development that way. If I'm writing code to demonstrate an idea sometimes I don't optimize the code---it can mmke it harder to see what I'm trying to demonstrate. > People keep quoting Knuth?s statement ?? premature optimization is the > root of all evil?? without quoting the first part of that statement ?? > we should forget about small efficiencies, say about 97% of the time ?? > > The keyword is ?small?. Knuth does not give us a license to be sloppy. And here's same more context if anyone is interested. >From https://en.wikiquote.org/wiki/Donald_Knuth Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%. See the web page for the original citation. This quote is from the 1970s according to the citation. (Now, at least for me, because I run so many different programs, the easiest and cheapest way to get better software performance, is get a new computer. The 32 GB, Intel Core i7 computer I use now has much better performance that the 28 KB, Digital Equipment Corporation PDP 11V03 I used many years ago. In practice, software performance has been noticably better each time a computer I use has been upgraded.) -mark From jacoby.david at gmail.com Wed Aug 12 08:21:26 2015 From: jacoby.david at gmail.com (Dave Jacoby) Date: Wed, 12 Aug 2015 11:21:26 -0400 Subject: [Purdue-pm] Today's Perl Mongers Meeting Cancelled Message-ID: I am sick. I left work early today. As I'm the organizer and speaker for this evening's meeting, I'm calling it. Will do the on-campus meeting next Tuesday instead. -- David Jacoby jacoby.david at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at purdue.edu Sat Aug 15 18:03:05 2015 From: mark at purdue.edu (Mark Senn) Date: Sat, 15 Aug 2015 21:03:05 -0400 Subject: [Purdue-pm] challenge snippet Message-ID: <48625.1439686985@pier.ecn.purdue.edu> I haven't noticed any replies to the challenge problem, so, in case people don't plan to work on it here is something easier. In Perl 5 and Perl 6, given the scalar $t, show how to delete all ASCII space characters at the beginning and end of that string. Only use statements built in to the version of Perl you are using. -mark From westerman at purdue.edu Sat Aug 15 18:19:36 2015 From: westerman at purdue.edu (Rick Westerman) Date: Sat, 15 Aug 2015 21:19:36 -0400 Subject: [Purdue-pm] challenge snippet In-Reply-To: <48625.1439686985@pier.ecn.purdue.edu> References: <48625.1439686985@pier.ecn.purdue.edu> Message-ID: <23612D06-D529-44B3-A40A-33B41DB49BB2@purdue.edu> Isn?t that just a simple regex? Here is a two liner. $t =~ s/^\s+//; $t =~ s/\s+$//; -- Rick Westerman westerman at purdue.edu > On Aug 15, 2015, at 9:03 PM, Mark Senn wrote: > > I haven't noticed any replies to the challenge problem, > so, in case people don't plan to work on it here is something > easier. > > In Perl 5 and Perl 6, given the scalar $t, show how to delete > all ASCII space characters at the beginning and end of that string. > Only use statements built in to the version of Perl you are using. > > -mark > _______________________________________________ > Purdue-pm mailing list > Purdue-pm at pm.org > http://mail.pm.org/mailman/listinfo/purdue-pm From mark at ecn.purdue.edu Sat Aug 15 20:32:16 2015 From: mark at ecn.purdue.edu (Mark Senn) Date: Sat, 15 Aug 2015 23:32:16 -0400 Subject: [Purdue-pm] challenge snippet In-Reply-To: <23612D06-D529-44B3-A40A-33B41DB49BB2@purdue.edu> References: <48625.1439686985@pier.ecn.purdue.edu> <23612D06-D529-44B3-A40A-33B41DB49BB2@purdue.edu> Message-ID: <27652.1439695936@pier.ecn.purdue.edu> Mark Senn wrote on 2015-08-15 at 21:03 -04: | In Perl 5 and Perl 6, given the scalar $t, show how to delete | all ASCII space characters at the beginning and end of that string. | Only use statements built in to the version of Perl you are using. Rick Westerman wrote on 2015-08-15 at 21:19 -04: | Isn?t that just a simple regex? Here is a two liner. | | $t =~ s/^\s+//; | $t =~ s/\s+$//; This program $t = "\ttesting"; $t =~ s/^\s+//; $t =~ s/\s+$//; ($t eq 'testing') and print "ASCII tab character was deleted\n"; printed ASCII tab character was deleted IMPROVED CHALLENGE SNIPPET STATEMENT In Perl 5 and Perl 6, given the scalar $t---which doesn't contain any "\n" characters---show how to delete all ASCII space characters (ASCII 32 decimal) at the beginning and end of that string. Only use statements built in to the version of Perl you are using. -mark From mark at purdue.edu Sat Aug 15 19:45:31 2015 From: mark at purdue.edu (Mark Senn) Date: Sat, 15 Aug 2015 22:45:31 -0400 Subject: [Purdue-pm] September challenge problem: rank poker hands Message-ID: <19538.1439693131@pier.ecn.purdue.edu> See https://en.wikipedia.org/wiki/List_of_poker_hands for a description of poker hand rankings. Do not read any other information on the web about this problem...either documentation, probability information, Perl modules, any other code in any language, etc. This is a programming challenge, not a challenge about how well one can look up already existing solutions. I'll only discuss any solution I come up with via email so any meeting time can be used to discuss other things. Devise a data structure for poker hands. Write a "rank" sub in Perl 5 and/or Perl 6 using only commands built-in to the language you are using, that given two poker hands dealt from a normal 52 card deck first checks if the hands would be legal in a game of fair poker, return -2 if the hands are not legal in any way. Return -1 if the first hand is ranked below the second hand, 0 if the hands are tied, and 1 if the first hand is ranked above the second hand. Assume aces are used in the way that gives each hand the highest value. Your "rank" sub can call any other subs you write if you want. It is more important that your code be understandable by humans that run the fastest on a computer. -mark From mark at purdue.edu Mon Aug 17 05:04:08 2015 From: mark at purdue.edu (Mark Senn) Date: Mon, 17 Aug 2015 08:04:08 -0400 Subject: [Purdue-pm] Perl 6 weekly report Message-ID: <1316.1439813048@pier.ecn.purdue.edu> >From http://www.perl6.org/ Perl 6 is currently being developed by a team of dedicated and enthusiastic volunteers. I've been using it for simple programs that don't require any external modules and have been very happy with it. I found this Perl 6 weekly report more interesting than most. https://p6weekly.wordpress.com/2015/08/10/2015-32-the-onset-of-upheaval/ Mark Senn, Systems Programmer, Engineering Computer Network, Purdue University From jacoby.david at gmail.com Wed Aug 19 11:52:27 2015 From: jacoby.david at gmail.com (Dave Jacoby) Date: Wed, 19 Aug 2015 14:52:27 -0400 Subject: [Purdue-pm] PerlMongers SIG: Sept 2015 Message-ID: Our presenter will be Joe Kline, talking about developing on the Odroid, a single-board computer similar to the Raspberry Pi. I will try to cross-promote this with Lafayettech Labs, simply because I can. About the Odroid: http://linuxgizmos.com/35-dollar-quad-core-hacker-sbc-offers-rpi-like-expansion/ As he's presenting, I gave him the option, and he's wanting to continue the Mongering after-hours experiment. So, we'll be meeting at 6pm Sept 16 in MatchBox, and move to Lafayette Brewing Company for Open Source Food and Beer and Chat afterward. You are, of course, perfectly welcome to come and talk Perl without going to LBC, or to go to LBC without learning about single-board computers. Please RSVP once the event is entered on opensourcelafayette.org. Thank you. -- David Jacoby jacoby.david at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gribskov at purdue.edu Fri Aug 21 04:07:42 2015 From: gribskov at purdue.edu (Michael Gribskov) Date: Fri, 21 Aug 2015 07:07:42 -0400 Subject: [Purdue-pm] SHORTEN NAMES CHALLENGE PROBLEM Message-ID: <55D7067E.20806@purdue.edu> here are my answers, sorry its a little late due to my out of townness. let me know what you think -------------- next part -------------- A non-text attachment was scrubbed... Name: prefix.pl Type: application/x-perl Size: 6803 bytes Desc: not available URL: From mark at purdue.edu Fri Aug 28 07:43:30 2015 From: mark at purdue.edu (Mark Senn) Date: Fri, 28 Aug 2015 10:43:30 -0400 Subject: [Purdue-pm] new CoderJojo chapter in West Lafayette Message-ID: <44293.1440773010@pier.ecn.purdue.edu> CoderDojo (coderdojo.com) is a "global network of free computer programming clubs for young people." A new chapter is starting in West Lafayette for youth ages 7 to 17. They are having an opening celebration and information session on Saturday, August 29, at 11:30 AM. See coderdojoanvil.com for more information. Mark Senn From mark at purdue.edu Mon Aug 31 09:04:11 2015 From: mark at purdue.edu (Mark Senn) Date: Mon, 31 Aug 2015 12:04:11 -0400 Subject: [Purdue-pm] Perl 6 parallelism, concurrency, and asyncrony Message-ID: <25777.1441037051@pier.ecn.purdue.edu> Jonathan Worthington is the lead developer of Rakudo Perl 6 and the founder and architect of the MoarVM that the mainstream implementation of Perl 6 uses. I found his Parallelism, Concurrency, and Asynchrony in Perl 6 talk at http://yapcasia.org/2015/talk/show/22f59fb8-0fad-11e5-98ef-43ec7d574c3a very good. I've written code outside of Perl in the past to run Perl programs in parallel, one program per core---with the new, elegant parallel stuff in Perl 6 I'll be using that in the future instead of the hack I did. -mark From mark at purdue.edu Mon Aug 31 09:54:19 2015 From: mark at purdue.edu (Mark Senn) Date: Mon, 31 Aug 2015 12:54:19 -0400 Subject: [Purdue-pm] for Emacs users Message-ID: <42551.1441040059@pier.ecn.purdue.edu> Do any Purdue Perl Mongers besides me use Emacs? Following my signature (i.e., "-mark") is some stuff I recently added to my .emacs file to make using Perl 6 easier. The "Package path and loading." stuff will automatically get and install smart-compile and smarter-compile packages. (Don't have to get packages manually when using a new computer.) The "smarter-compile configuration" stuff is used to set up Emacs so it will process files that end in ".p6" with "/usr/new/bin/perl". The global-set-key commands are used so I can type Control-C Control-C to smarter-compile it and confirm that I want to use "/usr/new/bin/perl6". The Emacs window is split into two parts automatically and the program is run in the other window. After that, Control-C Control-R recompiles it using the same Perl 6 executable. I'm looking into packages that read the she-bang line of the file and do the right thing. I'm an ergonomic nut. I use a TypeMatrix 2020 keyboard in Dvorak mode now. See http://www.typematrix.com/shop/ "C" is where "I" is on normal QWERTY keyboards; "R" is where "O" is on normal QWERTY keyboards so the key sequences above are easy to type. My hands are too big to use a Typematrix 2030 keyboard comfortably. I have an ErgoDox kit I need to assemble (see https://www.massdrop.com/buy/infinity-ergodox?mode=guest_open) and ordered a a Keyboardio Model 01 that should come next year (see http://shop.keyboard.io---wish it were made out of plastic instead of wood, but I think only wood is available). If you're interested in these let me know and I'll bring them to a meeting after assembled and received. -mark ; Package path and loading. ; See https://truongtx.me/2013/01/07/emacs-package-manager/ ;;; Emacs is not a package manager, and here we load its package manager! (require 'package) (dolist (source '(("marmalade" . "http://marmalade-repo.org/packages/") ("elpa" . "http://tromey.com/elpa/") ("melpa" . "http://melpa.milkbox.net/packages/") )) (add-to-list 'package-archives source t)) (package-initialize) ;;; Required packages ;;; everytime emacs starts, it will automatically check if those packages are ;;; missing, it will install them automatically (when (not package-archive-contents) (package-refresh-contents)) (defvar tmtxt/packages '(smart-compile smarter-compile)) (dolist (p tmtxt/packages) (when (not (package-installed-p p)) (package-install p))) ; smarter-compile configuration ; See https://marmalade-repo.org/packages/smarter-compile ; M-x recompile just does the last command as last time without prompting. (require 'smarter-compile) (add-to-list 'smart-compile-alist '("\\.p6\\'" . "/usr/new/bin/perl6 %f")) (global-set-key "\C-c\C-c" 'smarter-compile) (global-set-key "\C-c\C-r" 'recompile) From mdw at purdue.edu Mon Aug 31 10:38:18 2015 From: mdw at purdue.edu (Mark Daniel Ward) Date: Mon, 31 Aug 2015 13:38:18 -0400 Subject: [Purdue-pm] for Emacs users In-Reply-To: <42551.1441040059@pier.ecn.purdue.edu> References: <42551.1441040059@pier.ecn.purdue.edu> Message-ID: <55E4910A.6030004@purdue.edu> Dear Mark, I'm an emacs fanatic too. Thanks for sharing this information! Mark On 8/31/15 12:54 PM, Mark Senn wrote: > Do any Purdue Perl Mongers besides me use Emacs? > > Following my signature (i.e., "-mark") is some stuff I recently added to > my .emacs file to make using Perl 6 easier. > > The "Package path and loading." stuff will automatically get and install > smart-compile and smarter-compile packages. (Don't have to get packages > manually when using a new computer.) > > The "smarter-compile configuration" stuff is used to set up Emacs so it > will process files that end in ".p6" with "/usr/new/bin/perl". > > The global-set-key commands are used so I can type Control-C Control-C > to smarter-compile it and confirm that I want to use "/usr/new/bin/perl6". > The Emacs window is split into two parts automatically and the program is run > in the other window. After that, Control-C Control-R recompiles it using > the same Perl 6 executable. I'm looking into packages that read the > she-bang line of the file and do the right thing. > > I'm an ergonomic nut. I use a TypeMatrix 2020 keyboard in Dvorak mode > now. See > http://www.typematrix.com/shop/ > "C" is where "I" is on normal QWERTY keyboards; "R" is where "O" is on > normal QWERTY keyboards so the key sequences above are easy to type. My > hands are too big to use a Typematrix 2030 keyboard comfortably. I have > an ErgoDox kit I need to assemble (see > https://www.massdrop.com/buy/infinity-ergodox?mode=guest_open) and > ordered a a Keyboardio Model 01 that should come next year (see > http://shop.keyboard.io---wish it were made out of plastic instead of > wood, but I think only wood is available). If you're interested in these > let me know and I'll bring them to a meeting after assembled and received. > > -mark > > ; Package path and loading. > ; See https://truongtx.me/2013/01/07/emacs-package-manager/ > ;;; Emacs is not a package manager, and here we load its package manager! > (require 'package) > (dolist (source '(("marmalade" . "http://marmalade-repo.org/packages/") > ("elpa" . "http://tromey.com/elpa/") > ("melpa" . "http://melpa.milkbox.net/packages/") > )) > (add-to-list 'package-archives source t)) > (package-initialize) > ;;; Required packages > ;;; everytime emacs starts, it will automatically check if those packages are > ;;; missing, it will install them automatically > (when (not package-archive-contents) > (package-refresh-contents)) > (defvar tmtxt/packages > '(smart-compile smarter-compile)) > (dolist (p tmtxt/packages) > (when (not (package-installed-p p)) > (package-install p))) > > ; smarter-compile configuration > ; See https://marmalade-repo.org/packages/smarter-compile > ; M-x recompile just does the last command as last time without prompting. > (require 'smarter-compile) > (add-to-list > 'smart-compile-alist > '("\\.p6\\'" . "/usr/new/bin/perl6 %f")) > > (global-set-key "\C-c\C-c" 'smarter-compile) > (global-set-key "\C-c\C-r" 'recompile) > _______________________________________________ > Purdue-pm mailing list > Purdue-pm at pm.org > http://mail.pm.org/mailman/listinfo/purdue-pm