(naïve) Factorial Function in Cairo

Here is what I came up with.

# Use the output builtin.
%builtins output

# Import the serialize_word() function.
from starkware.cairo.common.serialize import serialize_word

# Naive factorial.

func factorial(n) -> (result):
    if n == 1:
        return (n)
    let (a) = factorial(n-1)
    return (n*a)

func main{output_ptr: felt*}():
    let (y) = factorial(10)
    return ()
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s