ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

# TkachukPavel's solution

## to Space Age in the Clojure Track

Published at Jan 17 2021 · 0 comments
Instructions
Test suite
Solution

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.

## Source

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.

### space_age_test.clj

``````(ns space-age-test
(:require [clojure.test :refer [deftest is]]
space-age))

(defn- rounds-to
[expected actual]
(is (= (Math/round (* 100.0 expected))
(Math/round (* 100.0 actual)))))

(deftest age-in-earth-years
(rounds-to 31.69 (space-age/on-earth 1000000000)))

(deftest age-in-mercury-years
(let [seconds 2134835688]
(rounds-to 67.65 (space-age/on-earth seconds))
(rounds-to 280.88 (space-age/on-mercury seconds))))

(deftest age-in-venus-years
(let [seconds 189839836]
(rounds-to 6.02 (space-age/on-earth seconds))
(rounds-to 9.78 (space-age/on-venus seconds))))

(deftest age-on-mars
(let [seconds 2329871239]
(rounds-to 73.83 (space-age/on-earth seconds))
(rounds-to 39.25 (space-age/on-mars seconds))))

(deftest age-on-jupiter
(let [seconds 901876382]
(rounds-to 28.58 (space-age/on-earth seconds))
(rounds-to 2.41 (space-age/on-jupiter seconds))))

(deftest age-on-saturn
(let [seconds 3000000000]
(rounds-to 95.06 (space-age/on-earth seconds))
(rounds-to 3.23 (space-age/on-saturn seconds))))

(deftest age-on-uranus
(let [seconds 3210123456]
(rounds-to 101.72 (space-age/on-earth seconds))
(rounds-to 1.21 (space-age/on-uranus seconds))))

(deftest age-on-neptune
(let [seconds 8210123456]
(rounds-to 260.16 (space-age/on-earth seconds))
(rounds-to 1.58 (space-age/on-neptune seconds))))``````
``````(ns space-age)

(def second->year-earth  31557600.0)
(def earth->mercury-year-rat 0.2408467)
(def earth->venus-year-rat 0.61519726)
(def earth->mars-year-rat 1.8808158)
(def earth->jupiter-year-rat 11.862615)
(def earth->saturn-year-rat 29.447498)
(def earth->uranus-year-rat 84.016846)
(def earth->neptune-year-rat 164.79132)

(defn on-mercury [age-sec] ;; <- arglist goes here
(/ age-sec second->year-earth earth->mercury-year-rat))

(defn on-venus [age-sec] ;; <- arglist goes here
(/ age-sec second->year-earth earth->venus-year-rat))

(defn on-earth [age-sec] ;; <- arglist goes here
(/ age-sec second->year-earth))

(defn on-mars [age-sec] ;; <- arglist goes here
(/ age-sec second->year-earth earth->mars-year-rat))

(defn on-jupiter [age-sec] ;; <- arglist goes here
(/ age-sec second->year-earth earth->jupiter-year-rat))

(defn on-saturn [age-sec] ;; <- arglist goes here
(/ age-sec second->year-earth earth->saturn-year-rat))

(defn on-neptune [age-sec] ;; <- arglist goes here
(/ age-sec second->year-earth earth->neptune-year-rat))

(defn on-uranus [age-sec] ;; <- arglist goes here
(/ age-sec second->year-earth earth->uranus-year-rat))``````

### 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?