開発環境
- 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-5.を取り組んでみる。
Exercise 5-5.
コード(Emacs)
#!/usr/bin/env perl6 # -*- coding: utf-8 -*- sub gcd($a, $b) { return $a if $b == 0; gcd($b, $a % $b); } for 1..10 -> $a { for 1..10 -> $b { say "gcd($a, $b) = ", gcd($a, $b); } }
入出力結果(Terminal, REPL)
$ ./sample5.pl gcd(1, 1) = 1 gcd(1, 2) = 1 gcd(1, 3) = 1 gcd(1, 4) = 1 gcd(1, 5) = 1 gcd(1, 6) = 1 gcd(1, 7) = 1 gcd(1, 8) = 1 gcd(1, 9) = 1 gcd(1, 10) = 1 gcd(2, 1) = 1 gcd(2, 2) = 2 gcd(2, 3) = 1 gcd(2, 4) = 2 gcd(2, 5) = 1 gcd(2, 6) = 2 gcd(2, 7) = 1 gcd(2, 8) = 2 gcd(2, 9) = 1 gcd(2, 10) = 2 gcd(3, 1) = 1 gcd(3, 2) = 1 gcd(3, 3) = 3 gcd(3, 4) = 1 gcd(3, 5) = 1 gcd(3, 6) = 3 gcd(3, 7) = 1 gcd(3, 8) = 1 gcd(3, 9) = 3 gcd(3, 10) = 1 gcd(4, 1) = 1 gcd(4, 2) = 2 gcd(4, 3) = 1 gcd(4, 4) = 4 gcd(4, 5) = 1 gcd(4, 6) = 2 gcd(4, 7) = 1 gcd(4, 8) = 4 gcd(4, 9) = 1 gcd(4, 10) = 2 gcd(5, 1) = 1 gcd(5, 2) = 1 gcd(5, 3) = 1 gcd(5, 4) = 1 gcd(5, 5) = 5 gcd(5, 6) = 1 gcd(5, 7) = 1 gcd(5, 8) = 1 gcd(5, 9) = 1 gcd(5, 10) = 5 gcd(6, 1) = 1 gcd(6, 2) = 2 gcd(6, 3) = 3 gcd(6, 4) = 2 gcd(6, 5) = 1 gcd(6, 6) = 6 gcd(6, 7) = 1 gcd(6, 8) = 2 gcd(6, 9) = 3 gcd(6, 10) = 2 gcd(7, 1) = 1 gcd(7, 2) = 1 gcd(7, 3) = 1 gcd(7, 4) = 1 gcd(7, 5) = 1 gcd(7, 6) = 1 gcd(7, 7) = 7 gcd(7, 8) = 1 gcd(7, 9) = 1 gcd(7, 10) = 1 gcd(8, 1) = 1 gcd(8, 2) = 2 gcd(8, 3) = 1 gcd(8, 4) = 4 gcd(8, 5) = 1 gcd(8, 6) = 2 gcd(8, 7) = 1 gcd(8, 8) = 8 gcd(8, 9) = 1 gcd(8, 10) = 2 gcd(9, 1) = 1 gcd(9, 2) = 1 gcd(9, 3) = 3 gcd(9, 4) = 1 gcd(9, 5) = 1 gcd(9, 6) = 3 gcd(9, 7) = 1 gcd(9, 8) = 1 gcd(9, 9) = 9 gcd(9, 10) = 1 gcd(10, 1) = 1 gcd(10, 2) = 2 gcd(10, 3) = 1 gcd(10, 4) = 2 gcd(10, 5) = 5 gcd(10, 6) = 2 gcd(10, 7) = 1 gcd(10, 8) = 2 gcd(10, 9) = 1 gcd(10, 10) = 10 $
0 コメント:
コメントを投稿