Skip to content

Instantly share code, notes, and snippets.

View mavant's full-sized avatar

Matthew Avant mavant

View GitHub Profile
@mavant
mavant / gist:7592554
Created November 22, 2013 00:29
Project Euler problem 67
import operator, csv
pyramid = []
with open ('triangle.txt', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter='\n')
for row in reader:
temp = row[0].split()
for x in range(len(temp)):
temp[x]=int(temp[x])
@mavant
mavant / gist:7592563
Created November 22, 2013 00:30
Project Euler problem 25
i = 1
n = 0
a = 1
b = 1
while n < 1000:
temp = b
b = a + b
a = temp
n = len(str(b))
i += 1
@mavant
mavant / gist:7592568
Created November 22, 2013 00:31
Project Euler problem 23
import logging, math
logging.basicConfig(level=logging.INFO)
def d(n):
#cribbed directly from problem 21; gives the sum of proper divisors
sum = 0
for i in range(1, int(math.sqrt(n)+1)):
if (n % i == 0):
sum += i
return sum
@mavant
mavant / gist:7592575
Created November 22, 2013 00:31
Project Euler problem 19
day = 1
hits = 0
year = 1900
while year < 2001:
for x in range(12):
if (day % 7 == 0 and year != 1900):
hits += 1
amount = 31
if ((x < 7 and x % 2 == 1) or (x > 7 and x % 2 == 0)):
@mavant
mavant / gist:7592805
Created November 22, 2013 00:53
Project Euler problem 18
import operator
pyramid = [[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], [53,71,44,65,25,43,91,52,97,51,14], [70,11,33,28,77,73,17,78,39,68,17,57], [91,71,52,38,17,14,91,43,58,50,27,29,48], [63,66,04,68,89,53,67,30,73,16,69,87,40,31], [04,62,98,27,23,9,70,98,73,93,38,53,60,04,23]]
sums = [0]*len(pyramid)
for row in reversed(pyramid):
row = map (operator.add, row, sums)
print (row)
sums = []
@mavant
mavant / gist:7592810
Created November 22, 2013 00:54
Project Euler problem 20
import math
a = math.factorial(100)
b = str(a)
d = 0
for c in b:
d += int(c)
print (d)
@mavant
mavant / gist:7592816
Created November 22, 2013 00:54
Project Euler problem 21
import math
def d(n):
sum = 0
for i in range(1, int(math.sqrt(n)+1)):
if (n % i == 0):
sum += i
return sum
amicable = []
@mavant
mavant / gist:7592822
Created November 22, 2013 00:55
Project Euler problem 24
import itertools
ints = range(10)
perms = list(itertools.permutations(ints))
print (perms[999999])
@mavant
mavant / gist:7592828
Created November 22, 2013 00:55
Project Euler problem 22
import csv
names = []
sum = 0
with open ('names.txt', 'rb') as csvfile:
namereader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in namereader:
names = names + row
names.sort()
for i in range(len(names)):
@mavant
mavant / gist:7592872
Last active December 29, 2015 01:28
A dice roller with logging written for ninja-academy-online.com. MySQL server information removed. This was my first piece of PHP, many many moons ago.
<html>
<head>
<title>Dice Roller</title>
</head>
<body>
<?php
#first things first - if the user didn't specify a name, die.
IF ($_POST['name'] != null){
#looks like they gave a name!