開発環境
- 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 7(Strings)の Looping and counting の Exercise.を取り組んでみる。
Looping and counting の Exercise.
コード(Emacs)
#!/usr/bin/env perl6
# -*- coding: utf-8 -*-
sub count($word, $letter) {
my $count = 0;
for $word.comb {
$count++ if $_ eq $letter;
}
$count;
}
say count('banana', 'a');
入出力結果(Terminal, REPL)
$ ./sample_count.pl 3 $
0 コメント:
コメントを投稿