May 31, 2007

i'm learning java..

Everyone who reads this for my fitness or ramblings or whatever, please indulge me for a second while I do this..

any java programmers out there?

The assignment, from Thinking in Java by Bruce Eckel:
A vampire number has an even number of digits and is formed by multiplying a pair of numbers containing half the number of digits as the results. The digits are taken from the original number in any order. Pairs of trailing zeros are not allowed. Examples include:
1260=21*60
1827=21*87
2187=27*81
Write a program that finds all the 4-digit vampire numbers."


so I wrote this from scratch. It works, and produces the correct result, but I'm sure there is a more elegant way of doing it- especially with getArrayOfDigits(). I don't know if there are any java developers who read my blog, but if there are, a little criticism would be appreciated.

import static net.mindview.util.Print.*;
// the print() method is identical to System.out.println().

public class Exercise10 {

public static void main(String[] args) {

for (int i=1000; i<10000;i++ )
{
if(i%100==0) continue; //weed out the numbers with two trailing zeros
int[] result = isVampire(i);
if(result != null) {
print(result[0] + "*" + result[1] + "=" + i + ". It's a vampire number");
}
}
}


private static int[] getArrayOfDigits(int i) {
//I am sure this can be done better
int[] a = {0,0,0,0};

a[0] = ((int)i/1000);
i=i-a[0]*1000;
a[1] = ((int)i/100);
i=i-a[1]*100;
a[2] = ((int)i/10);
a[3]=i-a[2]*10;

return a;

}


private static int[] isVampire(int i) {

int[] arr = getArrayOfDigits(i);

for(int a=0; a<=3;a++) {

for (int b=0;b<=3 ;b++ ) {
if(a==b) continue;

for (int c=0;c<=3 ;c++ ) {
if(a==c) continue;
if(b==c) continue;

for (int d=0;d<=3 ;d++ ) {
if(a==d) continue;
if(b==d) continue;
if(c==d) continue; //this series of continues can probably be done better, too.

if(GetTestNumber(arr[a],arr[b]) * GetTestNumber(arr[c],arr[d]) == i) {
int[] done={GetTestNumber(arr[a],arr[b]), GetTestNumber(arr[c],arr[d])};
return done;
}
}
}
}
}

return null;

}


private static int GetTestNumber(int a, int b) {
return ((a*10)+b);
}

}


thanks..
-steve

May 29, 2007

big, dumb bicycle moron coming to a street near you!

on may 25th:

spent 30 minutes repairing a flat today that i got for riding too far over the shoulder of the road. who knew that i was supposed to ride in the traffic lane?



actually, i spent 10 minutes repairing the flat (caused by a staple, which i saved), and 20 minutes trying to re-inflate the tire. i couldn't seem to get a good seal on the valve - which had a presta to schrader adapter on it, because the tubes i bought had stems that were too short..



when i finally got the thing inflated, i couldn't remove the pump from the valve. imagine my frustration when i watched 20 minutes of effort hiss out of the tire as i pulled on the valve like a wild crazy mad man. yet my screams of frustration were only drowned out by the 55mph traffic headed north out of the city for memorial day weekend.



so i did what any self-respecting man in my situation would do. i called my wife. to come get me and the bike. in the minivan.



in the 15 minute interim, i did mange to get the pump off the valve. actually, i managed to snap the valve off the stem (oops), ruining the tube, before getting the pump off the valve with a gentle tap on the guardrail. figures.



i have one more spare tube with the short stem, but i think that's going straight into the garbage. I put a long-stem tube on the wheel when i got home. Now all i have to do is inflate it. yay.



when it comes to bicycles, there's something about me and mental retardation.


Then, yesterday:

so..



i figured out the clipless pedal thing fine. read enough online accounts to know that i should practice snapping out of them while moving. it wasn't exactly brain surgery, and i managed to not fall down the first time. and for a whole week, i was golden and really getting the hang of it.



then, not one hour ago, i was riding north on franlkin turnpike about 3 miles from home when i came to a traffic light. i clipped out of my right pedal, no problem. then, to my horror, as soon as i stopped, my center of gravity was apparently to the left of the bike. i was still clipped in on the left side. 5 cars in line at the light saw the whole thing.



awesome.


oh, and by the way, i've signed up for a 100-mile bike ride THIS SATURDAY. i've never ridden a bike more than 25 miles in my life, and that was two years ago. one week ago, my bike was still locked up in the basement, tires flat because it hasn't been moved in almost two years.



at least the 100-mile tour is flat and scenic - from babylon to montauk. the weather is supposed to be nice, too.

May 23, 2007

errata..

popular science bit directered me to http://www.decluttered.com/, which was my inspiration for spending four hours on monday doing this:


(note the hinged bottom - i can swing the whole thing down and access the back!)


back on the diet, 1000 calories or so per day. as of this morning i'm already just 3 lbs away from where i was 4 weeks ago (when i left for california and experienced excessive gluttony.)


other stuff:
lenny dykstra washed my father's car


and he changed the oil, too


It's pretty surreal when the LA Times does features on a guy you used to hang out with.
http://www.latimes.com/features/magazine/west/la-tm-flash19may13,0,4021008.story

A Pat Cooper promotional video:
http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=2030779097

supporting photos for my claim to the TSA about the missing iPod.
http://tursi.com/ipod

gnarly-looking thunderstorm, taken from 36,000 feet:


that was a big train set:


my brother works at starbucks. so does my sister. my son does not.


the mountain that almost killed me.. i had my first beer in 2007 when i got down. the report is halfway done.


that's all for today.