開発環境
- 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 8(Case study: word play)の Exercises 8-2.を取り組んでみる。
Exercises 8-2.
コード(Emacs)
#!/usr/bin/env perl6
# -*- coding: utf-8 -*-
sub has-no-e($word) {
$word.index('e') === Nil;
}
my $total = 0;
my $has-no-e-words = 0;
for 'words.txt'.IO.lines {
$total += 1;
if has-no-e($_) {
$has-no-e-words += 1;
}
}
say $has-no-e-words / $total * 100, '%';
入出力結果(Terminal, REPL)
$ ./sample2.pl 33.0738342% $
0 コメント:
コメントを投稿