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.

---
Remarks:

#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.

---
My code is on https://github.com/manwar/perlweeklychallenge-club/tree/master/challenge-052/cheok-yin-fung/perl

3 Comments

The second challenge is kind of boring from a game theory perspective. Whoever gets the £2 coin wins automatically. The other coins only add up to £1.88, so even if you somehow got ALL the other coins, you'd lose. The £2 coin is even more OP than the golden snitch. (Harry Potter reference.)

The game could be made a lot more interesting if there were three 50p, 20p, and 10p coins, and five 5p, 2p, and 1p coins. That way, even if your opponent gets the £2 coin, if you can secure the £1 coin, you still have a potential path to victory.

I didn't realise it until now the point you raised. I missed the opportunity to make it more challenging. Thanks for the idea, though.

Congratulation on your first blog about your contributions. I just love reading blog and find it very informative.

Leave a comment

About C.-Y. Fung

user-pic This blog is inactive and replaced by https://e7-87-83.github.io/coding/blog.html ; but I post highly Perl-related posts here.