Skip to content

Instantly share code, notes, and snippets.

@amoshyc
amoshyc / DS_project6.md
Last active November 4, 2015 02:46
DS Project 6: BST

題目

In this project you need to use Binary Search Tree. Input Data is a text file containing a keyword in a line, prefixed by an operator

+ for insertion - for deletion

For example:

@amoshyc
amoshyc / DS_project7.md
Created January 8, 2015 16:10
DS Project 7: Basic Graph Operations

題目

In this project you need to implement some basic graph operations. Suppose program name is graph and distance.txt is a text file. After the "distance.txt" has been read in the memory and the data structure built, the program will enter interactive mode by prompting > to let user enter commands. The program should print > for prompting after the execution of each command. Input Data: a text file containing two locations and distance between two locations in a line. For example:

Taipei Ilan 4
@amoshyc
amoshyc / DS_project8.md
Created January 27, 2015 07:37
DS Project 8: Term Counting (Using hash table)

題目

In this project, you need to write a tool named “tcount” that will count the occurrences of terms in a given file. You will use hashing data structure to implement the tool.

The test data contains a dictionary file and a text file. For each term in the dictionary, count the occurrence number in the text file.

For example suppose the dictionary file contains:

apple pie
@amoshyc
amoshyc / project_euler_0001.md
Last active August 29, 2015 14:14
Project Euler #1
所求
= sum([x for x in range(1, 1000) if x % 3 is 0 or x % 5 is 0])
= 3 的倍數和 + 5 的倍數和 - 15 的倍數和
= (3+6+...+999) + (5+10+...+995) - (15+30+...+990)
= ((3 + 999) * 333 / 2) + ((5 + 995) * 199 / 2) - ((15 + 990) * 66 / 2)
= 233168
@amoshyc
amoshyc / project_euler_0002.md
Last active August 29, 2015 14:14
Project Euler #2
def fib():
    f0 = 1
    f1 = 2

    yield f0
    yield f1

    f = f0 + f1
 while f <= 4000000:
@amoshyc
amoshyc / project_euler_0003.md
Last active August 29, 2015 14:14
Project Euler #3
from math import sqrt

def is_prime(N, primes):
    for p in primes:
        if p*p > N:
            break
        if N % p is 0:
            return False
@amoshyc
amoshyc / project_euler_0004.md
Created February 7, 2015 13:33
Project Euler #4
def is_plaindrome(N):
    temp = N
    rev = 0
    while N is not 0:
        digit = N % 10
        rev = rev * 10 + digit
        N = N // 10

 return temp == rev
@amoshyc
amoshyc / project_euler_0005.md
Created February 7, 2015 13:40
Project Euler #5
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return max(a, b) // gcd(a, b) * min(a, b)

ans = 1
@amoshyc
amoshyc / project_euler_0006.md
Created February 7, 2015 13:44
Project Euler #6
a = 100*101*201 // 6
b = ((1 + 100) * 100 // 2) ** 2
print(b - a)
@amoshyc
amoshyc / project_euler_0007.md
Created February 7, 2015 13:55
Project Euler #7
def is_prime(N, primes):
    for p in primes:
        if p * p > N:
            return True
        if N % p is 0:
            return False
    return True

primes = [2, 3, 5, 7]