/
ch-1.raku
68 lines (45 loc) · 1.03 KB
/
ch-1.raku
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /usr/bin/env raku
# Perl Weekly Challenge
# © 2023 Shimon Bollinger. All rights reserved.
# Last modified: Mon 15 May 2023 09:17:32 PM EDT
# Version 0.0.1
=begin pod
=TITLE
=head2 Task 1: Three Power
=SUBTITLE
=head2 Submitted by massa
=CHALLENGE
=head2
You are given a positive integer, $n.
Write a script to return true if the given integer is a power of three
otherwise return false.
=head3 Example 1:
Input: $n = 27
Output: true
27 = 3 ^ 3
=head3 Example 2:
Input: $n = 0
Output: true
0 = 0 ^ 3
=head3 Example 3:
Input: $n = 6
Output: false
=SOLUTION
=end pod
# always use the latest version of Raku
use v6.*;
sub SOLUTION($n) {
(^∞).map(3 ** *).first(* >= $n) == $n
}
multi MAIN (Bool :$test!) {
use Testo;
my @tests =
%{ input => 27,
output => True },
%{ input => 0,
output => False },
%{ input => 6,
output => False },
;
.<input>.&SOLUTION.&is-eqv: .<output>, .<text> for @tests
} # end of multi MAIN (Bool :$test!)