root/examples/vmethods/math.pl

Revision 11293, 1.0 kB (checked in by Darren_Duncan, 3 years ago)

replaced all 'use v6;' lines with 'use v6-alpha;' in 330 files (examples/, ext/, t/, t_disabled/) ... more remain to do

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1# Please remember to update examples/output/vmethods/math if you change this
2# file so its output will change.
3#
4
5use v6-alpha;
6
7multi sub is_even (Int $value) {
8    $value % 2 == 1;
9}
10
11multi sub is_odd (Int $value) {
12    $value % 2 == 0;
13}
14
15multi sub is_factor_of (Int $self; Int $num) {
16    $num % $self == 0;
17}
18
19multi sub is_divisible_by (Int $self; Int $num) {
20    $self % $num == 0;
21}
22
23multi sub is_prime(Int $value) {
24    ?none(2..sqrt($value)).is_factor_of($value);
25}
26
27say "5 is " ~ (5.is_even ?? 'even' !! 'odd');
28say "8 is " ~ (8.is_odd  ?? 'odd' !! 'even');
29say "2 is" ~ (2.is_factor_of(10) ?? ' ' !! ' not ') ~ "factor of 10";
30say "3 is" ~ (3.is_factor_of(10) ?? ' ' !! ' not ') ~ "factor of 10";
31say "10 is" ~ (10.is_divisible_by(2) ?? ' ' !! ' not ') ~ "divisible by 2";
32say "10 is" ~ (10.is_divisible_by(3) ?? ' ' !! ' not ') ~ "divisible by 3";
33say "7 is" ~ (7.is_prime ?? ' '!!' not ') ~ "a prime number";
34say "9 is" ~ (9.is_prime ?? ' '!!' not ') ~ "a prime number";
Note: See TracBrowser for help on using the browser.