Saturday, August 17, 2013

When jQuery met Wikipedia for a game of Scrabble

I needed to obtain a JSON object containing the tile values on scrabble tiles for a project I took on. This was across 8 dictionaries (6 languages). The problem was, I couldn't  find a good source for the required data. I have since found a far easier way to obtain the data but it was still a fun challenge.

The best I could do at the time was http://en.wikipedia.org/wiki/Scrabble_letter_distributions.

The data was laid out as displayed below and it didn't look very friendly.

English

English-language editions of Scrabble contain 100 letter tiles, in the following distribution:
  • 2 blank tiles (scoring 0 points)
  • 1 point: E ×12, A ×9, I ×9, O ×8, N ×6, R ×6, T ×6, L ×4, S ×4, U ×4
  • 2 points: D ×4, G ×3
  • 3 points: B ×2, C ×2, M ×2, P ×2
  • 4 points: F ×2, H ×2, V ×2, W ×2, Y ×2
  • 5 points: K ×1
  • 8 points: J ×1, X ×1
  • 10 points: Q ×1, Z ×1

With a little inspection, I was able to identify the formatting applied to the required elements.

Enter Google Chrome plus the jsshell extension. Jsshell allows you to run jQuery on any page. Now isn't that somethin' :-).

So after a few (debatable) minutes I came up with the following



In other words

  1. For each of the six languages specified, find the span with an id  equal to the language.
  2. Find the first list following the parent of the identified span
  3. For each bold letter in the list, assign the integer value of the italicized text which is a sibling of that letter to that letters index in that languages array.
    • Example, for the English dictionary, Q and Z (bold) are 10 points (italicized). The integer value of  "10 points" is of course 10.


The result,

Lines of code : 10

Friday, August 16, 2013

I love pi, I do. All infinity digits, no wait...infinity and 1

I needed to get this party started, so why not do it with a little pi loving.

I'm not a die-hard pi-thusiast. I'm just a nerd who thinks that I'm the one (who knocks?) who ended up with this irrational love for a sequence of digits. Maybe it is the fact that it is the ratio of a circle's circumference to its diameter. I don't love circles. I don't dislike them, but they're just not that special. However, I think of time as a circle, I haven't studied time but that is just what I think. History tends to repeat itself,  recurring themes and so on..... but this post is about pi.

So here's my pistory
  • I memorized the digits of pi from my calculator in high school. I think at the time this was 3.141592654 rounded.
  • During an electronics lecture at the University of the West Indies, the lecturer asked the class to state the digits of pi. Oooooh, my time to shiiiiiiiineeee! Some stopped after 2 digits, some after four and Sir Dale (I've been knighted) of course went valiantly through his 10 digits :3
    Not bad, Mr. Ross
  • Of course, this drew attention, and the lecturer asked me to repeat, I think. He then went on to recite about 30 or so digits.
    Are you kidding me, seriously?!
  • I made a deal with the lecturer to receive imaginary marks if I could get to 100 digits by the end of the course.
  • On my final exam I included the following (I could only remember 93 while doing the post but it might be due to code-induced-insomnia). I Google™d (3.5-1.5 on the Bing test) the other 8 digits, sue me! No, please don't!
    3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798
  • That's 101 digits, because stopping at 100 would have required rounding and that's not cool, man. I got my imaginary marks but they only reported the real component, claiming it was too complex! The nerve!
    Awwww Yeahhhhhh!

  • Did you notice the pi in the Dajen Group logo? Of course you did!
So there you have it, my first post in the code room. 
Lines of code : 0