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 prefixes = [ "", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei" ]; | |
const GROUP = 1024; | |
function binaryUnitFormat(x, unit) { | |
var index = 0; | |
var xnew = x; | |
while (xnew >= GROUP && index < prefixes.length - 1) { | |
xnew /= GROUP; |
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 Iterable = { | |
func: { | |
predicate: { | |
TRUE: function (x) { return true; } | |
} | |
} | |
}; | |
Array.prototype.forEach = function (fn) { | |
for (var i = 0; i < this.length; i++) |
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 Iterable = { | |
func: { | |
predicate: { | |
TRUE: function (x) { return true; } | |
} | |
} | |
}; | |
Array.prototype.forEach = function (fn) { | |
for (var i = 0; i < this.length; i++) |
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
head [ (a, b, c) | c <- [1..], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a + b + c == 1000 ] |
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 permutations | |
MILLIONTH = 10 ** 6 - 1 | |
print reduce(lambda x, y: str(x) + str(y), list(permutations(range(10), 10))[MILLIONTH]) |
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
products = set() | |
for pair in [(a, b) for a in range(2, 101) for b in range(2, 101)]: | |
products.add(pair[0] ** pair[1]) | |
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
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): | |
if current > limit: |
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
digits = "" | |
for n in range(1, 1000001): | |
digits += str(n) | |
product = 1 | |
for i in range(7): | |
product *= int(digits[10 ** i - 1]) | |
print product |
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 operator | |
def factorial(n): | |
return 1 if n == 0 else reduce(operator.mul, range(1, n + 1)) | |
def combo(n, r): | |
return factorial(n) / (factorial(r) * factorial(n - r)) | |
count = 0 |