September 30, 2010

Some Professor Layton Prolog!

Time to combine two of my favorite things: Professor Layton and obscure languages! There was one puzzle (of the hardest difficulty) that I could have spent 40 minutes working out, but instead spent an hour and half solving in Prolog (for those unfamiliar with Prolog, check out this post for a description of what this magic language is!).

I'll post the puzzle and solution here; hopefully someone finds it fun!


No 151 from Professor Layton and the Diabolical Box: Colin's Score


Four students took a test where every question had two possible answers, A or B. Each question was worth 10 points, for a total of 100 points.

The students' test results were posted as seen below, but the teacher forgot to tally Colin's score. Colin was heading to the teacher's office when Mary called him back, saying they could figure out his score using the results from the other tests. Can you figure out Colin's score?

Mary: 70 points


12345678910
BBABABBABB


Dan: 50 points


12345678910
BAAABABAAA


Lisa: 30 points


12345678910
BAAABBBABA


Colin: ?? points


12345678910
BBAAABBAAA

-----

Below is the program I wrote to solve it. Verbose by contemporary language standards, but almost no thinking required, and the answer in an instant! Note the original version didn't have so many comments; these are to guide the curious reader. Sadly, github's gists don't know how to color Prolog syntax. Also, due to this terribly lame layout, I would suggest the 'view raw' feature at the bottom of the gist to see it in plaintext glory.



Edit: I also gist-ed my Prolog poker solver, which I wrote about in my first Prolog post. It was my very first prolog, and there are probably shorter ways of doing what I did, but hey! Give it a looksee and hope you enjoy it ^_^

No comments:

Post a Comment