Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
jakedobkin / gist:1440758
Created December 7, 2011 00:19
Project Euler 40 in JS
#!/usr/local/bin/node
// calculate the decimal to 1MM places, but record certain values
string = "";
for (i=1;i<=1000000;i++)
{
string += i.toString()
}
@jakedobkin
jakedobkin / gist:1441186
Created December 7, 2011 02:39
Euler 42 in JS
#!/usr/local/bin/node
// first, prep prime seive up to 7654321, which is the largest pan that doesn't fail the
// summing divisibility rules for 3 or 9
n=7654321;
myPrimes = new Array();
for (i=2;i<=n;i++)
{
myPrimes[i]=true;
@jakedobkin
jakedobkin / gist:1444954
Created December 7, 2011 22:13
Euler 42
#!/usr/local/bin/node
words = ["A","ABILITY","ABLE","ABOUT","ABOVE","ABSENCE","ABSOLUTELY","ACADEMIC","ACCEPT","ACCESS","ACCIDENT","ACCOMPANY","ACCORDING","ACCOUNT","ACHIEVE","ACHIEVEMENT","ACID","ACQUIRE","ACROSS","ACT","ACTION","ACTIVE","ACTIVITY","ACTUAL","ACTUALLY","ADD","ADDITION","ADDITIONAL","ADDRESS","ADMINISTRATION","ADMIT","ADOPT","ADULT","ADVANCE","ADVANTAGE","ADVICE","ADVISE","AFFAIR","AFFECT","AFFORD","AFRAID","AFTER","AFTERNOON","AFTERWARDS","AGAIN","AGAINST","AGE","AGENCY","AGENT","AGO","AGREE","AGREEMENT","AHEAD","AID","AIM","AIR","AIRCRAFT","ALL","ALLOW","ALMOST","ALONE","ALONG","ALREADY","ALRIGHT","ALSO","ALTERNATIVE","ALTHOUGH","ALWAYS","AMONG","AMONGST","AMOUNT","AN","ANALYSIS","ANCIENT","AND","ANIMAL","ANNOUNCE","ANNUAL","ANOTHER","ANSWER","ANY","ANYBODY","ANYONE","ANYTHING","ANYWAY","APART","APPARENT","APPARENTLY","APPEAL","APPEAR","APPEARANCE","APPLICATION","APPLY","APPOINT","APPOINTMENT","APPROACH","APPROPRIATE","APPROVE","AREA","ARGUE","ARGUMENT","ARISE","ARM","ARMY","AROUND","ARRANG
@jakedobkin
jakedobkin / gist:1448512
Created December 8, 2011 20:50
euler 43 python
# let's try using the built in permutation function!
import itertools
x = itertools.permutations('0123456789', 10)
sum = 0
for i in x:
string= "".join(list(i))
number = int(string)
# let's start by making a set of all pentagonal numbers from to n=10000
# you can actually do to like n=4000 and get the same answer
# then let's say check every number in set vs. every other.
# if sum and difference is also in the set, compute the difference, print
h = set()
for i in range (1,10000):
pent = (i*(3*i-1))/2
h.add(pent)
@jakedobkin
jakedobkin / gist:1452516
Created December 9, 2011 17:36
Euler 45 in Python
# we'll store numbers in two sets and keep going until we get a match
i = 286
found = False
p = set()
h = set()
while found == False:
hex = (i*(2*i-1))
h.add(hex)
@jakedobkin
jakedobkin / gist:1453136
Created December 9, 2011 20:21
Euler 46 Python
# set up prime seive
n=10000
myPrimes = []
myPrimes = [True]*10001
myPrimes[0] = False
myPrimes[1] = False
for i in range (2,n):
if myPrimes[i] == True:
j = 2*i
while j<=n:
@jakedobkin
jakedobkin / gist:1453787
Created December 9, 2011 23:21
Euler 47- modified sieve method in python
# set up 2 sieves- one is erastosthenes, the other is to track count
n=200000
myPrimes = [True]*(n+1)
myCount = [0]*(n+1)
# sieve, but count each time each composite number is hit during sieve
for i in range (2,n):
if myPrimes[i] == True:
j = 2*i
while j<=n:
@jakedobkin
jakedobkin / gist:1455632
Created December 10, 2011 17:18
Euler 48 Python: Exponential sum series
# http://projecteuler.net/problem=48.
n = 1000
sum = 0
for i in range (1,n+1):
sum += i**i
print str(sum)[-10:]
# python makes this trivial- but for a language that can't deal with large numbers,
@jakedobkin
jakedobkin / gist:1456068
Created December 10, 2011 19:35
Euler 49 Prime Permutations
# http://projecteuler.net/problem=49
# we'll use the python built-in permutation function
import itertools
# prime sieve
n=100000
myPrimes = [True]*(n+1)
for i in range (2,n):
if myPrimes[i] == True: