# [48in24 Exercise] [06-04] Space Age

This issue is a discussion for contributors to collaborate in getting ready to be featured in 48in24. Please refer to this forum topic for more info.

We will be featuring Space Age from Jun 04 onwards.

### Staff jobs

These are things for Erik/Jeremy to do:

• ☐ Check/update exercise in Problem Specifications
• ☐ Create + schedule video

### Community jobs

For each track:

• Implement Space Age
• Add approaches (and an approaches introduction!) for each idiomatic or interesting/educational approach.
• Add video walkthroughs (record yourself solving and digging deeper into the exercise).
• Highlight up to 16 different featured exercises (coming soon)

### Existing Approaches

You can use these as the basis for approaches on your own tracks. Feel free to copy/paste/reuse/rewrite/etc as you see fit! Maybe ask ChatGPT to translate to your programming language.

• `applydynamic` (scala)
• `array-index` (c)
• `currying` (scala)
• `partial-application` (scala)

### Track Statuses

You can see an overview of which tracks have implemented the exercise at the #48in24 implementation status page.

I’ve currently gathered the following solutions to feature:

1. Python: define planet methods in terms of pre-calculated earth age
Define the age on the planet methods using age of earth value

2. Clojure: define non-earth planet functions using age on earth function
Define the age on the non-earth planet functions using age on earth function

3. Julia: define dictionary with orbital period per planet
Define the orbital period per planet in a dictionary

4. F#: discriminated union and pattern matching to get orbital period in earth years
Convert seconds to earth years divide by planet to orbital period in earth years via pattern matching

5. Nim: planets enum with values being year in seconds
Precalculate seconds in years as enum value

6. Prolog: define relations
Define orbital period for each planet as a relation

7. Pharo: define class for each planet
Define a class for each planet

8. Ruby: run time metaprogramming using lookup table
Use a lookup table with metaprogramming to dynamically define the methods

9. Rust: compile time metaprogramming via macros
Define the functions for each planet at compile time

10. MIPS: using reciprocals to not use division
Multiply by reciprocals to not use division but only multiplication

If anyone has more suggestions, do let us know!

I rather like this one (and ones similar) that create the methods in a dynamic fashion. It’s less readable, but more fun for those who don’t like boilerplate.

yawpitche’s solution is also quite nice - he uses `@classmethod` as opposed to `setattr`.

1 Like

I enjoyed these “metaprogramming using lookup table”:
https://exercism.org/tracks/clojure/exercises/space-age/solutions/rwstauner
https://exercism.org/tracks/tcl/exercises/space-age/solutions/jmbaselec

Particularly the Tcl one: it handles “not a planet” using Tcl’s “command not found” mechanism.

2 Likes

Came here with a similar dynamic approach in Common Lisp.

2 Likes