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
UPPER_LETTER_OFFSET = ord("A") - 1 | |
names = sorted(open("euler_022_data.txt").read().replace('"', "").split(",")) | |
result = 0 | |
for (i, name) in enumerate(names, 1): | |
name_score = 0 | |
for c in name: | |
name_score += ord(c) - UPPER_LETTER_OFFSET | |
result += name_score * i | |
print result |
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
def gnome_sort(a): | |
i = 0 | |
while i < len(a)-1: | |
if a[i] > a[i+1] and i >= 0: | |
(a[i], a[i+1]) = (a[i+1], a[i]) | |
i -= 1 | |
else: | |
i += 1 | |
a = [4, 2, 42, 356, 5, 100, 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
from official.ref.is_palindromic_1 import is_palindromic | |
result = 0 | |
for i in range(1, 1000000): | |
if is_palindromic(str(i)) and is_palindromic(bin(i)[2:]): | |
result += i | |
print result |
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
def print_halves(n): | |
print n | |
while n > 0: | |
n = n / 2 | |
print n | |
print_halves(57) | |
def binary_length(n): | |
i = 0 | |
while n > 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
pond = input("Diameter of the pond? ") | |
water_lily = input("Initial diameter of the water lily? ") | |
growth = input("Daily growth? ") | |
day = 0 | |
while water_lily < pond: | |
day += 1 | |
water_lily *= growth | |
print "On day %s: %s" % (day, water_lily) | |
print"The pond is smothered!" |
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
def sum_proper_divisors(n): | |
acc = 0 | |
for i in xrange(1, n): | |
if n % i == 0: | |
acc += i | |
return acc | |
def amicable_nums(n): | |
m = sum_proper_divisors(n) | |
return sum_proper_divisors(m) == n and m != 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
def max_length(elements): | |
acc = "" | |
for element in elements: | |
if len(element) > len(acc): | |
acc = element | |
return len(acc) | |
def print_boxed_text(elements): | |
max_length_of_elements = max_length(elements) | |
print "#" * (max_length_of_elements + 4) | |
for element in elements: |
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
for i in range(1 , 21): | |
if i % 15 == 0: | |
print "FizzBuzz" | |
elif i % 3 == 0: | |
print "Fizz" | |
elif i % 5 == 0: | |
print "Buzz" | |
else: | |
print 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
#Program without functions | |
mileage = input("Mileage? ") | |
duration = input("Duration (in days)? ") | |
category = raw_input("Categorie (A or B)? ") | |
COST_PER_DAY_UNLIMITED_A = 70 | |
COST_PER_DAY_PACKAGE_A = 50 | |
COST_PER_DAY_UNLIMITED_B = 140 |
NewerOlder