CY's Take on Perl Weekly Challenge #052
This is a part of Perl Weekly Challenge(PWC) #052 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.
Do tell me if I am wrong or you strongly oppose my statements!
I register a free account on blogs.perl.org . The process is surprisingly easy but I am a bit nervous that my posts are put along those of experienced coders on the frontpage of blogs.perl.org .
Back to the main topic.
The first challenge is typical for PWC. Integers in base-10 with some properties on or among their digits, and the perl script needs to list it out. A very useful code slice is split //, $num . (For beginners: On other programming languages, usually we need to have a line of code which change the type of our variable; or more commonly seen, make a new variable of a different type of that variable. An example is to_string in C++. )
The second challenge is game theoretical. I think there are no shortcuts for this problem. I dug out a textbook on game theory #1, got back on the Coursera Course "Combinatorial Game Theory". #2 ... Finally, I find the challenge does not require advanced understanding of Prisoners' Dilemma or Nim. All we need to know is how to draw a game tree, how to count the payoff properly and how to code in Perl!
The procedure is: go forward for calculating the payoff function for every end node, and then having a backward induction. Then we get who the winner is while the game is played optimally. (Along process, the information gained can provide a method to allow the computer play against a human optimally.)
Writing this blog post reminds me that my code for the second challenge is quite different from the question statement. Maybe I should edit codes and resubmit it as it's Friday only.
#1 That book was freely available on Internet but now published by Princeton University Press. It is by Stephen Schecter and Herbert Gintis.
#2 When I watched one of the videos (...I skipped it before) of Week 1, though the coin-taking game is a "game without chance", I learnt the definition of a "combinatorial game"; and, the coin-taking game is not a "combinatorial game". A combinatorial game has to be finite, two-player, no-draw-allowed, information-complete and no-randomization. The course is freely available on
https://www.coursera.org/learn/combinatorial-game-theory/ by Dr. Tom Morley.
Update on March 21st (Sat):
Thanks Toby(ink) for pointing out the "shortcut". XD
Thanks Ryan and Mohammad for suggesting that I publish a Perl-related blog.