You're now viewing all of my posts relating to Ruby. Enjoy!

Link Crawler Again

Whoops. I got everything fixed with the file format issues. Steve, check out the Google Code Repository for a version of the script that should actually work.


Lunch With David Yields a Link Crawler

I had tasty lunch with David at the China Restaurant yesterday. It was good to see an old friend that I met on the Internet ages ago. Hopefully sometime soon I'll get to see his babby.

Anyway, he mentioned that he was in need of a link crawler while at lunch yesterday. As we all know, I have trouble resisting psuedo-challenges like that... and oh look. What's this? Could it be? A garbage file? Put there by none other than Elingson's elite sysadmin... oh, what's this? Is this the secret bank account that the money was stashed in? Oh, I think it is. Man. You know, I kind of feel like God...

Oh, wait... sorry. Really and truly, it would appear as though rather than my usual night of BioShock and/or Metroid Prime: 3 I tore myself away to write some code. Well David, here's your link crawler! It's not heavily tested or terribly robust, but it runs against a handful of test sites and I think it does exactly what you described.

Update - 2007/10/02

I've published a bazaar repository for this project. You can find information and an updated version of this file at this posting.


Computing Royal Flush Probabilities in Ruby

In a surprising turn of events the other day, I actually willingly performed some math. Andy mentioned the odds (different from probability!) of getting a Royal Flush in a game of poker... well intrigued I decided to go about modeling it in Ruby. Maybe I'll try Haskell later...

cards=52
hand=5
winning_combinations=4.00

def factorial(n)
  (n==1) ? n : n*factorial(n-1)
end

combinations=factorial(cards)/( factorial(hand) \
             * factorial(cards - hand) )
p=(winning_combinations/combinations.to_f)
o=p/(1-p)

printf("Combinations: %d\n", combinations)
printf("Winning Combo: %d\n", winning_combinations)
printf("Probability: %0.07f\n", p)
printf("Odds: %0.07f OR %0.07f:%0.07f\n", o, p, (1-p) )
printf("Adjusted Odds: %d:%d\n", 1, \
      (combinations-winning_combinations)/winning_combinations )
Combinations: 2598960
Winning Combo: 4
Probability: 0.0000015
Odds: 0.0000015 OR 0.0000015:0.9999985
Adjusted Odds: 1:649739

Dr. Ernst would be proud. :)


New Ruby Site!

There's a new Ruby-Lang site, and it looks oh so delicious! The old one was terrible looking and a pain to show people who you were introducing the language in. The new design makes me want to find more converts! I really love the little Ruby code breakout towards the top. Very nice.