zip
stringlengths
19
109
filename
stringlengths
4
185
contents
stringlengths
0
30.1M
type_annotations
listlengths
0
1.97k
type_annotation_starts
listlengths
0
1.97k
type_annotation_ends
listlengths
0
1.97k
archives/1098994933_python.zip
matrix/tests/test_matrix_operation.py
""" Testing here assumes that numpy and linalg is ALWAYS correct!!!! If running from PyCharm you can place the following line in "Additional Arguments" for the pytest run configuration -vv -m mat_ops -p no:cacheprovider """ # standard libraries import sys import numpy as np import pytest import logging # Custom/loca...
[]
[]
[]
archives/1098994933_python.zip
networking_flow/ford_fulkerson.py
# Ford-Fulkerson Algorithm for Maximum Flow Problem """ Description: (1) Start with initial flow as 0; (2) Choose augmenting path from source to sink and add path to flow; """ def BFS(graph, s, t, parent): # Return True if there is node that has not iterated. visited = [False]*len(graph) queue=...
[]
[]
[]
archives/1098994933_python.zip
networking_flow/minimum_cut.py
# Minimum cut on Ford_Fulkerson algorithm. test_graph = [ [0, 16, 13, 0, 0, 0], [0, 0, 10, 12, 0, 0], [0, 4, 0, 0, 14, 0], [0, 0, 9, 0, 0, 20], [0, 0, 0, 7, 0, 4], [0, 0, 0, 0, 0, 0], ] def BFS(graph, s, t, parent): # Return True if there is node that has not iterated. visited = [Fals...
[]
[]
[]
archives/1098994933_python.zip
neural_network/back_propagation_neural_network.py
#!/usr/bin/python # encoding=utf8 ''' A Framework of Back Propagation Neural Network(BP) model Easy to use: * add many layers as you want !!! * clearly see how the loss decreasing Easy to expand: * more activation functions * more loss functions * more optimization method Author: Stephen Lee Git...
[]
[]
[]
archives/1098994933_python.zip
neural_network/convolution_neural_network.py
#-*- coding: utf-8 -*- ''' - - - - - -- - - - - - - - - - - - - - - - - - - - - - - Name - - CNN - Convolution Neural Network For Photo Recognizing Goal - - Recognize Handing Writting Word Photo Detail:Total 5 layers neural network * Convolution layer * Pooling layer ...
[]
[]
[]
archives/1098994933_python.zip
neural_network/perceptron.py
''' Perceptron w = w + N * (d(k) - y) * x(k) Using perceptron network for oil analysis, with Measuring of 3 parameters that represent chemical characteristics we can classify the oil, in p1 or p2 p1 = -1 p2 = 1 ''' import random class Perceptron: def __init__(self, sample, exit, learn_r...
[]
[]
[]
archives/1098994933_python.zip
other/anagrams.py
import collections, pprint, time, os start_time = time.time() print('creating word list...') path = os.path.split(os.path.realpath(__file__)) with open(path[0] + '/words') as f: word_list = sorted(list(set([word.strip().lower() for word in f]))) def signature(word): return ''.join(sorted(word)) word_bysig = ...
[]
[]
[]
archives/1098994933_python.zip
other/binary_exponentiation.py
""" * Binary Exponentiation for Powers * This is a method to find a^b in a time complexity of O(log b) * This is one of the most commonly used methods of finding powers. * Also useful in cases where solution to (a^b)%c is required, * where a,b,c can be numbers over the computers calculation limits. * Done using iterati...
[]
[]
[]
archives/1098994933_python.zip
other/binary_exponentiation_2.py
""" * Binary Exponentiation with Multiplication * This is a method to find a*b in a time complexity of O(log b) * This is one of the most commonly used methods of finding result of multiplication. * Also useful in cases where solution to (a*b)%c is required, * where a,b,c can be numbers over the computers calculation l...
[]
[]
[]
archives/1098994933_python.zip
other/detecting_english_programmatically.py
import os UPPERLETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' LETTERS_AND_SPACE = UPPERLETTERS + UPPERLETTERS.lower() + ' \t\n' def loadDictionary(): path = os.path.split(os.path.realpath(__file__)) englishWords = {} with open(path[0] + '/dictionary.txt') as dictionaryFile: for word in dictionaryFile.read...
[]
[]
[]
archives/1098994933_python.zip
other/euclidean_gcd.py
# https://en.wikipedia.org/wiki/Euclidean_algorithm def euclidean_gcd(a, b): while b: t = b b = a % b a = t return a def main(): print("GCD(3, 5) = " + str(euclidean_gcd(3, 5))) print("GCD(5, 3) = " + str(euclidean_gcd(5, 3))) print("GCD(1, 3) = " + str(euclidean_gcd(1, 3))...
[]
[]
[]
archives/1098994933_python.zip
other/fischer_yates_shuffle.py
#!/usr/bin/python # encoding=utf8 """ The Fisher–Yates shuffle is an algorithm for generating a random permutation of a finite sequence. For more details visit wikipedia/Fischer-Yates-Shuffle. """ import random def FYshuffle(LIST): for i in range(len(LIST)): a = random.randint(0, len(LIST)-1) b = r...
[]
[]
[]
archives/1098994933_python.zip
other/frequency_finder.py
# Frequency Finder # frequency taken from http://en.wikipedia.org/wiki/Letter_frequency englishLetterFreq = {'E': 12.70, 'T': 9.06, 'A': 8.17, 'O': 7.51, 'I': 6.97, 'N': 6.75, 'S': 6.33, 'H': 6.09, 'R': 5.99, 'D': 4.25, 'L': 4.03, 'C': 2.78, 'U': 2.76, 'M': 2.41, 'W': 2.36, ...
[]
[]
[]
archives/1098994933_python.zip
other/game_of_life.py
'''Conway's Game Of Life, Author Anurag Kumar(mailto:anuragkumarak95@gmail.com) Requirements: - numpy - random - time - matplotlib Python: - 3.5 Usage: - $python3 game_o_life <canvas_size:int> Game-Of-Life Rules: 1. Any live cell with fewer than two live neighbours dies, as if caused by under-popu...
[]
[]
[]
archives/1098994933_python.zip
other/linear_congruential_generator.py
__author__ = "Tobias Carryer" from time import time class LinearCongruentialGenerator(object): """ A pseudorandom number generator. """ def __init__( self, multiplier, increment, modulo, seed=int(time()) ): """ These parameters are saved and used when nextNumber() is called. ...
[]
[]
[]
archives/1098994933_python.zip
other/nested_brackets.py
''' The nested brackets problem is a problem that determines if a sequence of brackets are properly nested. A sequence of brackets s is considered properly nested if any of the following conditions are true: - s is empty - s has the form (U) or [U] or {U} where U is a properly nested string - s has the form VW whe...
[]
[]
[]
archives/1098994933_python.zip
other/palindrome.py
# Program to find whether given string is palindrome or not def is_palindrome(str): start_i = 0 end_i = len(str) - 1 while start_i < end_i: if str[start_i] == str[end_i]: start_i += 1 end_i -= 1 else: return False return True # Recursive method def r...
[]
[]
[]
archives/1098994933_python.zip
other/password_generator.py
"""Password generator allows you to generate a random password of length N.""" from random import choice from string import ascii_letters, digits, punctuation def password_generator(length=8): """ >>> len(password_generator()) 8 >>> len(password_generator(length=16)) 16 >>> len(password_genera...
[]
[]
[]
archives/1098994933_python.zip
other/primelib.py
# -*- coding: utf-8 -*- """ Created on Thu Oct 5 16:44:23 2017 @author: Christian Bender This python library contains some useful functions to deal with prime numbers and whole numbers. Overview: isPrime(number) sieveEr(N) getPrimeNumbers(N) primeFactorization(number) greatestPrimeFactor(number) smallestPrimeFacto...
[]
[]
[]
archives/1098994933_python.zip
other/sierpinski_triangle.py
#!/usr/bin/python # encoding=utf8 '''Author Anurag Kumar | anuragkumarak95@gmail.com | git/anuragkumarak95 Simple example of Fractal generation using recursive function. What is Sierpinski Triangle? >>The Sierpinski triangle (also with the original orthography Sierpinski), also called the Sierpinski gasket or the Si...
[]
[]
[]
archives/1098994933_python.zip
other/tower_of_hanoi.py
def moveTower(height, fromPole, toPole, withPole): ''' >>> moveTower(3, 'A', 'B', 'C') moving disk from A to B moving disk from A to C moving disk from B to C moving disk from A to B moving disk from C to A moving disk from C to B moving disk from A to B ''' if height >= 1: ...
[]
[]
[]
archives/1098994933_python.zip
other/two_sum.py
""" Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0,...
[]
[]
[]
archives/1098994933_python.zip
other/word_patterns.py
import pprint, time def getWordPattern(word): word = word.upper() nextNum = 0 letterNums = {} wordPattern = [] for letter in word: if letter not in letterNums: letterNums[letter] = str(nextNum) nextNum += 1 wordPattern.append(letterNums[letter]) return '...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_01/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_01/sol1.py
""" Problem Statement: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5,6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. """ def solution(n): """Returns the sum of all the multiples of 3 or 5 below n. >>> solution(3) 0 >...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_01/sol2.py
""" Problem Statement: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5,6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. """ def solution(n): """Returns the sum of all the multiples of 3 or 5 below n. >>> solution(3) 0 ...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_01/sol3.py
""" Problem Statement: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5,6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. """ def solution(n): """ This solution is based on the pattern that the successive numbers in the series...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_01/sol4.py
""" Problem Statement: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5,6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. """ def solution(n): """Returns the sum of all the multiples of 3 or 5 below n. >>> solution(3) ...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_01/sol5.py
""" Problem Statement: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5,6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. """ """A straightforward pythonic solution using list comprehension""" def solution(n): """Returns the sum of...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_01/sol6.py
""" Problem Statement: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5,6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. """ def solution(n): """Returns the sum of all the multiples of 3 or 5 below n. >>> solution(3) 0 >...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_02/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_02/sol1.py
""" Problem: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1,2,3,5,8,13,21,34,55,89,.. By considering the terms in the Fibonacci sequence whose values do not exceed n, find the sum of the even-valued terms. e.g. for n=1...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_02/sol2.py
""" Problem: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1,2,3,5,8,13,21,34,55,89,.. By considering the terms in the Fibonacci sequence whose values do not exceed n, find the sum of the even-valued terms. e.g....
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_02/sol3.py
""" Problem: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1,2,3,5,8,13,21,34,55,89,.. By considering the terms in the Fibonacci sequence whose values do not exceed n, find the sum of the even-valued terms. e.g. for n=1...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_02/sol4.py
""" Problem: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1,2,3,5,8,13,21,34,55,89,.. By considering the terms in the Fibonacci sequence whose values do not exceed n, find the sum of the even-valued terms. e.g. for n=1...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_03/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_03/sol1.py
""" Problem: The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor of a given number N? e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17. """ import math def isprime(no): if no == 2: return True elif no % 2 == 0: return False sq = int(math....
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_03/sol2.py
""" Problem: The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor of a given number N? e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17. """ def solution(n): """Returns the largest prime factor of a given number n. >>> solution(13195) 29 >>> solution...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_04/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_04/sol1.py
""" Problem: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99. Find the largest palindrome made from the product of two 3-digit numbers which is less than N. """ def solution(n): """Returns the largest palindrome made from the prod...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_04/sol2.py
""" Problem: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99. Find the largest palindrome made from the product of two 3-digit numbers which is less than N. """ def solution(n): """Returns the largest palindrome made from the prod...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_05/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_05/sol1.py
""" Problem: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible(divisible with no remainder) by all of the numbers from 1 to N? """ def solution(n): """Returns the smallest positive number that is ...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_05/sol2.py
""" Problem: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible(divisible with no remainder) by all of the numbers from 1 to N? """ """ Euclidean GCD Algorithm """ def gcd(x, y): return x if y ==...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_06/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_06/sol1.py
# -*- coding: utf-8 -*- """ Problem: The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)^2 = 552 = 3025 Hence the difference between the sum of the squares of the first ten natur...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_06/sol2.py
# -*- coding: utf-8 -*- """ Problem: The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)^2 = 552 = 3025 Hence the difference between the sum of the squares of the first ten natur...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_06/sol3.py
# -*- coding: utf-8 -*- """ Problem: The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)^2 = 552 = 3025 Hence the difference between the sum of the squares of the first ten natur...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_07/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_07/sol1.py
# -*- coding: utf-8 -*- """ By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13 We can see that the 6th prime is 13. What is the Nth prime number? """ from math import sqrt def isprime(n): if n == 2: return True elif n % 2 == 0: return False else: sq = int(sqrt(n))...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_07/sol2.py
# -*- coding: utf-8 -*- """ By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13 We can see that the 6th prime is 13. What is the Nth prime number? """ def isprime(number): for i in range(2, int(number ** 0.5) + 1): if number % i == 0: return False return True def solution(...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_07/sol3.py
# -*- coding: utf-8 -*- """ By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13 We can see that the 6th prime is 13. What is the Nth prime number? """ import math import itertools def primeCheck(number): if number % 2 == 0 and number > 2: return False return all(number % i for i in ra...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_08/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_08/sol1.py
# -*- coding: utf-8 -*- """ The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 1254069874715852386305071569329...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_08/sol2.py
# -*- coding: utf-8 -*- """ The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 1254069874715852386305071569329...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_09/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_09/sol1.py
""" Problem Statement: A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. """ def solution(): """ Returns the product of ...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_09/sol2.py
""" Problem Statement: A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. """ def solution(n): """ Return the product of a,...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_09/sol3.py
""" Problem Statement: A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. """ def solution(): """ Returns the product of...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_10/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_10/sol1.py
""" Problem Statement: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. """ from math import sqrt def is_prime(n): for i in range(2, int(sqrt(n)) + 1): if n % i == 0: return False return True def sum_of_primes(n): if n > 2: ...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_10/sol2.py
""" Problem Statement: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. """ import math from itertools import takewhile def primeCheck(number): if number % 2 == 0 and number > 2: return False return all(number % i for i in range(3, int(math.sqrt(...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_10/sol3.py
""" https://projecteuler.net/problem=10 Problem Statement: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million using Sieve_of_Eratosthenes: The sieve of Eratosthenes is one of the most efficient ways to find all primes smaller than n when n is smaller than 10 millio...
[ "int" ]
[ 374 ]
[ 377 ]
archives/1098994933_python.zip
project_euler/problem_11/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_11/sol1.py
""" What is the greatest product of four adjacent numbers (horizontally, vertically, or diagonally) in this 20x20 array? 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 52 70 95 23 04 60 ...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_11/sol2.py
""" What is the greatest product of four adjacent numbers (horizontally, vertically, or diagonally) in this 20x20 array? 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 52 70 95 23 04 60 ...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_12/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_12/sol1.py
""" Highly divisible triangular numbers Problem 12 The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_12/sol2.py
""" Highly divisible triangular numbers Problem 12 The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_13/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_13/sol1.py
""" Problem Statement: Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. """ def solution(array): """Returns the first ten digits of the sum of the array elements. >>> import os >>> sum = 0 >>> array = [] >>> with open(os.path.dirname(__file__) + "/num.txt","...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_14/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_14/sol1.py
# -*- coding: utf-8 -*- """ Problem Statement: The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) n → 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1 It can be seen ...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_14/sol2.py
# -*- coding: utf-8 -*- """ Collatz conjecture: start with any positive integer n. Next term obtained from the previous term as follows: If the previous term is even, the next term is one half the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture states the s...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_15/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_15/sol1.py
""" Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. How many such routes are there through a 20×20 grid? """ from math import factorial def lattice_paths(n): """ Returns the number of paths possible in a n...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_16/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_16/sol1.py
""" 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? """ def solution(power): """Returns the sum of the digits of the number 2^power. >>> solution(1000) 1366 >>> solution(50) 76 >>> solution(20) 31 >>> solution(15) ...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_16/sol2.py
""" 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? """ def solution(power): """Returns the sum of the digits of the number 2^power. >>> solution(1000) 1366 >>> solution(50) 76 >>> solution(20) 31 >>> solution(...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_17/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_17/sol1.py
""" Number letter counts Problem 17 If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? NOTE: Do not count space...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_19/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_19/sol1.py
""" Counting Sundays Problem 19 You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have thirty-one, Saving February alone, Which has twenty-eight, rain or shine. And on leap years, twe...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_20/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_20/sol1.py
""" n! means n × (n − 1) × ... × 3 × 2 × 1 For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. Find the sum of the digits in the number 100! """ def factorial(n): fact = 1 for i in range(1, n + 1): fact *= i return...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_20/sol2.py
""" n! means n × (n − 1) × ... × 3 × 2 × 1 For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. Find the sum of the digits in the number 100! """ from math import factorial def solution(n): """Returns the sum of the digits in the n...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_21/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_21/sol1.py
# -.- coding: latin-1 -.- from math import sqrt """ Amicable Numbers Problem 21 Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers. For exampl...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_22/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_22/sol1.py
# -*- coding: latin-1 -*- """ Name scores Problem 22 Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical positio...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_22/sol2.py
# -*- coding: latin-1 -*- """ Name scores Problem 22 Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical positio...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_234/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_234/sol1.py
""" https://projecteuler.net/problem=234 For an integer n ≥ 4, we define the lower prime square root of n, denoted by lps(n), as the largest prime ≤ √n and the upper prime square root of n, ups(n), as the smallest prime ≥ √n. So, for example, lps(4) = 2 = ups(4), lps(1000) = 31, ups(1000) = 37. Let us call an integer...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_24/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_24/sol1.py
""" A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are: 012 021 102 120 201 210...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_25/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_25/sol1.py
# -*- coding: utf-8 -*- """ The Fibonacci sequence is defined by the recurrence relation: Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. Hence the first 12 terms will be: F1 = 1 F2 = 1 F3 = 2 F4 = 3 F5 = 5 F6 = 8 F7 = 13 F8 = 21 F9 = 34 F10 = 55 F11 = 89 F12 = 144 The...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_25/sol2.py
# -*- coding: utf-8 -*- """ The Fibonacci sequence is defined by the recurrence relation: Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. Hence the first 12 terms will be: F1 = 1 F2 = 1 F3 = 2 F4 = 3 F5 = 5 F6 = 8 F7 = 13 F8 = 21 F9 = 34 F10 = 55 F11 = 89 F12 = 144 The...
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_28/__init__.py
[]
[]
[]
archives/1098994933_python.zip
project_euler/problem_28/sol1.py
""" Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 It can be verified that the sum of the numbers on the diagonals is 101. What is the sum of the numbers o...
[]
[]
[]