The White Blog

A blog for technology, life, and food

  • Home
  • Photos
  • About
  • General
  • Life & Family
  • Programming
  • Gadgets & Toys
  • Food
  • Pictures

    • The White Pets
    • Western Carribean
    • Eastern Carribean
    • St. Louis
  • Other Pages

    • Side Projects
    • GeoCaching
    • Andrew's Wishlist
    • Christina's Wishlist
  • Across the Web

    View Andrew White's profile on LinkedIn profile for Andrew White on Stack Exchange, a network of free, community-driven Q&A sites
  • Gallery

              DSC00157 DSC00389
  • Recent Posts

    • Truthfulness of the 2012 Presidential Political Candidates
    • Slider Solver for Klotski Puzzles
    • Pet Pictures
    • LEGO iPad Stand
    • Unexpected empty JList model with IntelliJ’s GUI builder (Solved)
  • Older Posts

    • March 2012 (2)
    • February 2012 (1)
    • January 2012 (2)
    • March 2011 (2)
    • November 2010 (2)
    • September 2010 (2)
    • July 2010 (1)
    • June 2010 (3)
    • May 2010 (5)
    • April 2010 (4)
    • March 2010 (6)
    • February 2010 (1)
    • January 2010 (1)
    • December 2009 (1)
    • November 2009 (1)
    • September 2009 (1)
    • August 2009 (1)
    • July 2009 (2)
    • May 2009 (2)
    • March 2009 (2)
    • February 2009 (1)
    • January 2009 (1)
    • November 2008 (1)
    • October 2008 (1)
    • September 2008 (2)
    • August 2008 (1)
    • July 2008 (1)
    • June 2008 (2)
    • April 2008 (2)
    • February 2008 (2)
    • January 2008 (1)
    • December 2007 (3)
    • November 2007 (2)
    • October 2007 (2)
    • September 2007 (1)
    • August 2007 (6)
    • July 2007 (8)
    • June 2007 (7)
  • Site Tools

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Switch site

    • Switch to our mobile site

Truthfulness of the 2012 Presidential Political Candidates

I recently became interested in certain claims made by politicians and their perception among the public. In particular, I want to know how trustworthy a candidate is. Furthermore, I want to be able to back up or refute claims made by people about one candidate being more “honest” or “trustworthy”.

Methods and Bias

My methods are simple. I compiled statistics based on each candidate from PolitiFact and graphed the results below while also calculating a Trustworthiness Grade Point Average (TGPA). The pie chart is a simple breakdown of each category that Politfact assigned to a particular statement. The TGPA is a simple weighted average of each statement on a standard academic 4.0 scale system where “true” was assigned a value of 4.0 and “Pants On Fire” got a 0.0 and all other values where equally distributed in the range [0.0-4.0].

There is also the chance of bias from PolitiFact. For that I refer you to the PolitiFact Bias Blog where you can form your own opinion. This data also represents a rather small sample size, in particular for Ron Paul who does not receive nearly as much press coverage as other candidates. It should also be noted that PolitiFact does not rate every statement but rather statements that can be fact checked and that have some “boldness” or public interest. Therefore, I wouldn’t use this as a measurement of their personal character but rather how well they present themselves relative to known or verifiable facts in a political landscape.

Ron Paul TPGA 2.33 (C+)

Mitt Romney TPGA 2.21 (C+)

Rick Santorum TPGA 1.89 (C-)

Newt Gingrich TPGA 1.73 (C-)

Barack Obama TPGA 2.58 (B-)

Conclusions

Being a Ron Paul supporter, I was not too surprised to see he ranked among the top of the field. Newt’s record was anticipated, but I did expect Romney and Satorum to be reversed. Obama’s record was not what I predicted until I realized that he doesn’t make bold claims of fact as much as bold promises. In particular, Obama seems very good at avoiding outlandish remarks that would earn him a “Pants On Fire” ruling. Overall I was disappointed that the best republican rating was a C+ and best overall was a B-.

Mar 31, 2012aewhiteCategory: General Read more No Comments

Slider Solver for Klotski Puzzles

