keep-starknet-strange / shenlong

Shenlong is a blazingly fast ⚡ tool to generate LLVM IR from Cairo, written in Rust 🦀
https://keep-starknet-strange.github.io/shenlong
MIT License
66 stars 5 forks source link

Fibonacci array #5

Open 0xLucqs opened 1 year ago

0xLucqs commented 1 year ago

Description

Compile a sierra fib implementation that uses an array into an llvm IR file

fn fib(n: u128) -> (Array::<felt>, felt, u128) {
    let mut arr = array_new::<felt>();
    array_append::<felt>(arr, 1);
    array_append::<felt>(arr, 1);
    let mut arr = fib_inner(n, arr);
    let len = array_len::<felt>(arr);
    let last = unchecked_array_at(arr, len - 1_u128);
    return (arr, last, len);
}

fn fib_inner(n: u128, mut arr: Array::<felt>) -> Array::<felt> {
    let length = array_len::<felt>(arr);
    if n <= length {
        return arr;
    }
    array_append::<felt>(
        arr, unchecked_array_at(arr, length - 1_u128) + unchecked_array_at(arr, length - 2_u128)
    );
    fib_inner(n, arr)
}

Acceptance criteria

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a 👍 Because this issue is marked as stale, it will be closed and locked in 7 days if no further activity occurs. Thank you for your contributions!