Ejemplo n.º 1
0
def showDiagram():
    profile.fire()
    xml = """<?xml version="1.0" encoding="utf-8" ?>
<table>
    <row>
        <table>
            <row>
                <cell>First</cell>
                <cell>Second</cell>
            </row>
        </table>
        <cell>Python</cell>
    </row>
    <row>
        <cell>Speed</cell>
        <cell>Slow</cell>
    </row>
</table>
    """
    arr = reader.newBytes(len(xml))
    for i in range(0, len(xml)):
        arr[i] = JByte(ord(xml[i]))
        print arr[i]
    print "OK"
    rgba = reader.toDiagram(arr)
    profile.check()
    length = len(rgba)
    b = bytearray(length)
    for i in range(0, length):
        b[i] = (rgba[i] & 0xff)
    image = Image.open(io.BytesIO(b))
    image.show()
Ejemplo n.º 2
0
def test():
    for i in range(12, 25):
        length = 2 << i
        arr = [complex(random.random(), 0) for __i__ in range(0, length)]
        profile.fire()
        iter_fft(arr)
        time = profile.check()
Ejemplo n.º 3
0
def test(n):
    bt = BTree()
    a = [__i__ for __i__ in range(0, n)]
    random.shuffle(a)
    c = 0

    profile.fire()
    for __i__ in a:
        bt.insert(__i__)
        #print '------------------------------------------------------------------------------------------'
        #print '%d: inserted %d' % (c, __i__)
        #bt.print_self()
        c += 1
    # bt.print_self()
    profile.check()
    return bt
Ejemplo n.º 4
0
def max_sub(array):
    max_sum = 0
    for i in range(0, len(array)):
        for j in range(i, len(array)):
            max_sum = max(max_sum, sum(array[i: j]))
    return max_sum


def max_sub_opt(array):
    max_sum = 0
    max_current = 0
    for i in array:
        max_current += i
        if max_current < 0:
            max_current = 0
        elif i > 0:
            max_sum = max(max_sum, max_current)
    return max_sum


if __name__ == '__main__':
    while True:
        length = raw_input('>>> ')
        arr = [random.randint(-1000, 1000) for i in range(0, int(length))]
        profile.fire()
        print max_sub_opt(arr)
        profile.check()
        profile.fire()
        print max_sub(arr)
        profile.check()
Ejemplo n.º 5
0
    return profit


def memoized_cut_rod(price_table, length):
    memo = [None] * (length + 1)
    for i in range(0, length + 1):
        memo[i] = -1
    return memoized_cut_rod_aux(price_table, length, memo)


def memoized_cut_rod_aux(price_table, length, memo):
    max_len = max(price_table.keys())
    if memo[length] >= 0:
        return memo[length]
    if length == 0:
        return 0
    profit = 0
    for sub in range(max(0, length - max_len), length):
        profit = max(profit, price_table[length - sub] + memoized_cut_rod_aux(price_table, sub, memo))
    memo[length] = profit
    return profit


myIO.new("steel_result")

for i in range(1, 13):
    i = 2 << i
    profile.fire()
    print memoized_cut_rod(price, i)
    myIO.write("{%s, %s},\n" % (i, profile.check()))