開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Perl 6 (プログラミング言語)
- Rakudo(コンパイラ、実装)
Think Perl 6: How to Think Like a Computer Scientist (Laurent Rosenfeld(著)、Allen B. Downey(著)、Oreilly & Associates Inc)のPart 1(Starting with the basics)、Chapter 5(Fruitful subroutines)の Exercise 5-2.を取り組んでみる。
Exercise 5-2.
コード(Emacs)
#!/usr/bin/env perl6
# -*- coding: utf-8 -*-
sub ack($m, $n) {
return $n + 1 if $m == 0;
return ack($m - 1, 1) if $m > 0 and $n == 0;
return ack($m - 1, ack($m, $n - 1));
}
say ack(3, 4);
say ack(3, 4) == 125;
入出力結果(Terminal, REPL)
$ ./sample5_2.pl 125 True $
0 コメント:
コメントを投稿