Course of Raku / Essentials / Associative data types / Exercises

Travel distance*

Problem

Create a program that finds the total distance of the trip that is defined by the following array:

my @itinerary = < Berlin Prague Vienna Zurich Paris >;

Print the distance of each segment of the itinerary and the total distance.

Use the file distances.raku with the hash of hashes that lists the distances between the cities.

Example

For the given list of cities, the output of the program looks like this:

$ raku travel-distance.raku
Berlin — Prague: 354 km
Prague — Vienna: 312 km
Vienna — Zurich: 784 km
Zurich — Paris: 557 km
Total trip: 2007 km

Solution

See the solution

Course navigation

Positional data types / Subscripting ranges   |   Creating and calling functions