Monday, February 21, 2011

College = High School (except with money)

I think with every passing day I begin to hate college more...I guess it is college directly that is to blame for my hatred, but all the things you have to endure to get through college, which mostly includes working a part-time job to pay for in the first place and driving/travelling roughly 3hrs every day to get to and from college/university. College is basically like my high school experience except for it costs money. If it didn't I wouldn't have to work and could probably just live on campus. If this were the case, then maybe it wouldn't be so bad. I wouldn't have to constantly recheck my schedule to make sure I meet the numerous deadlines.

I used to think that I wanted to get a PhD or something, but that seems to be rapidly changing. Every day I wonder why I am doing this. I know that I love computers, learning and want to start my own trivia some day (emphasis on "some day", seeing as I have still not made much progress...). I also know that in order to make a decent living you need a bachelor's degree in something. I don't think I have ever given up on something that is major as this and I don't plan on doing so. However, now it has come down to one simple question How do I get this over as quickly as possible so that I can start making some money and get some real job experience? Maybe when I can afford graduate school I will go back (especially if my employer will pay me to do it)? I am just too exhausted. I just want to be able to go home and not worry about anything but getting to work on time. If I can afford a nice computer and lots of delicious food, then I think I will be content. Anyhow, I really should stop ranting and do my homework before I fail discrete math and algorithms and data structures!

Monday, February 14, 2011

Java- So evil, yet so sublime...?

So, I have a ton of homework to do, as usual. I am doing fine in writing and calculus, but am practically failing my Data Structures and Algorithms Java class and have like a 'C' in Discrete Math. Anyhow, instead of doing that homework, yet again as usual, I spent my time programming useless things for my own personal uses and reasons. My latest? A Java GUI that will close your music player for you after a specified amount of time (in minutes). I was just so proud of it that I thought I would post the source code (works with Rhythmbox in Ubuntu, but easily alterable to any OS):


package rhythmBox;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class closeRhythmBox extends JFrame implements ActionListener {

private static final long serialVersionUID = 1L;

private static final int WIDTH = 400;
private static final int HEIGHT = 300;

private JTextField minutesBox;

public static void main(String[] args) {
new closeRhythmBox().setVisible(true);
}

public static void execKill(long minutes) throws InterruptedException {
Thread.sleep(minutes*60*1000);
try{
Runtime.getRuntime().exec("pkill rhythmbox");
System.exit(0);
}
catch (IOException ioe) {
         ioe.printStackTrace();
       }
}
public closeRhythmBox(){
setTitle("Rythmbox Timer");
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container pane = getContentPane();
pane.setLayout(new FlowLayout());

JPanel box = new JPanel();
box.setLayout(new FlowLayout());
JButton startButton = new JButton("Start");
startButton.addActionListener(this);
box.add(startButton);
box.add(new JLabel("Minutes Until Close"));
box.add(minutesBox = new JTextField(20));

pane.add(box);
pack();

}

public void actionPerformed(ActionEvent e) {
String textNum = minutesBox.getText();
long minuteNum = Long.parseLong(textNum);
if (e.getActionCommand().equals("Start")){
try {
execKill(minuteNum);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}

Enhanced by Zemanta

Friday, February 11, 2011

PaRaDoX!? -When Reality Becomes Stranger Than Fiction

RadiolabImage via Wikipedia


Paradox can mean many things, such as in my discrete math class, where it defines a particular logical statement to be impossible. A paradox can also describe something that is counter-intuitive (you would think the opposite of the actuality). Today at work I listened to RadioLab (a cool NPR/WNYC podcast I recently found) titled "Numbers." While it wasn't quite as good as "Lost & Found", it is definitely up there...along with basically every other episode (http://www.radiolab.org/2009/nov/30/).
BenfordsLawThey were talking about something called Benford's law. Basically, if you find anything numerical, then the first number is most likely to be 1 (30% chance, aprox.- according to the chart above...calculated by averaging first digit from many sources). It was amazing to see how this serendipitous discovery led to so many applications, going as far as use as evidence in criminal court cases. Investigators can look at someone's bank account balance and if it doesn't follow Benford's law, then they may be committing fraud. It seems so, what's the word...oh, ya..."counter-intuitive"? Nevertheless, it seems to hold true (listen to podcast to learn more).



Monty Hall paradox illustrationImage via Wikipedia
This got me thinking about another paradox I ran into a while back called the Monty Hall Paradox. For just a second, imagine you are on a gameshow and the host shows you 3 different doors. Behind one door is a goat, another has a Porsche an the other contains nothing. The host then asks you to pick a door (in hopes of getting the Porsche, of course), so you randomly pick a door, say #3. The host then tells you that there definitely nothing behind #2 and proves it to you by opening it. Lastly, he asks you if you would like to switch or open the other door. Which should you do? Does it even make a difference? Answer...?

You should always switch because when you originally picked the 1st door you only had a 33% chance of picking the Porsche and now between the two doors that are left, there is a 50% chance. I found this interesting, but didn't quite understand (and you are probably still scratching your head too I suppose? ^_^). This is why I decided to put my Java programming skills to use to write a program to test this out. When writing I realized there were several possibilities (going under assumption that you always switch):
1) I originally picked the ONE door with the Porsche  and when I switch I will get crap.
2) I picked one of the other TWO booby prize doors and when I switch I will get the Porsche.
Ok, point proven...but if you are still unsatisfied you can try it yourself or run my java source code:


import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

/**
 *
 * @author JT Newsome
 * Demonstrates the Monty Hall Paradox and theory of probability.
 *
 */
public class MontyHallTester {
public static int forMonty = 0;
public static int againstMonty = 0;
public static int min = 0;
public static int max = 2;
public static int timesToLoop = 1000000;

public static void main(String[] args) {
for(int i = 0; i < timesToLoop; i++){
montyTest();
}
System.out.println("forMonty: "+forMonty);
System.out.println("againstMonty: "+againstMonty);
System.out.println("Ratio: "+ (forMonty/againstMonty));
}

public static void montyTest(){
ArrayList boxes = new ArrayList();
boxes.add(0);
boxes.add(1);
boxes.add(2);
Collections.shuffle(boxes);
Random rand = new Random();
int randomNum1 = rand.nextInt(max - min + 1) + min;
if (boxes.get(randomNum1) == 2){
againstMonty++;
}
else forMonty++;
}

}


Ok, well that was fun! Happy days until we meet again!
Enhanced by Zemanta