Mercurial > repos > tabletprog
comparison samples/iterfib.tp @ 46:55572bb15623
Added iterative fib example
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 13 Jul 2012 00:25:07 -0700 |
parents | |
children | 3a169ebb3224 |
comparison
equal
deleted
inserted
replaced
45:2a9c6eed0c70 | 46:55572bb15623 |
---|---|
1 #{ | |
2 true <- #{ | |
3 if:else <- :self trueblock :elseblock { | |
4 trueblock: | |
5 } | |
6 } | |
7 | |
8 false <- #{ | |
9 if:else <- :self trueblock :elseblock { | |
10 elseblock: | |
11 } | |
12 } | |
13 | |
14 fib <- :n { | |
15 last <- 0 | |
16 cur <- 1 | |
17 counter <- 0 | |
18 while: { counter < n } do: { | |
19 counter <- counter + 1 | |
20 tmp <- last | |
21 last <- cur | |
22 cur <- last + tmp | |
23 } | |
24 cur | |
25 } | |
26 | |
27 main <- { | |
28 print: (string: (fib: 30)) . "\n" | |
29 } | |
30 | |
31 } |