開発環境
- 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 4(Conditionals and recursion)のExercises 4-2-1、2.を取り組んでみる。
Exercises 4-2-1、2.
コード(Emacs)
#!/usr/bin/env perl6 # -*- coding: utf-8 -*- say '4-2'; say '1.'; sub check-fermat($a, $b, $c, $n) { if ($a ** $n + $b ** $n == $c ** $n and $n > 2) { say 'Holy smokes, Fermat was wrong!' } else { say "No, that doesn't work."; } } for 1..10 { my $a = 100 * rand.round + 1; my $b = 100 * rand.round + 1; my $c = 100 * rand.round + 1; for 3..10 -> $n { say "$a ** $n + $b ** $n = $c ** $n"; check-fermat($a, $b, $c, $_); } } say '2.'; sub check-fermat1 { my $a = get.Int; my $b = get.Int; my $c = get.Int; my $n = get.Int; check-fermat($a, $b, $c, $n); } check-fermat1;
入出力結果(Terminal, REPL)
$ ./sample2.pl < sample2.txt 4-2 1. 1 ** 3 + 1 ** 3 = 1 ** 3 No, that doesn't work. 1 ** 4 + 1 ** 4 = 1 ** 4 No, that doesn't work. 1 ** 5 + 1 ** 5 = 1 ** 5 No, that doesn't work. 1 ** 6 + 1 ** 6 = 1 ** 6 No, that doesn't work. 1 ** 7 + 1 ** 7 = 1 ** 7 No, that doesn't work. 1 ** 8 + 1 ** 8 = 1 ** 8 No, that doesn't work. 1 ** 9 + 1 ** 9 = 1 ** 9 No, that doesn't work. 1 ** 10 + 1 ** 10 = 1 ** 10 No, that doesn't work. 101 ** 3 + 1 ** 3 = 101 ** 3 No, that doesn't work. 101 ** 4 + 1 ** 4 = 101 ** 4 No, that doesn't work. 101 ** 5 + 1 ** 5 = 101 ** 5 No, that doesn't work. 101 ** 6 + 1 ** 6 = 101 ** 6 No, that doesn't work. 101 ** 7 + 1 ** 7 = 101 ** 7 No, that doesn't work. 101 ** 8 + 1 ** 8 = 101 ** 8 No, that doesn't work. 101 ** 9 + 1 ** 9 = 101 ** 9 No, that doesn't work. 101 ** 10 + 1 ** 10 = 101 ** 10 No, that doesn't work. 101 ** 3 + 1 ** 3 = 101 ** 3 No, that doesn't work. 101 ** 4 + 1 ** 4 = 101 ** 4 No, that doesn't work. 101 ** 5 + 1 ** 5 = 101 ** 5 No, that doesn't work. 101 ** 6 + 1 ** 6 = 101 ** 6 No, that doesn't work. 101 ** 7 + 1 ** 7 = 101 ** 7 No, that doesn't work. 101 ** 8 + 1 ** 8 = 101 ** 8 No, that doesn't work. 101 ** 9 + 1 ** 9 = 101 ** 9 No, that doesn't work. 101 ** 10 + 1 ** 10 = 101 ** 10 No, that doesn't work. 1 ** 3 + 1 ** 3 = 1 ** 3 No, that doesn't work. 1 ** 4 + 1 ** 4 = 1 ** 4 No, that doesn't work. 1 ** 5 + 1 ** 5 = 1 ** 5 No, that doesn't work. 1 ** 6 + 1 ** 6 = 1 ** 6 No, that doesn't work. 1 ** 7 + 1 ** 7 = 1 ** 7 No, that doesn't work. 1 ** 8 + 1 ** 8 = 1 ** 8 No, that doesn't work. 1 ** 9 + 1 ** 9 = 1 ** 9 No, that doesn't work. 1 ** 10 + 1 ** 10 = 1 ** 10 No, that doesn't work. 101 ** 3 + 1 ** 3 = 1 ** 3 No, that doesn't work. 101 ** 4 + 1 ** 4 = 1 ** 4 No, that doesn't work. 101 ** 5 + 1 ** 5 = 1 ** 5 No, that doesn't work. 101 ** 6 + 1 ** 6 = 1 ** 6 No, that doesn't work. 101 ** 7 + 1 ** 7 = 1 ** 7 No, that doesn't work. 101 ** 8 + 1 ** 8 = 1 ** 8 No, that doesn't work. 101 ** 9 + 1 ** 9 = 1 ** 9 No, that doesn't work. 101 ** 10 + 1 ** 10 = 1 ** 10 No, that doesn't work. 1 ** 3 + 1 ** 3 = 101 ** 3 No, that doesn't work. 1 ** 4 + 1 ** 4 = 101 ** 4 No, that doesn't work. 1 ** 5 + 1 ** 5 = 101 ** 5 No, that doesn't work. 1 ** 6 + 1 ** 6 = 101 ** 6 No, that doesn't work. 1 ** 7 + 1 ** 7 = 101 ** 7 No, that doesn't work. 1 ** 8 + 1 ** 8 = 101 ** 8 No, that doesn't work. 1 ** 9 + 1 ** 9 = 101 ** 9 No, that doesn't work. 1 ** 10 + 1 ** 10 = 101 ** 10 No, that doesn't work. 101 ** 3 + 101 ** 3 = 101 ** 3 No, that doesn't work. 101 ** 4 + 101 ** 4 = 101 ** 4 No, that doesn't work. 101 ** 5 + 101 ** 5 = 101 ** 5 No, that doesn't work. 101 ** 6 + 101 ** 6 = 101 ** 6 No, that doesn't work. 101 ** 7 + 101 ** 7 = 101 ** 7 No, that doesn't work. 101 ** 8 + 101 ** 8 = 101 ** 8 No, that doesn't work. 101 ** 9 + 101 ** 9 = 101 ** 9 No, that doesn't work. 101 ** 10 + 101 ** 10 = 101 ** 10 No, that doesn't work. 1 ** 3 + 101 ** 3 = 101 ** 3 No, that doesn't work. 1 ** 4 + 101 ** 4 = 101 ** 4 No, that doesn't work. 1 ** 5 + 101 ** 5 = 101 ** 5 No, that doesn't work. 1 ** 6 + 101 ** 6 = 101 ** 6 No, that doesn't work. 1 ** 7 + 101 ** 7 = 101 ** 7 No, that doesn't work. 1 ** 8 + 101 ** 8 = 101 ** 8 No, that doesn't work. 1 ** 9 + 101 ** 9 = 101 ** 9 No, that doesn't work. 1 ** 10 + 101 ** 10 = 101 ** 10 No, that doesn't work. 101 ** 3 + 1 ** 3 = 101 ** 3 No, that doesn't work. 101 ** 4 + 1 ** 4 = 101 ** 4 No, that doesn't work. 101 ** 5 + 1 ** 5 = 101 ** 5 No, that doesn't work. 101 ** 6 + 1 ** 6 = 101 ** 6 No, that doesn't work. 101 ** 7 + 1 ** 7 = 101 ** 7 No, that doesn't work. 101 ** 8 + 1 ** 8 = 101 ** 8 No, that doesn't work. 101 ** 9 + 1 ** 9 = 101 ** 9 No, that doesn't work. 101 ** 10 + 1 ** 10 = 101 ** 10 No, that doesn't work. 1 ** 3 + 101 ** 3 = 1 ** 3 No, that doesn't work. 1 ** 4 + 101 ** 4 = 1 ** 4 No, that doesn't work. 1 ** 5 + 101 ** 5 = 1 ** 5 No, that doesn't work. 1 ** 6 + 101 ** 6 = 1 ** 6 No, that doesn't work. 1 ** 7 + 101 ** 7 = 1 ** 7 No, that doesn't work. 1 ** 8 + 101 ** 8 = 1 ** 8 No, that doesn't work. 1 ** 9 + 101 ** 9 = 1 ** 9 No, that doesn't work. 1 ** 10 + 101 ** 10 = 1 ** 10 No, that doesn't work. 2. No, that doesn't work. $ cat sample2.txt 1 2 3 4 $
0 コメント:
コメントを投稿