Sunday, March 23, 2008

After several attempts to get Google to index my server at home on my DSL (using a hostname, of course), I decided I needed to set up a more "legitimate" host. So, I bought a VPS instance at for $9.99 a month so I could mess around with my own Ruby on Rails apps.

I tried to use some of the pointers I got from The Principles of Beautiful Web Design, which I finished reading last week, and ended up with a logo and welcome page that I can actually be proud of! Ok, so it's not much, but now I have a home for StampCalculator so people can actually discover and use it.

Thursday, March 6, 2008

Werewolf: Kill the quiet people!

Well, today I had the opportunity to be the storyteller in a game of Werewolf at our L.A. Times gaming lunch. Having played as a werewolf in the last three games in a row, I figured the villagers were going to kill me in the first round anyway, so why not be the moderator and break my streak? Today, we went down to two werewolves, after three werewolves have won every one of the last 4 games, with 10-14 players total. I'm promoting a handicapping strategy similar to what we use in Go. Basically, the villagers are trying to handle as many werewolves as possible. So, if one side wins 3 games in a row, you increase or decrease the number of werewolves by 1. As the moderator, I got to immediately see what role each player had, from the very beginning. So I got to see the seer accuse the one person she knew was a villager in the first round! I thought this was a clever ruse at the time, but in hindsight, the only person she fooled by this was a villager. Oh, well. I guess that's my "werewolf logic" showing through! Anyway, to the point: The villagers lost again. However, if they had stuck to the rule of "kill the quiet people first", they would have won. Why? The werewolves were quiet. Now, pay attention because I think this next bit is the thing people haven't been getting: If you have a policy of "kill the quiet people", you force the werewolves to participate! Werewolves are liars, and when you're a liar, you don't want to draw attention to yourself. So if the villagers show that they're intent on killing quiet people, the werewolves have no choice but to participate in the conversation. By smoking them out in this fashion (and not letting quiet people off because "we don't think that person is really a werewolf"), you force the werewolves to participate, and you might catch them in a lie. Update: I remembered what's so clever about the seer accusing an innocent person. It fools the werewolves, who are looking to kill the seer as quickly as possible. Bonus points if the seer gets a quiet person in this fashion, because that helps to flush out the wolves. While they're off the scent of the seer, the seer can continue to gather data about everybody.

Monday, March 3, 2008

Improbable Truths in Ruby

The following statements are all true in Ruby 1.8.6: 0.6 - 0.5 < 0.1 (0.29 * 100).to_i == 28 0.28 * 100 != 28 (0.28 * 100).to_i == 28 (0.27 * 100) == 27 Well, what can I say? Floating point errors in Ruby can really bite you. I had always thought higher precision numbers were necessary only when dealing with very small numbers or when computing compound interest, but look out! Ruby floating point can really bite you with some strange, unexpected results. It makes me wonder why Matz included a to_i method at all!

Saturday, March 1, 2008

Weird Floating Point Problem in Ruby

I'm working on a simple postage stamp calculator, just one of several projects I have for some Ruby on Rails practice. So I set up my rspec tests and find that one of my tests is failing. After stepping through the test, I found something that I find very surprising: 0.5 - 0.4 < 0.1: irb(main):001:0> 0.5-0.4 => 0.1 irb(main):002:0> 0.5-0.4<0.1 => true irb(main):003:0> ((0.5-0.4)*10) => 1.0 irb(main):004:0> ((0.5-0.4)*10).to_i => 0 irb(main):005:0> ((0.5-0.4)*20).to_i => 1 irb(main):006:0> ((0.5-0.4)*20) => 2.0 ...well, this certainly violates the principle of least astonishment, but I guess the lesson is that I should be using values in terms of pennies (ie, integers not floats).