This file contains 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
import itertools | |
products = set() | |
for (a, b) in itertools.product(range(2, 101), range(2, 101)): | |
products.add(a ** b) | |
print len(products) |
This file contains 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
def is_even(n): | |
return n % 2 == 0 | |
def mod_exp(base, exponent, modulus): | |
if exponent == 0: | |
return 1 | |
temp = mod_exp(base, exponent / 2, modulus) | |
if is_even(exponent): |
This file contains 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 * | |
pairs = product(range(1, 100), range(1, 100)) | |
exponentials = imap(lambda pair: pair[0] ** pair[1], pairs) | |
strings = imap(lambda exponential: str(exponential), exponentials) | |
sums = imap(lambda string: sum(map(lambda digit: int(digit), string)), strings) | |
print max(sums) |
This file contains 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
current = 0 | |
step = 2 | |
sum = 0 | |
limit = 1001 ** 2 | |
spiral = range(1, limit + 1) | |
while current < limit: | |
for i in range(4): |
This file contains 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
CAPITAL_LETTER_A = 'A' | |
COMMA = "," | |
def triangular_numbers(): | |
n = 1 | |
while True: | |
yield n * (n + 1) / 2 | |
n += 1 | |
def score_char(char): |
This file contains 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
public static void Main(string[] args) | |
{ | |
for (var n = 286L; ; n++) | |
{ | |
var triangleNumber = TriangleNumber(n); | |
if (IsPentagonal(triangleNumber) && IsHexagonal(triangleNumber)) | |
{ | |
Console.WriteLine(triangleNumber); | |
break; | |
} |
This file contains 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
set ai | |
set smartindent | |
set lbr | |
"set nowrap | |
"set expandtab | |
set ts=4 | |
set sw=4 | |
"set cindent |
This file contains 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
set ai | |
set smartindent | |
set lbr | |
"set nowrap | |
"set expandtab | |
set ts=4 | |
set sw=4 | |
"set cindent |
This file contains 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
var startDate = DateTime.Parse("1 Jan 1901"); | |
var endDate = DateTime.Parse("31 Dec 2000"); | |
var currentDate = startDate; | |
var count = 0; | |
while (currentDate < endDate) | |
{ | |
if (currentDate.DayOfWeek == DayOfWeek.Sunday) |
This file contains 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
Console.WriteLine(Enumerable.Range(0, 1000000) | |
.Where(x => x.IsPalindromic() && x.IsPalindromic(Base2)).Sum()); |