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
module Euler.Problem1 where | |
-- | Given a maximum integer m and a factor n calculates the sum | |
-- of all divisors of the given factor up to m. | |
sumDivisible :: Int -> Int -> Int | |
sumDivisible m n = n * (p * (p + 1)) `div` 2 where p = m `div` n | |
result = (sumDivisible 999 3) + (sumDivisible 999 5) - (sumDivisible 999 15) | |
solve::String |
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
/** | |
* Given a maximum integer m and a factor n calculates the sum | |
* of all divisors of the given factor up to m. | |
* | |
* @param m maximum integer | |
* @param n given factor (i.e. 3 or 5) | |
* @return the sum of all divisors. | |
*/ | |
def sumDivisible(m: Int, n:Int): Int = { |
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 sumDivisible(m,n): | |
""" | |
Given a maximum integer m and a factor n, calculates the sum | |
of all divisors of n up to m. | |
""" | |
p = m // n | |
return n * (p * (p + 1)) // 2 | |
def solve(): |
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
# Given a maximum integer m and a factor n, calculates the sum | |
# of all divisors of n up to m. | |
def sumDivisible(m,n) | |
p = m / n | |
n * (p * (p + 1)) / 2 | |
end | |
def solve | |
result = sumDivisible(999,3) + sumDivisible(999,5) - sumDivisible(999, 15) |
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_palindrome(n): | |
text = str(n) | |
return text == text[::-1] | |
def palindromes(): | |
for j in range(100,1000): | |
for k in range(100,1000): | |
product = j * k |
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 StringIO | |
def get_big_number(): | |
number = """ | |
73167176531330624919225119674426574742355349194934 | |
96983520312774506326239578318016984801869478851843 | |
85861560789112949495459501737958331952853208805511 | |
12540698747158523863050715693290963295227443043557 | |
66896648950445244523161731856403098711121722383113 | |
62229893423380308135336276614282806444486645238749 |
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 StringIO | |
def get_big_numbers(): | |
number = """ | |
37107287533902102798797998220837590246510135740250 | |
46376937677490009712648124896970078050417018260538 | |
74324986199524741059474233309513058123726617309629 | |
91942213363574161572522430563301811072406154908250 | |
23067588207539346171171980310421047513778063246676 | |
89261670696623633820136378418383684178734361726757 |
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 collatz(start=1): | |
n = start | |
while n!= 1: | |
n = n / 2 if not n % 2 else 3 * n + 1 | |
yield n | |
def count(limit=13): | |
n = 2 | |
while n < 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
if __name__ == '__main__': | |
number = sum( [int(n) for n in str(2 ** 1000)] ) | |
print "The sum of the digits of the number 2^1000 is: %d" % number |
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 next_number(stop=1000): | |
n = 1 | |
while n <= stop: | |
yield n ** n | |
n += 1 | |
if __name__ == '__main__': | |
result = str(sum(next_number()))[-10:] | |
print "The last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000 is: %s" % result |
OlderNewer