示例#1
0
def add_str(a: pygg.Value, b: pygg.Value) -> pygg.Output:
    ap = a.path()
    bp = b.path()
    assert ap is not None
    assert bp is not None
    sub.check_call([gg.bin("add_str").path(), ap, bp])
    return gg.file_value("out")
示例#2
0
def add_str(a: pygg.Value, b: pygg.Value) -> pygg.Output:
    ai = int(a.as_str())
    bi = int(b.as_str())
    path = 'random'
    with open(path, 'w') as f:
        f.write(str(ai + bi))
    return gg.file_value(path)
示例#3
0
def merge(a: pygg.Value, b: pygg.Value) -> pygg.Value:
    al = [int(l.strip()) for l in open(a.path(), 'r').readlines()]
    bl = [int(l.strip()) for l in open(b.path(), 'r').readlines()]
    ai = 0
    bi = 0
    with open('c', 'w') as f:
        while ai < len(al) and bi < len(bl):
            if al[ai] < bl[bi]:
                f.writelines([str(al[ai]), "\n"])
                ai += 1
            else:
                f.writelines([str(bl[bi]), "\n"])
                bi += 1
        f.writelines(str(x) + "\n" for x in al[ai:])
        f.writelines(str(x) + "\n" for x in bl[bi:])
    return gg.file_value('c')
示例#4
0
def fib_(n: pygg.Value) -> pygg.Output:
    i = int(n.as_str())
    if i < 2:
        return gg.str_value(str(i))
    else:
        s = gg.thunk(split, n)
        a = gg.thunk(fib_, s)
        b = gg.thunk(fib_, s["n2"])
        return gg.thunk(add_str, a, b)
示例#5
0
def sort(a: pygg.Value) -> pygg.Output:
    al = open(a.path(), 'r').readlines()
    if len(al) < 2:
        with open("out", "w") as f:
            f.writelines(al)
        return gg.file_value("out")
    else:
        with open("1", "w") as f:
            f.writelines(al[:len(al) // 2])
        with open("2", "w") as f:
            f.writelines(al[len(al) // 2:])
        return gg.thunk(merge, gg.thunk(sort, gg.file_value("1")),
                        gg.thunk(sort, gg.file_value("2")))
示例#6
0
def add_str(a: pygg.Value, b: pygg.Value) -> pygg.Output:
    ai = int(a.as_str())
    bi = int(b.as_str())
    return gg.str_value(str(ai + bi))
示例#7
0
def split(n: pygg.Value) -> pygg.OutputDict:
    i = int(n.as_str())
    return {
        "n1": gg.str_value(str(i - 1)),
        "n2": gg.str_value(str(i - 2)),
    }
示例#8
0
def inc(n: pygg.Value) -> pygg.Value:
    i = int(n.as_str())
    return gg.str_value(str(i + 1))