Created
June 11, 2022 12:17
-
-
Save Th0rgal/96123800ec23eaf794e3992ee75ed4a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func reverse{syscall_ptr : felt*, range_check_ptr, pedersen_ptr : HashBuiltin*}( | |
arr_len : felt, arr : felt* | |
) -> (rev_arr_len : felt, rev_arr : felt*): | |
# if our array is empty (i.e. we reached the end of our recursion) | |
if arr_len == 0: | |
let (rev_arr) = alloc() | |
return (0, rev_arr) | |
end | |
# otherwise, we reverse the rest of our array | |
let (rev_rest_len, rev_rest) = reverse(arr_len-1, arr+1) | |
# and then we append the current element (the first of our array) | |
# at the end of the reversed array | |
assert rev_rest[rev_rest_len] = [arr] | |
return (rev_rest_len+1, rev_rest) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment