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
37107287533902102798797998220837590246510135740250 | |
46376937677490009712648124896970078050417018260538 | |
74324986199524741059474233309513058123726617309629 | |
91942213363574161572522430563301811072406154908250 | |
23067588207539346171171980310421047513778063246676 | |
89261670696623633820136378418383684178734361726757 | |
28112879812849979408065481931592621691275889832738 | |
44274228917432520321923589422876796487670272189318 | |
47451445736001306439091167216856844588711603153276 | |
70386486105843025439939619828917593665686757934951 |
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
# Read the problem matrix into an array in python | |
filename = 'euler13.txt' | |
with open(filename, "r") as ins: | |
array = [] | |
for line in ins: | |
array.append(line) | |
# Convert the array into an array of integers | |
newArray = [] | |
for i in array: | |
newArray.append(int(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
# Longest Collatz Sequence under a million | |
# Function listing collatz sequence for a number | |
def collatz(n): | |
"function listing collatz sequence for a positive integer" | |
coll = [] | |
coll.append(n) | |
while n != 1: | |
if n % 2 == 0: | |
n = n/2 | |
coll.append(n) |
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
collatz = {1:1} | |
def Collatz(n): | |
global collatz | |
if not collatz.has_key(n): | |
if n%2 == 0: | |
collatz[n] = Collatz(n/2) + 1 | |
else: | |
collatz[n] = Collatz(3*n + 1) + 1 | |
return collatz[n] |
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
75 | |
95 64 | |
17 47 82 | |
18 35 87 10 | |
20 04 82 47 65 | |
19 01 23 75 03 34 | |
88 02 77 73 07 63 67 | |
99 65 04 28 06 16 70 92 | |
41 41 26 56 83 40 80 70 33 | |
41 48 72 33 47 32 37 16 94 29 |
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
59 | |
73 41 | |
52 40 09 | |
26 53 06 34 | |
10 51 87 86 81 | |
61 95 66 57 25 68 | |
90 81 80 38 92 67 73 | |
30 28 51 76 81 18 75 44 | |
84 14 95 87 62 81 17 78 58 | |
21 46 71 58 02 79 62 39 31 09 |
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
# Read the problem matrix into a triangle array in python | |
filename = 'euler67.txt' | |
with open(filename, "r") as ins: | |
array = [] | |
for line in ins: | |
array.append(line) | |
# Convert the triangle arry entries into integers | |
newArray = [] | |
for i in array: | |
j = i.split(' ') |
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
from itertools import permutations | |
from itertools import combinations | |
# array of candidate solutions empty at the beginning | |
record = [] | |
# choose 5 numbers for inner cells between 1 and 9; there are 9C5 combinations | |
# the problem ask for a 16-digit number, so 10 is not to be included in inner cells | |
cells = range(1,10) | |
inner_cells = [map(int,comb) for comb in combinations(cells,5)] |
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
# prints recursive count of lines of python source code from current directory | |
# includes an ignore_list. also prints total sloc | |
import os | |
cur_path = os.getcwd() | |
ignore_set = set(["__init__.py", "count_sourcelines.py"]) | |
loclist = [] | |
for pydir, _, pyfiles in os.walk(cur_path): |
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
## load the requisite libraries into R | |
library("xlsx") | |
library("choroplethr") | |
library("choroplethrAdmin1") | |
library("ggplot2") | |
indianregions <- get_admin1_regions("india") | |
## gets dataframe of 2 columns with name of country ("india") throughout column 1 | |
## and name of regions in 2nd column |