Monday, November 12, 2007

Science Experiments

I was poking around last night on the computer and found some old Bill Nye and Mr. Wizard videos. We homeschool, so today I worked with the two older kids on magnets. We messed with a little magnet kit, made a compass with a needle and glass of water, and took apart an old harddrive which has a couple heavy magnets in it that controls the mechanical arm that moves across the platters. So my point about Nye and Mr. Wizard is that I found an old clip from Wizard's show that gave a puzzle to cut up a piece of paper with a hole big enough to walk through. They seemed to enjoy that. Back to work tomorrow after a nice 4 day weekend.

Sunday, November 11, 2007

Coding Primes and E

So I've been messing with some javascript code I found to try and calculate a few different things for fun. I turned the code into C and attempted to calculate prime numbers. It is basically a loop that counts up from 1 to whatever you want and finds all the primes between.

The second program was to try and calculate 10 digit primes off e. This didn't work so well. I found that even your long datatypes have limits. There are some libraries out there that let you use bigger numbers (bmp) but I didn't feel like messing with that.

The last program was to calculate e as far as I could take it. First I tried a method I found off the web. Using the formula (1-1/n)^n I tried to write a program to use this and do as far as n was set to a variable. C didn't like using fractions and floats for me. I then changed to another method I read about which was calculating up to a certain set of digits. Using a method like so:
1+1+1/2!+1/3!...1/n!
Where n is a variable set on how deep to calculate it. Setting n lets you calculate e to n-3. As an fyi for review, 1/3! means 1/(1*2*3). So the code has a nested loop to it that helps with calculating this. I'll try and post the code in the comments for any interested.

Ok...trying to post it here since comments get angry with what it thinks is html code.

PRIMES.C

#include stdio.h

int main(){

unsigned long int maxNumber = 999;
int primeFlag = 1;
unsigned long int maxTest;
unsigned long int Test;
unsigned long int i;

for ( i = 100; i <= maxNumber; i++ ){
primeFlag = 1;

maxTest = i / 2;

if ( (i != 2) && (( i % 2 ) == 0 ) ){
primeFlag = 0;
}
Test = 3;
while ( ( Test <= maxTest) && ( primeFlag == 1 ) ) {
if (( i % Test ) == 0 ){
primeFlag = 0;
}
Test = Test + 2;
}
if ( primeFlag == 1 ){
printf ( "%ld, ", i );
}
}
printf ("\n");
}

CALC_E.CPP

#include iostream
#include iomanip

using namespace std;

int main(){

int howdeep = 18;
int i, j;
double frac, denom, my_e;
//double e = (1+1/howdeep)^howdeep; //doesn't work - can't put exponent on it

//cout << "E: " << setiosflags(ios::fixed) << setprecision(5) << e << endl;

for ( i = 2; i <= howdeep; i++ ){
denom = 1;
for ( j = 1; j <= i; j++ ){
denom = j * denom;
//cout << "denom: " << denom << endl;
}
frac = 1 / denom;
my_e = frac + my_e;
}

my_e += 2;

cout << "E: " << setprecision(15) << my_e << endl;
return 0;
}

Saturday, July 7, 2007

Bumpa

I wanted to start documenting some of the things my grandfather has said that were funny, thought provoking, etc. He's just passed away and I thought it appropriate to put these down before they start to slip my memory (as I'm sure numerous stories and sayings already have).

Bumpa-isms
It only bothers you if you let it.
Only boring people are bored.
You didn't eat all your beans? I ate all mine...want me to prove it?


He would visit his sisters who's book shelf had perfectly aligned books. He'd push one in just and not tell her just to bug her.

He told a story about a woman who ordered some fresh cut meat at a store and was in a bad mood. As she left the cashier said have a nice day, and she replied "Don't tell me what to do!"

Diddly say kiddly's?

Throw it under
He asked mom prop a stick under his motor home bed while he was holding up one end. He said throw is under, and she threw the stick under the bed...they laughed for quite awhile about that.

Spliv parking
This is what he called handicap parking.

He'd constantly mess with toll takers on drives through to Florida. Mumbling 'they aren't very friendly are they?' and things of that nature while giving them money and getting change.

He, his father, and uncle, all went to Harvard. He had a masters business degree. He'd alway say "you can tell a Harvard man, but you can't tell him much."

An interview while fresh out of college was for a sales job. While interviewing the owner walked in and while holding his suspenders asked a few questions. Bumpa didn't know he was the owner, but the owner thought he'd be best for marketing. He doesn't want to be in marketing. The owner wants the man interviewing to call downtown and setup an interview with the marketing director. The interviewer does, and the owner walks out. Bumpa turns to the man and says well this is a fine mess you've gotten me into. What am I going to do now? The man hands him a book the marketing director wrote. He says, here, read this and say it back to the marketer...he'll eat it up. So Bumpa does read it while on the midnight train and spews it all back to the marketing director. He gets the job.

He introduced me to frozen peas and cayenne pepper.

Preferred two ply.

When driving the motor home he would enlist the passenger to his right to say 'yes yes yes yes' or 'no no no no' to tell him when the traffic to the right was clear when turning left.

He didn't like the blinking colon between the hour and minutes on his indash motorhome digital clock, so he put a piece of black electrical tape over it.

He'd like to teach about not being able to speak with someone when concentrating on driving. He'd explain this very throughly so as to make sure you didn't misunderstand why he wasn't able to look at you while driving.

Was a sailor in World War II, a navigator no less. Later in life, trying to teach a kid about how to find the N. Star, and ended up pointing at the wrong one.

In numerous drives to Florida with his motor home he had all kinds of stories to tell. One I remember is: Bumpa will leave on time as necessary. He'd bring people down to FL, sometimes some high schooler that was working for him. So one time it was time to leave. The kid that said he was coming wasn't there, so Bumpa started down the road. The mom caught up on the highway with the kid and flagged him down to pull over. He did, and the kid ended up making the trip after all.