Solution: Apple sharing
Here is the solution to the problem.
my $N = 3; my $K = 11; my $gets = $K div $N; my $remains = $K % $N; say "Each person gets $gets apple(s)."; say "There are $remains apple(s) remaining.";
🦋 You can find the full code in the file apple-sharing.raku.
With the input numbers 3 and 11, the program prints the following output:
$ raku exercises/numbers/apple-sharing.raku Each person gets 3 apple(s). There are 2 apple(s) remaining.
Modify the initial value of
$K to model other situations:
$Kis multiple of
$N, for example,
$Kis equals to
$Kis less than
In the program, we are using the two operators:
div to perform integer division and
% for getting the remainder of the division. Alternatively, you can make the calculations in the following manner:
my $gets = $K div $N; my $remains = $K - $N * $gets;
Also note how the variables are interpolated in the string.