This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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++) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/node | |
| //NOW WITH NODE.JS | |
| n=2000000; | |
| sumPrimes=0; | |
| myPrimes = new Array(); | |
| // set all array values to true |