2017年4月1日土曜日

開発環境

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)の Boolean functions の Exercise.を取り組んでみる。

Boolean functions の Exercise.

コード(Emacs)

#!/usr/bin/env perl6
# -*- coding: utf-8 -*-

sub is-between($x, $y, $z) {
    $x <= $y <= $z
}

for 1..5 -> $x {
    for 1..5 -> $y {
        for 1..5 -> $z {
            say "$x <= $y <= $z: ", is-between($x, $y, $z);
        }
    }
}

入出力結果(Terminal, REPL)

$ ./sample_between.pl
1 <= 1 <= 1: True
1 <= 1 <= 2: True
1 <= 1 <= 3: True
1 <= 1 <= 4: True
1 <= 1 <= 5: True
1 <= 2 <= 1: False
1 <= 2 <= 2: True
1 <= 2 <= 3: True
1 <= 2 <= 4: True
1 <= 2 <= 5: True
1 <= 3 <= 1: False
1 <= 3 <= 2: False
1 <= 3 <= 3: True
1 <= 3 <= 4: True
1 <= 3 <= 5: True
1 <= 4 <= 1: False
1 <= 4 <= 2: False
1 <= 4 <= 3: False
1 <= 4 <= 4: True
1 <= 4 <= 5: True
1 <= 5 <= 1: False
1 <= 5 <= 2: False
1 <= 5 <= 3: False
1 <= 5 <= 4: False
1 <= 5 <= 5: True
2 <= 1 <= 1: False
2 <= 1 <= 2: False
2 <= 1 <= 3: False
2 <= 1 <= 4: False
2 <= 1 <= 5: False
2 <= 2 <= 1: False
2 <= 2 <= 2: True
2 <= 2 <= 3: True
2 <= 2 <= 4: True
2 <= 2 <= 5: True
2 <= 3 <= 1: False
2 <= 3 <= 2: False
2 <= 3 <= 3: True
2 <= 3 <= 4: True
2 <= 3 <= 5: True
2 <= 4 <= 1: False
2 <= 4 <= 2: False
2 <= 4 <= 3: False
2 <= 4 <= 4: True
2 <= 4 <= 5: True
2 <= 5 <= 1: False
2 <= 5 <= 2: False
2 <= 5 <= 3: False
2 <= 5 <= 4: False
2 <= 5 <= 5: True
3 <= 1 <= 1: False
3 <= 1 <= 2: False
3 <= 1 <= 3: False
3 <= 1 <= 4: False
3 <= 1 <= 5: False
3 <= 2 <= 1: False
3 <= 2 <= 2: False
3 <= 2 <= 3: False
3 <= 2 <= 4: False
3 <= 2 <= 5: False
3 <= 3 <= 1: False
3 <= 3 <= 2: False
3 <= 3 <= 3: True
3 <= 3 <= 4: True
3 <= 3 <= 5: True
3 <= 4 <= 1: False
3 <= 4 <= 2: False
3 <= 4 <= 3: False
3 <= 4 <= 4: True
3 <= 4 <= 5: True
3 <= 5 <= 1: False
3 <= 5 <= 2: False
3 <= 5 <= 3: False
3 <= 5 <= 4: False
3 <= 5 <= 5: True
4 <= 1 <= 1: False
4 <= 1 <= 2: False
4 <= 1 <= 3: False
4 <= 1 <= 4: False
4 <= 1 <= 5: False
4 <= 2 <= 1: False
4 <= 2 <= 2: False
4 <= 2 <= 3: False
4 <= 2 <= 4: False
4 <= 2 <= 5: False
4 <= 3 <= 1: False
4 <= 3 <= 2: False
4 <= 3 <= 3: False
4 <= 3 <= 4: False
4 <= 3 <= 5: False
4 <= 4 <= 1: False
4 <= 4 <= 2: False
4 <= 4 <= 3: False
4 <= 4 <= 4: True
4 <= 4 <= 5: True
4 <= 5 <= 1: False
4 <= 5 <= 2: False
4 <= 5 <= 3: False
4 <= 5 <= 4: False
4 <= 5 <= 5: True
5 <= 1 <= 1: False
5 <= 1 <= 2: False
5 <= 1 <= 3: False
5 <= 1 <= 4: False
5 <= 1 <= 5: False
5 <= 2 <= 1: False
5 <= 2 <= 2: False
5 <= 2 <= 3: False
5 <= 2 <= 4: False
5 <= 2 <= 5: False
5 <= 3 <= 1: False
5 <= 3 <= 2: False
5 <= 3 <= 3: False
5 <= 3 <= 4: False
5 <= 3 <= 5: False
5 <= 4 <= 1: False
5 <= 4 <= 2: False
5 <= 4 <= 3: False
5 <= 4 <= 4: False
5 <= 4 <= 5: False
5 <= 5 <= 1: False
5 <= 5 <= 2: False
5 <= 5 <= 3: False
5 <= 5 <= 4: False
5 <= 5 <= 5: True
$

0 コメント:

コメントを投稿