I hate slider puzzles aka Klotski puzzles. The key move is usually a subtle block placement nested halfway between the starting setup and the ending solution. Since even the more basic puzzles require a minimum of 20+ moves to solve, I end up using trial and error which inevitably results in me repeating positions several times before frustration sets in.

Solving one puzzle is nice, but if I can solve every puzzle then I feel like I have truly conquered the problem. As such, I wrote a small Java command line application that can solve most compact sliders quickly.  It uses a breadth first searching algorithm to find the shortest solution assuming moving one block one space counts as a move.

Using the solver

Warning, this is more of a developer/geek friendly application. Download and unzip either the .zip or .tar.gz files from below. The program is meant to be run from the command line so jump to the console. Change directories to where you extracted the download and then you can run…

$bin/SliderSolver /path/to/puzzle /path/to/goal

See the download section for example puzzles, goals, and outputs. When creating the puzzle and goal files note that the only reserved character is the ‘#’ which is the wall symbol. There is very little error checking so be sure the puzzle is enclosed and “small”. At some point I might wrap this in a GUI but for now it is just a self exercise in solving a puzzle.

How it works

The algorithm is pretty straight forward:

  1. Read puzzle and goal files
  2. Generate shape equivalence mappings
  3. Try possible moves and store the current puzzle state if we have not seen the state before
  4. If the state matches the goal then print the solution else go to step 3

The only complex part is generating shape equivalence. In practice, this optimization reduces the memory needed and time required by a factor equal to the number of duplicate shapes in the puzzle. Without this trick the original Klostki puzzle will consume over 4GB of RAM and take several hours to solve. With the optimization, the puzzle can be solved in under a minute with under 2GB of RAM.

Below is a snip of the core solve method which uses a breadth first algorithm to find solutions.

public Solution solve() {
    Queue<StateNode> nextStates = new ArrayDeque<StateNode>();
    Set<String>      seenStates = new HashSet<String>();
 
    nextStates.offer(new StateNode(new Puzzle(this.sourcePuzzle), ROOT_MOVE, NO_PARENT));
 
    while (!nextStates.isEmpty()) {
	final StateNode currentState = nextStates.poll();
	final String puzzleString = this.generateEquivalentPuzzleString(currentState.puzzle);
 
	if (seenStates.contains(puzzleString)) {
	    continue;
	}
 
	if (this.targetGoal.matches(currentState.puzzle)) {
	    return this.buildSolution(currentState);
	}
 
	seenStates.add(puzzleString);
	this.offerNextStates(nextStates, currentState);
    }
 
    return null;
}

Summary

This isn’t the most user friendly app but I never really intended to release it anyway. It could probably be future optimized by adding an AI that could do path trimming or algorithm selection based on certain puzzle metrics. Error handling and usability could certainly be improved on. I found the exercise to be a good refresher on performance aware Java application development and a good reminder that my algorithms class in college does still hold some use for me.

Downloads

Slider Solver Source Code
Slider Solver Source Code
SliderSolver-Project.zip

Date:March 3, 2012
28.8 KiB
27 Downloads
Details...

Slider Solver (zip)
Slider Solver (zip)
SliderSolver.zip

Windows friendly version.

Date:March 3, 2012
1.1 MiB
21 Downloads
Details...

Slider Solver (tar.gz)
Slider Solver (tar.gz)
SliderSolver.tar.gz

Linux/Mac friendly version

Date:March 3, 2012
1.1 MiB
11 Downloads
Details...

Klotski Puzzle
Klotski Puzzle
klotski-puzzle.txt

Date:March 3, 2012
56.0 B
43 Downloads
Details...

Klotski Goal
Klotski Goal
klotski-goal.txt

Date:March 3, 2012
56.0 B
38 Downloads
Details...

Klotski Solution
Klotski Solution
klotski-solution.txt

Date:March 3, 2012
1.7 KiB
47 Downloads
Details...

Mar 2, 2012aewhiteCategory: General, Programming Read more Comments (1)

Pet Pictures

I was recently reminded that I have not updated my pictures in a while and, in particular, my pet album was missing a few. So, for the friends and family readers, I give you Green, Yellow, and Orange the hermit crabs and some Faye pup pictures. Our other hermit crab, Red, is probably molting right now so we didn’t dig him up for a photo shoot.

