rejetto forum

Software => HFS ~ HTTP File Server => HTML & templates => Topic started by: rejetto on April 02, 2008, 04:02:23 AM

Title: Fibonacci with macros
Post by: rejetto on April 02, 2008, 04:02:23 AM
This is for those interested in programming with template macros.

I made this for fun, to test the capabilities of this shitty language. :)

Fibonacci is a function of numbers http://en.wikipedia.org/wiki/Fibonacci_number

And this is how to get it with macros

Code: [Select]
{.set|fib|{:
    {.if|{.$1 <= 1.}
        | $1
        | {: {.add| {.^fib|{.sub|$1|1.}.} | {.^fib|{.sub|$1|2.}.} /add.} :}
    /if.}
:}.}

to make a test, you can try {.^fib|10.}

I tried even with 20, it takes forever, but the result is correct.

Extra note: this recursive way is highly inefficient.
Title: Re: Fibonacci with macros
Post by: Mars on April 02, 2008, 10:53:13 PM
In when macro for the square matrices of order N? ;D ;D