Wednesday, July 22nd, 2009
Two more giants fall:
Project Euler 30: Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
and Project Euler 34: Find the sum of all numbers which are equal to the sum of the factorial of their digits.
Posted in Code, euler | No Comments »
Monday, July 6th, 2009
The trip to Malawi was beginning to dull the technical part of my brain (it is very small, so to neglect it and risk losing it completely would be devastating). To keep sharp I cracked back into the ole’ Project Euler problems. I got two more solved by the pool in the shad of some large banana trees in Lilongwe.
Problem 25: What is the first term in the Fibonacci sequence to contain 1000 digits?
Problem 48: Find the last ten digits of the series, 1^(1) + 2^(2) + 3^(3) + … + 1000^(1000)
Posted in Code, euler | No Comments »
Friday, July 4th, 2008
Hey! I think I’m getting better at this. Well no, probably not, I must have just hit on some easy Euler Problems. But anyway, I solved three more last night. Maybe it’s just being bored back home in Indiana. Yeah I’ll blame my increase in mental acuity on Indiana, THAT makes sense…
Problem 14: Find the longest sequence using a starting number under one million.
Problem 16: What is the sum of the digits of the number 2 to the 1000th power? (Note: This was by far the easiest one I’ve done so far. Took me about 30 seconds to solve)
Problem 20: Find the sum of digits in 100! (Note: This was just problem 16 with one more step)
Posted in Code, euler | No Comments »
Wednesday, July 2nd, 2008
…a giant that has been solved by only 9632 people! Take THAT stupid Project Euler 13! You were too easy, I conquered you in all of 5 minutes, and most of that was time spent adding line breaks into the horrendously large number you provided. The conundrum was such:
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers:
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676
89261670696623633820136378418383684178734361726757
28112879812849979408065481931592621691275889832738
44274228917432520321923589422876796487670272189318
47451445736001306439091167216856844588711603153276
70386486105843025439939619828917593665686757934951
62176457141856560629502157223196586755079324193331
64906352462741904929101432445813822663347944758178
92575867718337217661963751590579239728245598838407
58203565325359399008402633568948830189458628227828
80181199384826282014278194139940567587151170094390
35398664372827112653829987240784473053190104293586
86515506006295864861532075273371959191420517255829
71693888707715466499115593487603532921714970056938
54370070576826684624621495650076471787294438377604
53282654108756828443191190634694037855217779295145
36123272525000296071075082563815656710885258350721
45876576172410976447339110607218265236877223636045
17423706905851860660448207621209813287860733969412
81142660418086830619328460811191061556940512689692
51934325451728388641918047049293215058642563049483
62467221648435076201727918039944693004732956340691
15732444386908125794514089057706229429197107928209
55037687525678773091862540744969844508330393682126
18336384825330154686196124348767681297534375946515
80386287592878490201521685554828717201219257766954
78182833757993103614740356856449095527097864797581
16726320100436897842553539920931837441497806860984
48403098129077791799088218795327364475675590848030
87086987551392711854517078544161852424320693150332
59959406895756536782107074926966537676326235447210
69793950679652694742597709739166693763042633987085
41052684708299085211399427365734116182760315001271
65378607361501080857009149939512557028198746004375
35829035317434717326932123578154982629742552737307
94953759765105305946966067683156574377167401875275
88902802571733229619176668713819931811048770190271
25267680276078003013678680992525463401061632866526
36270218540497705585629946580636237993140746255962
24074486908231174977792365466257246923322810917141
91430288197103288597806669760892938638285025333403
34413065578016127815921815005561868836468420090470
23053081172816430487623791969842487255036638784583
11487696932154902810424020138335124462181441773470
63783299490636259666498587618221225225512486764533
67720186971698544312419572409913959008952310058822
95548255300263520781532296796249481641953868218774
76085327132285723110424803456124867697064507995236
37774242535411291684276865538926205024910326572967
23701913275725675285653248258265463092207058596522
29798860272258331913126375147341994889534765745501
18495701454879288984856827726077713721403798879715
38298203783031473527721580348144513491373226651381
34829543829199918180278916522431027392251122869539
40957953066405232632538044100059654939159879593635
29746152185502371307642255121183693803580388584903
41698116222072977186158236678424689157993532961922
62467957194401269043877107275048102390895523597457
23189706772547915061505504953922979530901129967519
86188088225875314529584099251203829009407770775672
11306739708304724483816533873502340845647058077308
82959174767140363198008187129011875491310547126581
97623331044818386269515456334926366572897563400500
42846280183517070527831839425882145521227251250327
55121603546981200581762165212827652751691296897789
32238195734329339946437501907836945765883352399886
75506164965184775180738168837861091527357929701337
62177842752192623401942399639168044983993173312731
32924185707147349566916674687634660915035914677504
99518671430235219628894890102423325116913619626622
73267460800591547471830798392868535206946944540724
76841822524674417161514036427982273348055556214818
97142617910342598647204516893989422179826088076852
87783646182799346313767754307809363333018982642090
10848802521674670883215120185883543223812876952786
71329612474782464538636993009049310363619763878039
62184073572399794223406235393808339651327408011116
66627891981488087797941876876144230030984490851411
60661826293682836764744779239180335110989069790714
85786944089552990653640447425576083659976645795096
66024396409905389607120198219976047599490197230297
64913982680032973156037120041377903785566085089252
16730939319872750275468906903707539413042652315011
94809377245048795150954100921645863754710598436791
78639167021187492431995700641917969777599028300699
15368713711936614952811305876380278410754449733078
40789923115535562561142322423255033685442488917353
44889911501440648020369068063960672322193204149535
41503128880339536053299340368006977710650566631954
81234880673210146739058568557934581403627822703280
82616570773948327592232845941706525094512325230608
22918802058777319719839450180888072429661980811197
77158542502016545090413245809786882778948721859617
72107838435069186155435662884062257473692284509516
20849603980134001723930671666823555245252804609722
53503534226472524250874054075591789781264330331690
So I did what I was told and what have I got to show for it? Nuthin! Just this post before going to bed before going to Indianapolis.
Posted in Code, euler | No Comments »
Tuesday, June 3rd, 2008
The clouds have parted (even though it’s storming here right now) and allowed me to briefly glimpse the mind of god. It is an ugly beast that takes nearly a minute to solve this simple(ish) problem, and does not lend itself easily to more complex operations, but it works for what I needed it for (to advance and increase my genius rating mwah ha ha!). Thanks for helping me solve Project Euler #10 god. Your aid will soon be forgotten, my increased genius ranking however, will not.
#!/usr/bin/env python
#euler10.py
#Calculate the sum of all primes below 2,000,000def main():
Primes = [2]
n = 2
sum = 2
for i in range(3, 2000000):
while i % n != 0 and n <= 2001:
n += 1
if n == i or n > 2000:
Primes.append(i)
sum += i
else:
n = 2
print sumif __name__ == ‘__main__’:
main()
Posted in Code, euler | No Comments »
Thursday, May 29th, 2008
73, 32, 102, 105, 110, 97, 108, 108, 121, 32, 102, 105, 110, 105, 115, 104, 101, 100, 32, 97, 110, 111, 116, 104, 101, 114, 32, 74, 97, 118, 97, 83, 99, 114, 105, 112, 116, 32, 98, 117, 105, 108, 100, 32, 111, 102, 32, 111, 110, 101, 32, 111, 102, 32, 109, 121, 32, 111, 108, 100, 32, 80, 121, 116, 104, 111, 110, 32, 112, 114, 111, 103, 114, 97, 109, 115, 46, 32, 84, 104, 101, 32, 74, 97, 118, 97, 83, 99, 114, 105, 112, 116, 32, 67, 105, 112, 104, 101, 114, 105, 122, 101, 114, 32, 105, 115, 32, 117, 112, 32, 97, 110, 32, 114, 117, 110, 110, 105, 110, 103, 46, 32, 78, 111, 119, 32, 121, 111, 117, 32, 99, 97, 110, 32, 101, 110, 99, 111, 100, 101, 32, 97, 110, 100, 32, 100, 101, 99, 111, 100, 101, 32, 115, 101, 99, 114, 101, 116, 32, 109, 101, 115, 115, 97, 103, 101, 115, 32, 102, 114, 111, 109, 32, 121, 111, 117, 114, 32, 102, 114, 105, 101, 110, 100, 115, 32, 97, 110, 100, 32, 101, 110, 101, 109, 105, 101, 115, 46, 32, 85, 110, 102, 111, 114, 116, 117, 110, 97, 116, 101, 108, 121, 32, 105, 115, 32, 105, 115, 32, 101, 97, 115, 105, 101, 114, 32, 116, 111, 32, 99, 114, 97, 99, 107, 32, 116, 104, 97, 110, 32, 116, 104, 101, 32, 80, 121, 116, 104, 111, 110, 32, 118, 101, 114, 115, 105, 111, 110, 44, 32, 97, 115, 32, 116, 104, 101, 114, 101, 32, 119, 97, 115, 32, 97, 110, 32, 101, 108, 101, 109, 101, 110, 116, 32, 111, 114, 32, 116, 119, 111, 32, 116, 104, 97, 116, 32, 73, 32, 104, 97, 118, 101, 32, 98, 101, 101, 110, 32, 117, 110, 97, 98, 108, 101, 32, 116, 111, 32, 115, 117, 99, 99, 101, 115, 115, 102, 117, 108, 108, 121, 32, 97, 112, 112, 108, 121, 32, 105, 110, 32, 116, 104, 101, 32, 74, 97, 118, 97, 83, 99, 114, 105, 112, 116, 32, 98, 117, 105, 108, 100, 32, 111, 102, 32, 116, 104, 101, 32, 112, 114, 111, 103, 114, 97, 109, 46, 32, 66, 117, 116, 32, 105, 116, 32, 119, 111, 114, 107, 115, 32, 97, 115, 32, 105, 116, 32, 115, 104, 111, 117, 108, 100, 44, 32, 97, 110, 100, 32, 105, 115, 32, 103, 117, 97, 114, 97, 110, 116, 101, 101, 100, 32, 116, 111, 32, 112, 114, 111, 118, 105, 100, 101, 32, 108, 105, 116, 101, 114, 97, 108, 108, 121, 32, 109, 111, 109, 101, 110, 116, 115, 32, 111, 102, 32, 102, 117, 110, 32, 102, 111, 114, 32, 121, 111, 117, 32, 97, 110, 100, 32, 111, 110, 101, 32, 111, 116, 104, 101, 114, 32, 112, 101, 114, 115, 111, 110, 46
Posted in Code, euler | No Comments »
Thursday, May 22nd, 2008
After over a week, I have finally come up with a solution to Project Euler #3. In which I was asked to find the largest prime factor of the number 600851475143. This was a particularly nasty little bugger that gave me all sorts of hell. It took me a while in the first place to come up with an algorithm to figure primes. I thought I was sitting pretty when I got that working, but the number they give was too big to compute with brute force, so I had to come up with a way to chop it down a bit. The solution, as you can see, is pretty messy, and I barely have a grasp on how it even works. The print out is also really quite gross, so you have to know what you’re even looking for, but it works. I’ve got my answer. I can sleep through my nights once more.
I’ve also managed to plow through another problem involving Primes that I had passed over, Problem 7, which by comparison seemed pretty meager simply asking me to find the 10001st Prime. No problem. Just takes a while to compute.
Posted in Code, euler | No Comments »
Wednesday, May 21st, 2008
I tried to explain that I am lousy with math, but it seemed like my head was on straight enough. However the worst of all possible nightmarishly ironic situations has occurred: my math describing how bad my math is has turned out to be incorrect. So, as a formal retraction to my claim that my solution to Project Euler #9 goes through !3000 iterations to produce it’s results, I must announce that it does not. My buddy Carl tipped me off to the fact, of which I am logically aware, but chose to ignore since the thrill of stupidly large numbers was at stake, that !3000 is a number larger than the count of atoms in the universe, or grains of sand on all the World’s beaches. The correct total of iterations for this particular program is more sensible: 1,000,000,000. Which I guess is large enough, but it sure aint no !3000. However, I do trust that my skills are slowly getting less bad. It has been at least seven years since I have done any real and consistent crunching of numbers (I went to Art School remember), and it is a disappointment, but no surprise that is taking me some time to get back into the swing of things.
Posted in Code, euler | No Comments »
Saturday, May 17th, 2008
So in progressing through Project Euler it is becoming more and more apparent that with slightly better math skills, I could be much more efficient at this. For example, my solution to Problem 9. While the code itself may not look all that messy, this is probably the WORST way to solve this one. My computer is not very happy with me at the moment, but I got the right answer damnit! But this just goes to show you, you can get the right answer the wrong way. In this case I was trying to find the ONE Pythagorean Triplet (a < b < c where a*a + b*b = c*c) that sums to 1000. With my solution I had it running through !3000 (3000 Factorial) iterations, or, more accurately, this lovely 9,131 digit number. I’ve gotta get better at this stuff.
Posted in Code, euler | No Comments »
Saturday, May 17th, 2008
Through overwhelming use of my brain powers, I have successfully (albeit, not particularly elegantly) solved three more Project Euler Problems. In Problem 5 I found the smallest integer divisible by all numbers 1 – 20. My solution to this one is TERRIBLE, but it works, so I haven’t fixed it yet. Problem 6 I found the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum. I’m pretty happy with my solution to that one, but I’m no expert, and I’m sure all of these can be further simplified. Last on the updates is Problem 8 which came out nearly allright. I could pretty it up a bit, but it’s a decent way to muscle through this particular problem, which was to find the greatest product of five consecutive digits in the 1000-digit number given.
Keep in mind that there are much more intelligent humans solving these in much more intelligent ways than I am currently. I just happen to have gone slightly insane, and find it kind of fun to spend my Friday nights at home working on math problems and listening to Phil Ochs. If a version of myself were to time travel to now from the past, I’m sure he would be horrified to the point of self obliteration, and thusly eliminate all possibility of me ever falling into this lifestyle.
Posted in Code, euler | No Comments »