img_0042 img_0030 img_0023 img_0015_1

Feb 26, 2012aewhiteCategory: General, Life & Family Read more No Comments

LEGO iPad Stand

I’ve always loved LEGOs and this year for Christmas I got The LEGO Ideas Book. It has an entire chapter dedicated to practical applications of LEGOs such as card and pen holders. I also got this handy portable Bluetooth keyboard but our iPad’s case lacks the stand that some have. So, until we get one, I decided to build one and here are the results…

From a structural standpoint, the stand is fairly sturdy. It is mostly made from parts of an old LEGO fort from the Pirate series. This  project was particularly interesting due to the engineering challenge of supporting and balancing the iPad’s weight while not shearing the bricks from their bases.

Jan 10, 2012aewhiteCategory: General Read more No Comments

Unexpected empty JList model with IntelliJ’s GUI builder (Solved)

When working with IntelliJ’s GUI builder it is possible for custom implantations of  JList to mysteriously be empty when using a custom model that was defined and set in the constructor. This can be very confusion and non trivial to track down. This can be caused by accidentally setting the model property in the GUI Builder. The solution is to right click and select “Restore Default Value.”

This appears to be an issue because IntelliJ’s GUI builder uses instrumentation to inject the component properties at runtime. Furthermore, this occurs after the constructor of the components are finished. So, in a custom JList implementation, great care must be taken not to override any properties in the GUI builder that are going to be defined in code.

Jan 9, 2012aewhiteCategory: General, Programming Read more No Comments

Disable System Beeps for Non-KDE Applications (Eclipse) While Running KDE

If you have tried everything to get those annoying system beeps in KDE to stop but can’t, here is something to try.

  1. Launch gnome-control-center
    1. Can be done by typing “gnome-control-center” in a console while in KDE
    2. Log in to a Gnome session and launch the Control Center
  2. Find the “Sound” item
  3. Click the “Mute” checkbox next to “Alert Volume”

I noticed this issue when I was running Ubuntu and I updated to Kubuntu and I was running some non-KDE apps such as Eclipse. I had tried everything else from setting the system bell to mute to setting the “Beep Channel” to 0%/Mute and updating various settings in the System Notifications configuration. Finally I concluding that certain applications must still be pulling configurations from Gnome.

Mar 26, 2011aewhiteCategory: General, Programming Read more Comments (2)

How to Get the Most for Your Carnival Fun Points

This article outlines some easy to follow steps for participants in the Carnival Fun Points Mastercard program. The steps below work at the time of writing but may not after they change the point system on May 1st 2011, but may continue to work even then.

A little background

There is a little known secret about the Carnival Fun Points system that could save you hundreds of dollars on your next cruise. If you have ever played around with the Fun Points calculator you might have noticed some odd conversion ratios. First, let’s price out a cruise for $1250…

Ok, so we need 113,636 points to pay for that Cruise, fair enough. I wonder how much a $1251 cruise is worth in Fun Points…

What!? If I spend just $1 more I can cruise for free with just 74,910 points? Yes, and there is more to the story, but if you just want to see where the savings come in skip down to the “What does this mean for me?” section. So, you’re pricing a cruise, it sure would be nice to know where these boundaries are. After some basic analysis we can see that there are several of boundaries that are important to know.

Cost Range Points Needed Points Range
$50-$200 100 x Cost 5,000 – 20,000
$201-$800 ~95.23 x Cost 19,143 – 76,190
$801-$1250 ~90.91 x Cost 72,818 – 113,636
>$1251 ~59.88 x Cost 74,910

An astute reader will note that the same points buy you different amounts. For example if you have 73,000 points, which range do you fall in? The $801-$1250 range or the >$1251 range? Sadly it’s not documented on the site because they base their redemptions on the transaction amount NOT how many points you have.  However, as you can see, spending more than $1251 gets you a huge increase of points to cash conversion. There are still two more caveats to this system however.

  1. The table above is only for a redemption of a transaction in full!
  2. If you cannot redeem your transaction in full with your points it defaults to using the $50-$200 conversion rate.

