LaurentRosenfeld / Perl-6-Miscellaneous

2 stars 5 forks source link

Solutions for challenge 25 #5

Closed jaldhar closed 5 years ago

jaldhar commented 5 years ago

Once again I missed the deadline for that week but I did eventually complete the tasks. If you would like to take a look, my blog post is at https://www.braincells.com/perl/2019/09/perl_weekly_challenge_week_25.html and there are links to the actual scripts there.

If you can spare the time, I would be particularly interested in your opinion on my Perl6 solution for the Pokemon problem. I didn't expect my code to be very fast with that algorithm but it is unbelievably slow. What's the reason?

Oh and on a minor note, in several places, you have written my name as Jaldhar M. Vyas. My middle initial is actually H. It's a patronym; my fathers' name was Harshad. But then my mothers name is Manorama so it's kind of correct. :-)

LaurentRosenfeld commented 5 years ago

Hi Jaldhar, I will update my review to include your contribution, but it might take a few days as I have very little time this week. I will also take a look at your P6 solution and see if I can find out why it is so slow, but again it might take a few days.

Sorry about misspelling your middle name, for a couple of weeks I thought it was "M". I'll fix that as soon as possible. Best, Laurent.

LaurentRosenfeld commented 5 years ago

Jaldhar, if you look at my original blog post (http://blogs.perl.org/users/laurent_r/2019/09/perl-weekly-challenge-25-pokemon-sequence-and-chaocipher.html), you'll see that my P5 solution runs in 35 seconds and my first P6 solution in 8 minutes. The revised P6 version still takes four and a half minutes. So P6 is definitely slower than P5 for this type of task. The one thing you could do to speed up your algorithm is to use the same thing as I did (and most other challengers), i.e. build before you start a hash of arrays of all possible successors for each name or for each final letter. This reduces considerably the number of candidates to test. I'll look more at your blog post later.

BTW, I fixed your middle name on all my posts.

LaurentRosenfeld commented 5 years ago

Jaldhar, please disregard my previous comment on building a hash of arrays, you're basically doing the same thing in the graph subroutine which I had overlooked.

The other thing you might do to speed up your program is to use a set or a hash to record the names already in the current sequence (what I do in the $seen set), which would probably provide faster lookup than your if @path.grep(none /$neighbor/) { ... code.

LaurentRosenfeld commented 5 years ago

Jaldhar, I have updated my two reviews for week 25 challenge to include your contributions.

I hope you'll find them satisfactory. Please let me know whether I can close your issue (or close it yourself if you prefer).

Cheers, Laurent.

jaldhar commented 5 years ago

Hello Laurent,

Sorry to keep cluttering up your issues list with unclosed issues. I was in India for a couple of weeks and I had no Internet access. I just wanted to mention that I had tried your suggestion of keeping a hash of visited nodes in the graph but that made negligble impact on the run time. The only thing which had any impact was removing is copy from traverse()'s signature. (i.e pass @path by reference instead of by value.) But then of course you get the wrong answer. Hopefully this can be fixed but the fix will have to be done by better men than I.

Also I just wanted to mention that now I'm back I've caught up with the other weeks I've missed (27, 28, and 29) if you would like to take a look.

https://www.braincells.com/perl/2019/10/perl_weekly_challenge_weeks_27-28.html

https://www.braincells.com/perl/2019/10/perl_weekly_challenge_week_29.html

LaurentRosenfeld commented 5 years ago

Hi Jaldhar,

I have added your contributions to five existing reviews and will add the last one to the review on C function, still in progress. I hope you'll find is satisfactory.

Note that I unfortunately made a typo on your first name in the commit message for three of the reviews, but I don't think I can modify these commit messages. I'm sorry about that, but the blog posts themselves should hopefully be correct.

I'll try to look again at your Pokemon sequence graph this weekend, if times permits.

Best, Laurent.