annotate paper/codes/fib.nqp @ 122:a3ff00c33fd7 default tip

update slide
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 20 Feb 2019 12:05:38 +0900
parents 96e9cf9c2ea2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #! nqp
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 sub fib($n) {
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 $n < 2 ?? $n !! fib($n-1) + fib($n - 2);
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 }
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 my $N := 29;
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 my $t0 := nqp::time_n();
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 my $z := fib($N);
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 my $t1 := nqp::time_n();
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 say("fib($N) = " ~ fib($N));
96e9cf9c2ea2 add source files
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 say("time = " ~ ($t1-$t0));