Now I’m going to show you how to save big money using a few easy rules.

What does this mean for me?

There are two main parts of this process. First, figure out how much your points are really worth. Second, make sure you only pay for a very exact amount of your cruise at a time.

Step 1 – Figure out how much your points are worth

Use the following simple algorithm to determine what you can get with your points…

  • If you have more than 74,910 points then divide your points by 59.88
  • If you have between 72,818 and 74,909 points then divide your points by 90.91
  • If you have between 19,143 and 72,817 points then divide your points by 95.23
  • Else you don’t have enough points for this method to work

Step 2 – Pay only what your points will redeem in full now

This is the most important part. The credit card company only uses transaction amounts NOT the price of the cruise to calculate point redemption rates. So, if you calculated that your points are worth $1300 but your cruise will cost $2000, call your travel agent and only pay $1300 right now. As soon as the transaction posts, you can redeem your points in full and pay the remaining $700 later.

How much can I really save?

Let’s say you have a cruise booked for $1925 and you have 75,000 points. If you pay for the cruise in full and tried to redeem your 75,000 points you would get $750 off, not bad. Now, using the system above you would divide 75,000 by 59.88 and get $1252. Call the travel agent and pay for $1252 of the cruise, and redeem your points in full. You just saved $1252 or $500 more than what they would have given you in the first place.

Is this legal? How did you find out about this?

It’s legal but they can probably close this loophole at any time so I’m trying to let as many people as possible know about it. I found out about it when I didn’t get the points I expected. After several attempts to get customer service to provide me with a document that outlined their formulas or method I was simply told that no such document existed. Finally, I did find out that the redemption amount is based on transactions and not the price of the cruise. The conversation went something like this…

Me: “So, if I call up my travel agent and tell them to only post amount X you’ll give me an addition $Y back? Just by splitting the transaction”

Rep: “Yes, it’s only based on the transaction amount”

Conclusion

First, if at all possible spend more than $1251 and have at least 74,910 points. The savings are huge when compared to the lower values. Second, pay what your points are worth. Since you have 180 days to redeem your points for any given transaction you may be able to milk more savings out the system, but just be careful not to lock yourself into something you can’t buy your way out of. Finally, spread the word. I’m sure this loophole will get closed at some point but you might as well save an extra $500 on your next cruise at the expense of the credit card company.

Mar 16, 2011aewhiteCategory: General Read more Comments (1)

Hexaddicus – Great Android Puzzle Game

Sharper Minds Technologies has release their first Android game, Hexaddicus. Hexaddicus is a mixture of mental math, memory, and puzzle solving. The game feature two modes of play, a timed mode and a puzzle mode.

In a timed game players try to connect numbers together that add up to a target that changes after each turn. As the player gets better the target get harder. In the lite version, there is a short and long variation of the time mode, whereas the full version features four modes.

Hexaddicus also features a puzzle mode where players must use every number on the board. This mode has elements similar to Sudoku and a word searches. There are five levels of difficulty ranging from very easy, which should take less than a couple minutes, to very hard, which could take an hour or more.

Nov 14, 2010aewhiteCategory: General Read more No Comments

Writing Beautiful Code – Nested If-Then Statements Are Evil

It’s amazing at how developers can abuse the most basic construct in almost any language, the if-then-else clause. First, let’s examine a pretty common block of language independent code.

Complex example

0 simple-method (args...)
1     if cond then
2         some code here
3         if cond then
4             more code here
5             if cond then
6                 deeply nested code
7         else 
8            more deeply nested code
9    return code

Harmless and easy to read, right? The answer is mostly dependent on the code inside the if-then-else clauses, but, even with that aspect aside, this code can be much simpler. For a human to understand a function they must understand all paths that lead to all exits. So, for this function there is only one exit on line 9 but 4 ways to get there. As an exercise try to find all of paths to line 9.

Simplified example

