Course of Raku / Essentials / Numbers / Exercises

Apple sharing

Problem

N people evenly distribute K apples among them. Create a program that answers the following questions:

  • How many apples every single person gets?
  • How many apples remain in the basket?

The input numbers N and K should be hardcoded and assigned to the variables, for example:

my $N = 3;
my $K = 11;

# Your code here . . .

Consider the apples atomic, so you cannot cut them into pieces.

Example

With the numbers given above, we expect the program to print the following:

$ raku apple-sharing.raku
Each person gets 3 apple(s).
There are 2 apple(s) remaining.

At this point, ignore putting the nouns in the correct form and do not take into account a potentially awkward output when the remaining number is zero.

Solution

See the solution

Next exercise

💪 Sum of numbers

Course navigation

Strings / String length   |   Boolean type