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
" Vim syntax file | |
" Language: Haml (XHTML Abstraction Markup Language) | |
" Maintainer: Dmitry A. Ilyashevich <dmitry.ilyashevich@gmail.com> | |
" License: This file can be redistribued and/or modified under the same terms | |
" as Vim itself. | |
" | |
" Version: 0.3.it | |
" Last Change: 2008-10-21 | |
" Notes: Last synced with Haml 1.8 | |
" TODO: Support for indented multiline sections |
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 factors(num): | |
"""Generates the factors for num. | |
By PEZ, from a description by BradC over at Stackoverflow.com | |
http://stackoverflow.com/questions/439814#439850 | |
""" | |
from math import sqrt | |
def _candidates(): | |
"""Generates the sequence 2, then all odd ints starting with 3""" |
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
""" Project Euler Problem 99 http://projecteuler.net/index.php?section=problems&id=99 """ | |
def max_base_exp(base_exps): | |
from math import log | |
return reduce(lambda a, b: a if a[2] * log(a[1]) > b[2] * log(b[1]) else b, base_exps) | |
print max_base_exp([ | |
(1, 519432, 525806), | |
(2, 632382, 518061), | |
(3, 78864, 613712), | |
(4, 466580, 530130), |
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
"""Find the sum of all numbers below 1000 divisible by 3 or 5. | |
http://projecteuler.net/index.php?section=problems&id=1""" | |
#Brute force #1 | |
sum(x for x in xrange(3,1000) if x % 3 == 0 or x % 5 == 0) | |
#Brute force #2 | |
sum(set(range(3, 1000, 3) + range(5, 1000, 5))) | |
#Less brute (after reading the problem discussion PDF) |
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
"""Sum of all even fibonacci numbers below 4000000 | |
http://projecteuler.net/index.php?section=problems&id=2""" | |
#Brute force | |
def fibs_up_to(t, a=1, b=2): | |
while a < t: | |
yield a | |
a, b = b, a + b | |
sum(n for n in fibs_up_to(4000000) if n % 2 == 0) |
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
"""Find the largest palindrom that is the product of two three-digit factors: | |
http://projecteuler.net/index.php?section=problems&id=4""" | |
# Brute force | |
def big_products(max): | |
for a in xrange(100, 1000): | |
for b in xrange(100, 1000): | |
yield str(a * b) | |
max(int(p) for p in big_products(999) if p == p[::-1]) |
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
"""Python for Project Euler #5: http://projecteuler.net/index.php?section=problems&id=5 | |
Find the smallest number that is divisible with all integers from 1 to 20""" | |
#It's the Least Common Multiple; lcm(1,2, ..., 20) | |
def gcd(a, b): | |
while b > 0: | |
a, b = b, a % b | |
return a | |
def lcm(a, b): |
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
=== Search on search === | |
Contributors: cobpez | |
Donate link: http://wikimediafoundation.org/wiki/Support_Wikipedia/en | |
Tags: search, widget, search engines | |
Requires at least: 2.8 | |
Tested up to: 2.9.1 | |
Stable tag: trunk | |
A Widget that links to posts and pages matching search engine terms used to find the page. |
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
@property | |
def type(self): | |
stripped = re.sub(r'Notification$', '', self.__class__.__name__) | |
if stripped != '': | |
return re.sub(r'([a-z])([A-Z])', '%s_%s' % (r'\1', r'\2'), stripped).lower() | |
else: | |
return 'generic' |
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
''' | |
Created on Jan 12, 2011 | |
@author: cobpez | |
''' | |
import math | |
def double_squares(v): | |
for x in xrange(int(math.sqrt(v))): | |
y = math.sqrt(v - x*x) |
OlderNewer