CY's take on PWC#054
This is a part of Perl Weekly Challenge(PWC) #054 and the followings are related to my solution. If you want to challenge yourself on Perl, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email) if possible, before reading my blog post.
My laptop spent about 40.5 hours for calculating the list for the extra credit in task #2. While it was calculating, I found that my code hadn't been optimized. Anyway, even if I optimized it by 50%, the wait of 20 hours could still be a record for an impatient and blunt person like me.
2nd Apr, 2020
time | number_reached
1427 1
1745 309560
1809 325441
1831 339572
1852 353486
1951 386882
2205 453250
2253 475841
2308 482951
2358 502248
3rd Apr, 2020
time | number_reached
0419 600125
1405 772771
1534 794982
1538 796651
1543 798343
1555 800112 At this point, I realized that I should do more optimization.
1558 801872
1607 803625
1630 808808
1724 822777
1730 824482
1955 859075
4th Apr, 2020
time | number_reached
0519 980874
0636 994616
0653 1000000
Being afraid of losing the data, I did not use the laptop for other tasks. And, I am living in a hostel-like environment; continuous occupying the electrical plug is not a sensible action. Luckily the staff of my room is sensible enough...
I want to implement a binary tree for the integers, such that, for instance, I want to list the sequence for 13, the program can just trace the "ancestries". However, I am not good at handling references. I kept puzzled with my codes. No codes to be provided in blogpost this week.
(After having the list, I am going to use selection algorithm to get the top 20 "drunkers".)
--
Some feedback on my performance/blogpost PWC#053:
- I was having indulgence of bad(unedited) script of "the simple verison" in the task #1.
- $class = $module = $package in OO sense... (ref: Section 1.3, "Object Oriented Perl" by Damian Conway)
- Though reading others' code, there is an easy way put the module inside a script:
instead of
#!/usr/bin/perl
use strict;
use xy.pm; #require the user inconveniently
#put the module in the right directory
# inside his/her disk
we can just do
#!/usr/bin/perl
use strict;
{
package xy;sub new {
my ($class) = @_;
bless{
_value=> $_[1],
_x=>$_[2],
_y=>$_[3],
}, $class;
}sub #...
}
Anyway, I found I have devoted more and more time on PWC and Perl. Well, on the positive side: I can learn to be a good coder sooner.
My scirpts is on https://github.com/manwar/perlweeklychallenge-club/tree/master/challenge-054/cheok-yin-fung/perl
Hi,
using a cache, I was able to run the extra credit in 1 min 7 sec. Take a look at my blog post to see the details.
Cheers, Laurent.