Пример #1
0
def isPal(number):
    number = str(number)
    num_len = len(number)
    num_half = len(number) / 2
    for x in range(0, num_half):
        if number[x] != number[num_len - x - 1]:
            return False

    helper.result('906609', number)
    sys.exit()
Пример #2
0
def factorize(target, primes, factor):
    multiplier = 2
    factored = True
    sieve = range(primes[len(primes)-1]+1, factor)
    for i in range(0, len(primes)):
        if target % primes[i] == 0:
            target = target / primes[i]
            print target
            if isPrime(target):
                helper.result(6857, target)
                sys.exit()
        if i == len(primes) - 1:
            factored = False
            factor = factor * multiplier
            primes = reducer(factor, sieve, primes, target)
            factorize(target, primes, factor)
        i += 1
Пример #3
0
def generate_ai_move(board):
    """Determine the optimal move for the AI to make and the send it"""
    if terminal(board):  # if the game is over, do nothing
        pass
    else:
        move = minimax(board)  # use minimax algorithm to generate optimal move
        res = result(board, move[0])
        emit("update", res)
Пример #4
0
def factorize(target, primes, factor):
    multiplier = 2
    factored = True
    sieve = range(primes[len(primes) - 1] + 1, factor)
    for i in range(0, len(primes)):
        if target % primes[i] == 0:
            target = target / primes[i]
            print target
            if isPrime(target):
                helper.result(6857, target)
                sys.exit()
        if i == len(primes) - 1:
            factored = False
            factor = factor * multiplier
            primes = reducer(factor, sieve, primes, target)
            factorize(target, primes, factor)
        i += 1
Пример #5
0
def backlog_delete(id):
    return result(Backlog().get(id))
Пример #6
0
def backlog_add():
    return result(Backlog().add(request.json))
Пример #7
0
def user_signout():
    print "LOGOUT"
    return result(User().signout())
Пример #8
0
def user_current():
    return result(User().current())
Пример #9
0
def user_delete(id):
    return result(User().delete(id))
Пример #10
0
def user_add():
    return result(User().add(request.json))
Пример #11
0
def error_permissions(error):
    return result(dict({"error": "Permissions error"})), 401
Пример #12
0
def issue_get(id):
    return result(Issue().get(id))
Пример #13
0
#!/usr/bin/python
from time import time
import helper
'''
Problem: Find the sum all all numbers that are multiples of 3
or 5 from 1 to 999

Solution: Sum all the multiples of 3, sum all the multiples
of 5, add them together, sum all the multiples of 15, and
subtract.
'''

def sumMultiplesOf(x):
	num = 0
	tot = 0

	while (num <= 999):
		if (num % x == 0):
			tot += num
		num += 1

	return tot

newTot = sumMultiplesOf(3) + sumMultiplesOf(5) - sumMultiplesOf(15)
helper.result(233168, newTot)
Пример #14
0
def make_move(json):
    """Send the state of the board after the desired move is made"""
    res = result(json["board"], tuple(json["move"]))
    emit("update", res)
Пример #15
0
#!/usr/bin/python
from time import time
import helper
'''
Problem: Find the sum all all numbers that are multiples of 3
or 5 from 1 to 999

Solution: Sum all the multiples of 3, sum all the multiples
of 5, add them together, sum all the multiples of 15, and
subtract.
'''


def sumMultiplesOf(x):
    num = 0
    tot = 0

    while (num <= 999):
        if (num % x == 0):
            tot += num
        num += 1

    return tot


newTot = sumMultiplesOf(3) + sumMultiplesOf(5) - sumMultiplesOf(15)
helper.result(233168, newTot)
Пример #16
0
def issue_add():
    return result(Issue().add(request.json))
Пример #17
0
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 four million, find the sum of the even-valued terms.

Solution: Check each fib number to see if it's even.  If so, add to
the sum.  Do this in a loop while fib is less than 4,000,000

Test: Fibs <= 40 are 1, 2, 3, 5, 8, 13, 21, 34
Evens are just 2, 8, 34
So the sum would be 2 + 8 + 34 = 44
'''
total = 2
maxnum = 4000000


def getFib(x, y, maxnum, total):
    fib = x + y
    if fib <= maxnum:
        if fib % 2 == 0:
            total += fib
        fib = getFib(y, fib, maxnum, total)

        return fib
    else:
        return total


fib = getFib(1, 2, maxnum, total)

helper.result(4613732, fib)
Пример #18
0
def issue_edit(id):
    return result(Issue().edit(id, request.json))
Пример #19
0
def user_get(id):
    return result(User().get(id))
Пример #20
0
def issue_delete(id):
    return result(Issue().delete(id))
Пример #21
0
def user_edit(id):
    return result(User().edit(id, request.json))
Пример #22
0
def issue_all():
    return result(Issue().all(request.args))
Пример #23
0
def user_all():
    return result(User().all(request.args))
Пример #24
0
def subissue_get(id):
    return result(Subissue().get(id))
Пример #25
0
def user_signin():
    return result(User().signin(request.form))
Пример #26
0
def subissue_add():
    return result(Subissue().add(request.json))
Пример #27
0
def backlog_get(id):
    return result(Backlog().get(id))
Пример #28
0
def subissue_edit(id):
    return result(Subissue().edit(id, request.json))
Пример #29
0
def backlog_edit(id):
    return result(Backlog().edit(id, request.json))
Пример #30
0
def subissue_delete(id):
    return result(Subissue().delete(id))
Пример #31
0
def backlog_all():
    return result(Backlog().all(request.args))
Пример #32
0
def subissue_all():
    return result(Subissue().all(request.args))
Пример #33
0
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 four million, find the sum of the even-valued terms.

Solution: Check each fib number to see if it's even.  If so, add to
the sum.  Do this in a loop while fib is less than 4,000,000

Test: Fibs <= 40 are 1, 2, 3, 5, 8, 13, 21, 34
Evens are just 2, 8, 34
So the sum would be 2 + 8 + 34 = 44
'''
total    = 2
maxnum   = 4000000

def getFib(x, y, maxnum, total):
	fib = x + y
	if fib <= maxnum:
		if fib % 2 == 0:
			total += fib
		fib = getFib(y, fib, maxnum, total)

		return fib
	else:
		return total

fib = getFib(1, 2, maxnum, total)

helper.result(4613732, fib)
Пример #34
0
#!/usr/bin/python
import helper
'''
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?
'''

number = 2**1000
result = 0

while (number > 0):
    result = result + number % 10
    number = number / 10

helper.result(1366, result)