def euclid(x, y): a = ScratchVar(TealType.uint64) b = ScratchVar(TealType.uint64) tmp = ScratchVar(TealType.uint64) start = If(x < y, Seq(a.store(y), b.store(x)), Seq(a.store(x), b.store(y))) cond = b.load() > Int(0) step = Seq(tmp.store(b.load()), b.store(Mod(a.load(), b.load())), a.store(tmp.load())) return Seq(For(start, cond, step).Do(Seq()), a.load())
def root_closeness(A, B, C, X): left = ScratchVar(TealType.uint64) right = ScratchVar(TealType.uint64) return Seq( left.store(A * X * X + C), right.store(B * X), If(left.load() < right.load()).Then(right.load() - left.load()).Else(left.load() - right.load()), )
def calculate_prize(closeness): return (If(closeness + Int(1) < Int(20)).Then( ONE_ALGO * (Int(10) - (closeness + Int(1)) / Int(2))).Else(Int(0)))
def euclid(x, y): return (If(x < y).Then(euclid(y, x)).Else( If(y == Int(0)).Then(x).Else(euclid(y, Mod(x, y)))))
def itoa(i: TealType.uint64): return If( i == Int(0), Bytes("0"), Concat(If(i / Int(10) > Int(0), itoa(i / Int(10)), Bytes("")), int_to_ascii(i % Int(10))))
def atoi(a: TealType.bytes): return If( Len(a) > Int(0), (ascii_to_int(head(a)) * ilog10(Len(a) - Int(1))) + atoi(Substring(a, Int(1), Len(a))), Int(0))
def ILLEGAL_recursion(i: ScratchVar): return (If(i.load() == Int(0)).Then(i.store( Int(1))).ElseIf(i.load() == Int(1)).Then(i.store(Int(0))).Else( Seq(i.store(i.load() - Int(2)), ILLEGAL_recursion(i))))
def recursiveIsEven(i): return (If(i == Int(0)).Then(Int(1)).ElseIf(i == Int(1)).Then( Int(0)).Else(recursiveIsEven(i - Int(2))))