2017年4月5日水曜日

開発環境

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 5-3.を取り組んでみる。

Exercise 5-3.

コード(Emacs)

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

sub is-power-of($a, $b) {
    return True if $a == 1;
    return False if $b == 1;
    return True if $a == $b;
    $a %% $b and is-power-of($a / $b, $b);
}

for 1..100 {
    say "is-power-of($_, 2): ", is-power-of($_, 2);
}

入出力結果(Terminal, REPL)

$ ./sample3.pl
is-power-of(1, 2): True
is-power-of(2, 2): True
is-power-of(3, 2): False
is-power-of(4, 2): True
is-power-of(5, 2): False
is-power-of(6, 2): False
is-power-of(7, 2): False
is-power-of(8, 2): True
is-power-of(9, 2): False
is-power-of(10, 2): False
is-power-of(11, 2): False
is-power-of(12, 2): False
is-power-of(13, 2): False
is-power-of(14, 2): False
is-power-of(15, 2): False
is-power-of(16, 2): True
is-power-of(17, 2): False
is-power-of(18, 2): False
is-power-of(19, 2): False
is-power-of(20, 2): False
is-power-of(21, 2): False
is-power-of(22, 2): False
is-power-of(23, 2): False
is-power-of(24, 2): False
is-power-of(25, 2): False
is-power-of(26, 2): False
is-power-of(27, 2): False
is-power-of(28, 2): False
is-power-of(29, 2): False
is-power-of(30, 2): False
is-power-of(31, 2): False
is-power-of(32, 2): True
is-power-of(33, 2): False
is-power-of(34, 2): False
is-power-of(35, 2): False
is-power-of(36, 2): False
is-power-of(37, 2): False
is-power-of(38, 2): False
is-power-of(39, 2): False
is-power-of(40, 2): False
is-power-of(41, 2): False
is-power-of(42, 2): False
is-power-of(43, 2): False
is-power-of(44, 2): False
is-power-of(45, 2): False
is-power-of(46, 2): False
is-power-of(47, 2): False
is-power-of(48, 2): False
is-power-of(49, 2): False
is-power-of(50, 2): False
is-power-of(51, 2): False
is-power-of(52, 2): False
is-power-of(53, 2): False
is-power-of(54, 2): False
is-power-of(55, 2): False
is-power-of(56, 2): False
is-power-of(57, 2): False
is-power-of(58, 2): False
is-power-of(59, 2): False
is-power-of(60, 2): False
is-power-of(61, 2): False
is-power-of(62, 2): False
is-power-of(63, 2): False
is-power-of(64, 2): True
is-power-of(65, 2): False
is-power-of(66, 2): False
is-power-of(67, 2): False
is-power-of(68, 2): False
is-power-of(69, 2): False
is-power-of(70, 2): False
is-power-of(71, 2): False
is-power-of(72, 2): False
is-power-of(73, 2): False
is-power-of(74, 2): False
is-power-of(75, 2): False
is-power-of(76, 2): False
is-power-of(77, 2): False
is-power-of(78, 2): False
is-power-of(79, 2): False
is-power-of(80, 2): False
is-power-of(81, 2): False
is-power-of(82, 2): False
is-power-of(83, 2): False
is-power-of(84, 2): False
is-power-of(85, 2): False
is-power-of(86, 2): False
is-power-of(87, 2): False
is-power-of(88, 2): False
is-power-of(89, 2): False
is-power-of(90, 2): False
is-power-of(91, 2): False
is-power-of(92, 2): False
is-power-of(93, 2): False
is-power-of(94, 2): False
is-power-of(95, 2): False
is-power-of(96, 2): False
is-power-of(97, 2): False
is-power-of(98, 2): False
is-power-of(99, 2): False
is-power-of(100, 2): False
$

0 コメント:

コメントを投稿