I tried at first to make this waaaay more complicated than it needed to be and least for a 1000 digit number… I have a feeling this question may be repeated later on with a much larger number (string of numbers), which may slow this down quite a lot, but for the 1000, it ran in .0015 seconds.
<?
//Find the greatest product of five consecutive digits in the 1000-digit number.
$num = '7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450';
$time_start = microtime(true);
$num = str_split($num);
$cnt = count($num);
$max = $prod = $i = $start = 0;
while ($i < $cnt) {
$prod = 0;
$end = $start + 5;
for($i=$start;$i $max ) {
$max = $prod;
}
$start++;
}
$time_end = microtime(true);
echo 'time '.($time_end - $time_start)."n";
echo 'answer '.$max."n";
?>
fast/brutish .03 seconds
<?php
//2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
//What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
$time_start = microtime(true);
$max = 20;
$start = 2520;
for($i=$start;$i<2000000000;$i+=$start){
for($j=10;$j
.0004 seconds
<?php
/*You are given the following information, but you may prefer to do some research for yourself.
1 Jan 1900 was a Monday.
Thirty days has September,
April, June and November.
All the rest have thirty-one,
Saving February alone,
Which has twenty-eight, rain or shine.
And on leap years, twenty-nine.
A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
*/
$time_start = microtime(true);
$sundays = $days = 0;
for($y=0;$y<=100;$y++) {
for($m=1;$m 0 && $y % 4 == 0 ) { $daysinmonth = 29; } else { $daysinmonth = 28; }
break;
case 4:
case 6:
case 9:
case 11: $daysinmonth = 30; break;
default: $daysinmonth = 31;
}
$days += $daysinmonth;
if($y > 0 && ($days + 1) % 7 == 0 ) {
$sundays++;
}
}
}
echo 'time '.(microtime(true) - $time_start)."secsn";
echo 'answer '.$sundays." sundaysnn";
?>
Brute/slow – 4.5 Sec
I can’t ever remember the simple format for this…
date nnddhhmmyyyy.ss
month day hour minute year . second
After doing some reading on cnczone and elsewhere I decided to go with the AMT102 encoders from http://www.amtencoder.com/ These guys have come up with a pretty cool little product and I’ve even decided to use them in a quality control device I’m working on at my day job. I had already ordered them and so dug into the servos to figure out if I could even mount the things.
Under the covers I found the BEI encoder that had been mentioned in the cnczone forums. They had to go…
and a few minutes later, I was surprised to see what looked like brushes in the end of the motor. A quick post on cnczone delivered the simple answer, “it’s a tachometer”. Phew.
Turn, turn, Snip, snip and that was taken care of.
Now it was clear that I could easily sandwich a simple plate mount in between the housings. A few minutes later I sent a drawing off to the BEST WATERJET COMPANY IN PHOENIX. Johnny, the owner, is great and quickly turned around the 3 mounts that I needed. Between the clever mounting method that they’ve developed for the encoders and the quality parts from Johnny, it took no time to hook them all up.
Well, after getting her in the shop I was able to finish cleaning and start re-assembling. The upper-portion of the head was just caked with grease.
I’m still a little unsure about this, but to me, the grease was in the wrong spot. I’ve never seen a toothed timing type belt like that run in grease and there isn’t a whole lot else there to lubricate so I went ahead and cleaned that area out. Funny thing is, once I pulled that aluminum plate out, the one that is covered in grease, I found a completely dry back gear. Made no sense, still doesn’t. I choose to grease up the back gear and cleaned everything else.
In putting it back together, I found that the main drive belt was coming apart in a few places. So off to the local belt supplier I headed. Unfortunately, they couldn’t find anything that matched the numbers on the belt and I, not wanting to get my wife’s car dirty, decided NOT to bring the belt with me. So there I am, all dressed up having just come from a funeral, my glasses conveniently left at home, my wife equally dressed patiently sitting in the car and I’m at the dirty ol’ parts counter on my cell phone blindly trying to find some reference to belt size for a Bridgeport. Considering I can’t see crap without my glasses, you’d think I would’ve opted for a larger screen! My wife comes walking in and whispers in my ear “what the hell goes on in here?”. Having never been in such a fine establishment, she couldn’t quite figure out why there were 10 greasy guys, and me (who at other times would have fit right in), sitting on stools staring at the counter in silence…
Trip 2. They were able to measure up the belt and came up with a BAN 2230V345 as the modern replacement for that old thing. So, for anyone in a similar situation, that is the PART NUMBER FOR A BRIDGEPORT SERIES I or SERIES 1 BOSS 8 CNC MILL BELT REPLACEMENT (hopefully the search engines heard that).
And with that, I was able to button up the top section of the mill. Yey!
Picked up an R2E3 about a month ago at a local auction in a generally unknown condition. Actually, it was in a completely unknown condition as I didn’t make it to the preview… I know, you’re probably wondering why you are reading this about now as I must be dumb as a stump to buy a machine site unseen. And I gotta admit, I had a tinge of buyers remorse as soon as I hit the submit button. Unfortunately, that was nothing compared to the moment of shear terror when I actually saw the machine! Funny thing is, the machine looked like it was in great shape, it was just that moment when it was actually in front of me and I remembered how big these things are and how questionable the trailer was that I had to get it home on. Anyhow, after a few scary moments with the auction house’s forklift operator, we managed to get it on to the trailer and down the road without incident.
As you search some of the forums you find people saying they got a machine like this “for a song”. I always wonder what that really means so for what it’s worth, I had to give about $800 with tax. Luckily, as scary as it was, the auction house loaded for free. When I got it home I faced the 7 foot garage door dilemma. Searching online I found that people attack this problem in many different ways. The easiest of which seems to be removing the head by taking off the two side covers and removing the four bolts that are used for tramming the head. This is NOT how I did it!
A few years back, a buddy of mine purchased a similar machine at auction. His was a little older Series II with stepper motors. At some point his spindle motor sizzled and he had to have it rewound. I had this idea in my mind that it was pretty easy for us to remove the motor. So I decided instead to disassemble the top portion of the head. I figured it would allow me to get a look at most of the belts and bearings and replace anything questionable before firing the thing up. So an hour here and there over the next couple of weeks and a gallon of degreaser later, I had the top end torn apart enough that I could easily clear the 7 foot door. I had a local crane company bring one of their small cranes out one morning and it took about five minutes to hook it up to the crane and drop it on six pieces of round tube right outside my garage door. At which point, I was able to easily push the thing into position. Having, at another point in time, unloaded my Hardinge AHC from the same trailer with nothing more than a cherry picker and some good old-fashioned ingenuity, the $98 for the crane was some of the best money I’ve ever spent.
You can see in the photo my method of dis-assembly. It was pretty easy to do it this way, and I am glad that it forced me to go through everything in the top-end. The only thing I haven’t really checked out are the spindle bearings but with any luck they are in good shape.
unoconv fails when run under www-data. Looking for work-around.