rejetto forum

Fibonacci with macros

0 Members and 1 Guest are viewing this topic.

Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13523
    • View Profile
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.
« Last Edit: April 02, 2008, 04:04:31 AM by rejetto »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2068
    • View Profile
In when macro for the square matrices of order N? ;D ;D