From mark at purdue.edu Sun Jul 14 17:30:07 2019 From: mark at purdue.edu (Mark Senn) Date: Sun, 14 Jul 2019 20:30:07 -0400 Subject: [Purdue-pm] Perl Weekly Challenge 016 Task #1 Message-ID: <48433.1563150607@pier.ecn.purdue.edu> I got the right answer to the wrong question for the Perl Weekly Challenge - 016, Task #1. Thought you might be interested in it anway. It's at https://engineering.purdue.edu/~mark/pwc-016.pdf and has Wolfram Language (Mathematica) and Perl 6 solutions. It has a sentence inspiried by the lyrics of the song "In The Year 2525" and compares hard-to-follow mathemagical solutions in lectures to throwing flashbang grenades from a car during a drive-by derivation. The Perl 6 code is typeset using a style similar to Don Knuth's Literate Programming system. -mark From mark at purdue.edu Wed Jul 17 07:22:09 2019 From: mark at purdue.edu (Mark Senn) Date: Wed, 17 Jul 2019 10:22:09 -0400 Subject: [Purdue-pm] Perl Weekly Challenge hints Message-ID: <46171.1563373329@pier.ecn.purdue.edu> Why yes---I am trying to get people interested in Perl 6. You'll thank me in the long run I think. Perl 6 hints to this week's Perl Weekly Challenge See https://perlweeklychallenge.org/blog/perl-weekly-challenge-017/ for this week's weekly challenge Hints to https://perlweeklychallenge.org/blog/perl-weekly-challenge-017/#task-1 multi A(Int $m, Int $n where $m == 0) { return $n + 1 } multi A(Int $m, Int $n where $m > 0 && $n > 0) { return A($m-1, A($m,$n-1)) } say A(1, 2); Hints to https://perlweeklychallenge.org/blog/perl-weekly-challenge-017/#task-2 https://docs.perl6.org/language/regexes especially https://docs.perl6.org/language/regexes#Capturing_groups use ':' (including the quotes) to match a colon literally use <[a..z]> to match a lowercase letter https://docs.perl6.org/language/grammars/#Named_Regexes demos named regexes https://docs.perl6.org/language/regexes#Named_captures demos named captures -mark From mark at purdue.edu Sun Jul 28 20:33:21 2019 From: mark at purdue.edu (Mark Senn) Date: Sun, 28 Jul 2019 23:33:21 -0400 Subject: [Purdue-pm] Perl Challenge 018 Message-ID: <3377.1564371201@pier.ecn.purdue.edu> My blog about Perl Weekly Challenge - 018 is at https://engineering.purdue.edu/~mark/pwc-018.pdf It contains the two task descriptions and my Perl 6 (Perl 5 completely redesigned and rewritten from the ground up, even code as simple as $array[1] = 1 doesn't work now---but it is worth it---Perl 6 is a much better language) code to solve the problems. I quote Jeff Atwood's "The Best Code is No Code At All" and Randall Munroe's xkcd comic strip because many of the solutions to the challenges are way over-engineered. Task #1: print the longest common substring in two or more substrings. Answer highlights: Put all substrings for word[i] in set[i] and use Perl 6's set intersection hyperoperator to find the longest substring. Task #2: implement priority queues. Answer doesn't use classes or methods I had to write. Just two parallel arrays. First get it working and if needed, then make it better. And because the specs for the problems don't give any info about space or time constraints there is no need to make it better. -mark From mdw at purdue.edu Sun Jul 28 20:54:28 2019 From: mdw at purdue.edu (Ward, Mark Daniel) Date: Mon, 29 Jul 2019 03:54:28 +0000 Subject: [Purdue-pm] Perl Challenge 018 In-Reply-To: <3377.1564371201@pier.ecn.purdue.edu> References: <3377.1564371201@pier.ecn.purdue.edu> Message-ID: Dear Mark, I might be misreading your email, but I think you are suggesting in Task #1 to use a brute force solution.? If you touch all substrings for a word, then you will take a length of time that is exponential in the length of the word.? In contrast, however, there is actually a solution that is linear in terms of the length of the words. https://en.wikipedia.org/wiki/Longest_common_substring_problem The suffix tree solution -- which yields this optimal solution -- is really beautiful in its own right, and it doesn't need to be a bunch of complicated code.? It can be done easily, especially if you have a library with a suffix tree included.? I don't think this is over-engineering.? I think it gets to the heart of the solution. So I find it hard to get excited about your suggestion to "put all substrings for word[i] in set[i]" because this will take an exponential number of steps, in terms of the length of the word, and that is entirely inefficient. Am I saying something stupid?? Maybe!? That is the danger of writing an email late at night.? Well, it's only 10 PM here (not midnight) since I'm in Denver at the moment, but that is still relatively late for me. Warmest regards, Mark On 7/28/19 11:33 PM, Mark Senn wrote: > My blog about Perl Weekly Challenge - 018 is at > https://engineering.purdue.edu/~mark/pwc-018.pdf > > It contains the two task descriptions and my Perl 6 (Perl 5 completely > redesigned and rewritten from the ground up, even code as simple as > $array[1] = 1 doesn't work now---but it is worth it---Perl 6 is a > much better language) code to solve the problems. > > I quote Jeff Atwood's "The Best Code is No Code At All" and Randall > Munroe's xkcd comic strip because many of the solutions to the > challenges are way over-engineered. > > Task #1: print the longest common substring in two or more substrings. > Answer highlights: Put all substrings for word[i] in set[i] and use > Perl 6's set intersection hyperoperator to find the longest substring. > > Task #2: implement priority queues. Answer doesn't use classes or > methods I had to write. Just two parallel arrays. > > First get it working and if needed, then make it better. And because > the specs for the problems don't give any info about space or time > constraints there is no need to make it better. > > -mark > _______________________________________________ > Purdue-pm mailing list > Purdue-pm at pm.org > https://mail.pm.org/mailman/listinfo/purdue-pm From mdw at purdue.edu Mon Jul 29 02:29:20 2019 From: mdw at purdue.edu (Ward, Mark Daniel) Date: Mon, 29 Jul 2019 09:29:20 +0000 Subject: [Purdue-pm] Perl Challenge 018 In-Reply-To: References: <3377.1564371201@pier.ecn.purdue.edu>, Message-ID: <28163B98-444D-436C-B536-6F836E5636C4@purdue.edu> Dear Mark, I think I did write something stupid last night, namely, I think I wrote that the brute force solution is exponential, but it might only be quadratic. Still a lot worse than linear! Warmest regards, Mark > On Jul 28, 2019, at 9:54 PM, Ward, Mark Daniel wrote: > > Dear Mark, > > I might be misreading your email, but I think you are suggesting in Task #1 to use a brute force solution. If you touch all substrings for a word, then you will take a length of time that is exponential in the length of the word. In contrast, however, there is actually a solution that is linear in terms of the length of the words. > > https://en.wikipedia.org/wiki/Longest_common_substring_problem > > The suffix tree solution -- which yields this optimal solution -- is really beautiful in its own right, and it doesn't need to be a bunch of complicated code. It can be done easily, especially if you have a library with a suffix tree included. I don't think this is over-engineering. I think it gets to the heart of the solution. > > So I find it hard to get excited about your suggestion to "put all substrings for word[i] in set[i]" because this will take an exponential number of steps, in terms of the length of the word, and that is entirely inefficient. > > Am I saying something stupid? Maybe! That is the danger of writing an email late at night. Well, it's only 10 PM here (not midnight) since I'm in Denver at the moment, but that is still relatively late for me. > > Warmest regards, > > Mark > > >> On 7/28/19 11:33 PM, Mark Senn wrote: >> My blog about Perl Weekly Challenge - 018 is at >> https://engineering.purdue.edu/~mark/pwc-018.pdf >> >> It contains the two task descriptions and my Perl 6 (Perl 5 completely >> redesigned and rewritten from the ground up, even code as simple as >> $array[1] = 1 doesn't work now---but it is worth it---Perl 6 is a >> much better language) code to solve the problems. >> >> I quote Jeff Atwood's "The Best Code is No Code At All" and Randall >> Munroe's xkcd comic strip because many of the solutions to the >> challenges are way over-engineered. >> >> Task #1: print the longest common substring in two or more substrings. >> Answer highlights: Put all substrings for word[i] in set[i] and use >> Perl 6's set intersection hyperoperator to find the longest substring. >> >> Task #2: implement priority queues. Answer doesn't use classes or >> methods I had to write. Just two parallel arrays. >> >> First get it working and if needed, then make it better. And because >> the specs for the problems don't give any info about space or time >> constraints there is no need to make it better. >> >> -mark >> _______________________________________________ >> Purdue-pm mailing list >> Purdue-pm at pm.org >> https://mail.pm.org/mailman/listinfo/purdue-pm From mark at purdue.edu Mon Jul 29 05:34:52 2019 From: mark at purdue.edu (Mark Senn) Date: Mon, 29 Jul 2019 08:34:52 -0400 Subject: [Purdue-pm] good Perl 6 article Message-ID: <31230.1564403692@pier.ecn.purdue.edu> There is a good Perl 6 article at http://blogs.perl.org/users/damian_conway/2019/07/six-slices-of-pie.html about the following problem First person gets 1% of a pie, secord person gets 2% of the remaining pie, etc. Which person gets the largest piece of pie. Handy takeaway: instead of typing $x/100 do sub postfix:<%> (Numeric $x) { $x / 100 } to make a % postfix operator and type $x%. Last line from article: Because people shouldn't have to adapt to the needs of programming languages; programming languages should adapt to the needs of people. -mark From mark at ecn.purdue.edu Mon Jul 29 07:37:40 2019 From: mark at ecn.purdue.edu (Mark Senn) Date: Mon, 29 Jul 2019 10:37:40 -0400 Subject: [Purdue-pm] Perl Challenge 018 In-Reply-To: References: <3377.1564371201@pier.ecn.purdue.edu> Message-ID: <34380.1564411060@pier.ecn.purdue.edu> > I might be misreading your email, but I think you are suggesting in Task > #1 to use a brute force solution.? If you touch all substrings for a > word, then you will take a length of time that is exponential in the > length of the word.? In contrast, however, there is actually a solution > that is linear in terms of the length of the words. > > https://en.wikipedia.org/wiki/Longest_common_substring_problem > > The suffix tree solution -- which yields this optimal solution -- is > really beautiful in its own right, and it doesn't need to be a bunch of > complicated code.? It can be done easily, especially if you have a > library with a suffix tree included.? I don't think this is > over-engineering.? I think it gets to the heart of the solution. Hi Mark, Yes, I suggested using a brute force solution to find the longest common substring of "ABABC", "BABCA", and "ABCBA". The challenge didn't say anything about any space restraints, time constraints, or if the solution would be usedd for bigger problemms. The challenge used to include the critieria of only use Perl 5 or Perl 6 but no extra modules so I didn't use anything not built-in. (I don't see that criteria listed on the web page now.) I was trying to get a solution that was easy to understand and worked with as little time investment as possible. Human time is more expensive than computer time. The solution worked using Perl 6 stuff I already knew. I agree with you, if the problem was bigger and needed to be solved to be solved using less computer time or space I should have used a different method. (At a recent Perl Mongers meeting I think Joe Kline may have used the phrase "conserving a limitless resource" in connection with there is an abundance of computer time and space to work on small problems.) -mark From mdw at purdue.edu Tue Jul 30 05:05:11 2019 From: mdw at purdue.edu (Ward, Mark Daniel) Date: Tue, 30 Jul 2019 12:05:11 +0000 Subject: [Purdue-pm] Perl Challenge 018 In-Reply-To: <34380.1564411060@pier.ecn.purdue.edu> References: <3377.1564371201@pier.ecn.purdue.edu> <34380.1564411060@pier.ecn.purdue.edu> Message-ID: <9ccb15ef-8cbe-932b-82be-fd3fb4e2b661@purdue.edu> Dear Mark, Aha!? I understand your motivation.? Thanks for sharing! I wonder if you ever worked on the Project Euler problems? https://projecteuler.net/ I think that these problems require "efficient" solutions, i.e., they will have some problems for which it is necessary to have small space requirements and/or fast execution time.? I think that there is a 1-minute execution rule on the site.? This prevents some brute-force solutions, to some of the harder problems. I'm guessing that you know about this site.... but just curious! Warmest regards, Mark On 7/29/19 10:37 AM, Mark Senn wrote: >> I might be misreading your email, but I think you are suggesting in Task >> #1 to use a brute force solution.? If you touch all substrings for a >> word, then you will take a length of time that is exponential in the >> length of the word.? In contrast, however, there is actually a solution >> that is linear in terms of the length of the words. >> >> https://en.wikipedia.org/wiki/Longest_common_substring_problem >> >> The suffix tree solution -- which yields this optimal solution -- is >> really beautiful in its own right, and it doesn't need to be a bunch of >> complicated code.? It can be done easily, especially if you have a >> library with a suffix tree included.? I don't think this is >> over-engineering.? I think it gets to the heart of the solution. > Hi Mark, > > Yes, I suggested using a brute force solution to find the longest common > substring of "ABABC", "BABCA", and "ABCBA". The challenge didn't say > anything about any space restraints, time constraints, or if the > solution would be usedd for bigger problemms. The challenge used to > include the critieria of only use Perl 5 or Perl 6 but no extra modules > so I didn't use anything not built-in. (I don't see that criteria > listed on the web page now.) I was trying to get a solution that was > easy to understand and worked with as little time investment as > possible. Human time is more expensive than computer time. The > solution worked using Perl 6 stuff I already knew. I agree with you, if > the problem was bigger and needed to be solved to be solved using less > computer time or space I should have used a different method. (At a > recent Perl Mongers meeting I think Joe Kline may have used the phrase > "conserving a limitless resource" in connection with there is an > abundance of computer time and space to work on small problems.) > > -mark