0 simple-method (args...)
1     if cond is false then return code  # 1 way to get here
2     some code here
3     if cond then
4         more code here
5         if cond then
6             nested code
7        return code                     # 2 was to get here           
8    not so deeply nested code
9    return code                         # 1 way to get here
This new code has three exists but never more than two ways to get to any one of them. In many cases the reader can mentally break the flow down easily in the above code because of the short-circuit logic on on lines 1 and 7. So, by this logic we can create a nice rule-of-thumb which is to…
Return from a method as soon as you can.

There are other nice perks to this way of thinking which include…

  1. Tighter variable scopes
  2. Less horizontal indentions which means easier to scan
  3. Fewer bugs in future edits by reducing the chance of corrupting a critical path

In summary, exit as soon as possible using negative conditions if needed. If highly nested logic is in fact needed considering moving the inner blocks to a new function for readability and to keep the variable scope as small as possible.

Nov 4, 2010aewhiteCategory: General, Programming Read more Comments (1)

Writing Beautiful Code – The Vertical Alignment Coding Style

Writing readable code is an art. There are always exceptions to every “rule” and many religious flame wars have become of this nonsense. Below I outline my thoughts on vertical alignment in key cases that will have the best impact. As a disclaimer, you will probably have to rethink the tabs vs spaces debate after reading this.

Line up data-types, variable names, and assignment operators

Let’s look at an example of the most common style first. This snip declares all of the variables that will be needed in the method body. Try to read it and remember the variable names and their types.

    private long getGameTime() {
        final String mode = GameSettings.getGameMode(this);
        final Resources r = this.getResources();
        final String[] vals = r.getStringArray(R.array.mode_values);
        final long[] map  = { (2*60+30)*1000, 5*60*1000, 10*60*1000, 15*60*1000 };
        /* do stuff */
    }

Now take a look at the “column” formatted snip below. It’s the same code but with some extra whitespace added to line things up.

    private long getGameTime() {
        final String    mode = GameSettings.getGameMode(this);
        final Resources r    = this.getResources();
        final String[]  vals = r.getStringArray(R.array.mode_values);
        final long[]    map  = { (2*60+30)*1000, 5*60*1000, 10*60*1000, 15*60*1000 };
        /* do stuff */
    }

Some might argue this is tiny, no big deal, formatting overkill. There are a few points that I think make this a “big deal”.

  • The variable names can be easily found
  • Dependencies are easier to see
  • Data-types are grouped and can be linked to variables quickly

Given that variable names are probably the most important part of actually reading the code it seems fair to assert that they should be easy to find! The other two points are not as strong as the first but still hold merit. All of these points become more true where the data-types and variable names have a high degree of variance in the same grouping, which is often the case in OOP languages like Java/C++/C#.

Line up chained ternary arguments

Some people like to argue that ternary assignment is hard to read. I might accept that argument if I could see an alternative that didn’t involve a huge block of if-then-else statements. However, the below code is both concise and easy to ready.

            final int turn     = (diff == 1 || diff == 5) ? 1
                               : (diff == 2 || diff == 4) ? 2 
                               : (diff == 3)              ? 3
                               : -1;

Line function arguments, but only when it matters

A function should usually take less than five arguments in which case it is usually ok to just call the function in a one-liner. However, sometime you need to comment on the argument list and draw attention to passed in variables.

hrService.addPersion( first_name, last_name, /* silly order of names */
                      crypt.encrypt(ssn),    /* SSN must be encrypted */
                      dob);                  /* DOB must be in YYYY-MM-DD format */

This is probably comment overkill (future post) and SSN should probably be encrypted before the function call but the point is still there. This style becomes more important if mutable variables are passed in since it is important to keep track any changes to them.

Summary

You can probably see where tabs could get troublesome unless everyone that will ever read your code agrees on a fixed tab width. This is also really hard for automated code formatters to get correct since there is a degree of subjectivity to it. However, I do find that this makes code more readable and at the very least better organized and more professional.

I usually note programmers that take the time to make their code clean since it probably also means they read it more than once. On the other hand, I also note sloppy code even if it’s functionally correct. Sloppy usually means lazy and I don’t want to have to maintine code written by a lazy coder.

Sep 24, 2010aewhiteCategory: General, Programming Read more No Comments

© 2008 The White Blog | Create by: Tatoon | Valid XHTML | CSS