Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
jakedobkin / gist:1381787
Created November 21, 2011 05:59
Euler 19
#!/usr/local/bin/node
// set up arrays for day names and number of days in month
days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
daysinmonth = [31,28,31,30,31,30,31,31,30,31,30,31]
daysinmonth_leapyear = [31,29,31,30,31,30,31,31,30,31,30,31]
// enter starting day and date (monday = 1 in our array), also initials vars
// 1.1.1901 is a tuesday (2 in days array)- i figured that out using this program
// but using the info they gave us about 1/1/1900 being a monday.
@jakedobkin
jakedobkin / gist:1380694
Created November 20, 2011 18:55
Euler 18
#!/usr/local/bin/node
// put the text string into an array
triangle = new Array ();
triangle[0] = [75]
triangle[1] = [95,64]
triangle[2] = [17,47,82]
triangle[3] = [18,35,87,10]
triangle[4] = [20,04,82,47,65]
@jakedobkin
jakedobkin / gist:1375704
Created November 18, 2011 05:38
Euler 17
#!/usr/local/bin/node
// first we need to declare a few arrays to hold the names
ones = ["", "one","two","three","four","five","six","seven","eight","nine", "ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"]
twenties = ["","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"]
sum = 0;
// for loop to extract each number, turn it into a string, slice it into digits
@jakedobkin
jakedobkin / gist:1371865
Created November 16, 2011 23:30
Euler 16 in Python
# let's try to do problem 16 in python
# first, we need to do some python math
# apparently the ** is exponent in python
answer = str(2**1000)
# now we need to extract each position from this string, convert it back to a number, and add
i=0
sum=0
@jakedobkin
jakedobkin / gist:1371619
Created November 16, 2011 22:06
Euler 15
#!/usr/local/bin/node
// number of paths is a combination 40C20, because you have to get there in 40 steps and make 20 choices along the way
// that's n! / k! (n-k)!
n = 40;
k = 20;
nminusk = n-k;
n_factorial = 1;
k_factorial = 1;
@jakedobkin
jakedobkin / gist:1370968
Created November 16, 2011 18:54
Euler 14
#!/usr/local/bin/node
// basic strategy is to run a for loop to check each number, and then run a while loop
// with some if statements to run each number down to 1 counting the steps.
biggesti = 0;
biggest = 0;
for(i=13;i<1000000; i++)
{
@jakedobkin
jakedobkin / gist:1370739
Created November 16, 2011 17:28
Euler 13
#!/usr/local/bin/node
// why can't we just declare each line in an array and then add?
sum=0;
myNumbers = new Array();
// you could probably cut these out into 50 digit strings automatically with a loop rather than typing them out;
@jakedobkin
jakedobkin / gist:1370671
Created November 16, 2011 17:06
Euler 11
#!/usr/local/bin/node
// according to wikipedia, formula for triangle numbers is Tn=n(n+1)/2
// so we can just generate triangle numbers with a while loop, and then check for factors with a for loop
// everytime it finds a factor, add 1 to the limit, end for loop when factors > 500
biggesti = 0;
biggesttriangle = 0;
biggestfactors = 0;
@jakedobkin
jakedobkin / gist:1368349
Created November 15, 2011 21:08
Euler 11
#!/usr/local/bin/node
// i decided to do this as array of strings instead of a 2-dim array
myGrid = new Array();
myGrid[0] = "08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08";
myGrid[1] = "49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00";
myGrid[2] = "81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65";
myGrid[3] = "52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91";
myGrid[4] = "22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80";
myGrid[5] = "24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50";
#!/usr/local/bin/node
//NOW WITH NODE.JS
n=2000000;
sumPrimes=0;
myPrimes = new Array();
// set all array values to true