🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of yangyanzhan

yangyanzhan's solution

to Space Age in the Raku Track

Published at Oct 24 2019 · 0 comments
Test suite


This exercise has changed since this solution was written.

Given an age in seconds, calculate how old someone would be on:

  • Earth: orbital period 365.25 Earth days, or 31557600 seconds
  • Mercury: orbital period 0.2408467 Earth years
  • Venus: orbital period 0.61519726 Earth years
  • Mars: orbital period 1.8808158 Earth years
  • Jupiter: orbital period 11.862615 Earth years
  • Saturn: orbital period 29.447498 Earth years
  • Uranus: orbital period 84.016846 Earth years
  • Neptune: orbital period 164.79132 Earth years

So if you were told someone were 1,000,000,000 seconds old, you should be able to say that they're 31.69 Earth-years old.

If you're wondering why Pluto didn't make the cut, go watch this youtube video.


Remember to check out the Perl 6 documentation and resources pages for information, tips, and examples if you get stuck.

Running the tests

There is a test suite and module included with the exercise. The test suite (a file with the extension .t6) will attempt to run routines from the module (a file with the extension .pm6). Add/modify routines in the module so that the tests will pass! You can view the test data by executing the command perl6 --doc *.t6 (* being the name of the test suite), and run the test suite for the exercise by executing the command prove6 . in the exercise directory.


Partially inspired by Chapter 1 in Chris Pine's online Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=01

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

unit module SpaceAge;

role Planet {
  method age-on($seconds) {
      ($seconds / $.orbital-period).round(0.01);

class Earth does Planet is export {
  my $.orbital-period = 31557600;

class Mercury does Planet is export {
  my $.orbital-period = 31557600 * 0.2408467;

class Venus does Planet is export {
  my $.orbital-period = 31557600 * 0.61519726;

class Mars does Planet is export {
  my $.orbital-period = 31557600 * 1.8808158;

class Jupiter does Planet is export {
  my $.orbital-period = 31557600 * 11.862615;

class Saturn does Planet is export {
  my $.orbital-period = 31557600 * 29.447498;

class Uranus does Planet is export {
  my $.orbital-period = 31557600 * 84.016846;

class Neptune does Planet is export {
  my $.orbital-period = 31557600 * 164.79132;

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?