exercism / cairo

Exercism exercises in Cairo.
https://exercism.org/tracks/cairo
MIT License
6 stars 10 forks source link

Add Practice Exercise: `space-age` #235

Closed 0xNeshi closed 1 month ago

0xNeshi commented 2 months ago

Problem specification: https://github.com/exercism/problem-specifications/tree/main/exercises/space-age

TODO:

Even though this exercise requires the use of floating point numbers (which are not supported by Cairo), we should implement it in a way that works without them. This is usually achieved by the use of "basis points" - in short, the decimal part of the float number is represented by additional decimals being added to the Cairo integer, enabling calculations. Basically all numbers are multiplied by some multiple of the number 10, converting the float number into a regular (but expanded) integer. So 10.34 becomes 10.34 * 100 = 1034.

BNAndras commented 1 month ago

This one involves floating point math so I was on the fence about proposing it earlier. If the solution uses multiplication to avoid using floats at any point, that might work. However, that approach feels a bit convoluted for what generally is an easier exercise. Just because we can do it doesn't necessarily mean it's a great fit for the track. On the other hand, it can highlight some potential limitations with Cairo and how to work around them so there's some use there. We'll definitely want to provide an instructions-append highlighting the situation going into the exercise.

0xNeshi commented 1 month ago

On the other hand, it can highlight some potential limitations with Cairo and how to work around them so there's some use there.

Exactly this :point_up: Given that one of the main current uses for Cairo is for smart contract development, where there is a need to handle decimals without the use of floating point numbers, I think this would be a great exercise to teach students how do exactly this.

We'll definitely want to provide an instructions-append highlighting the situation going into the exercise.

Agreed.

Updating the description.

0xNeshi commented 1 month ago

@BNAndras I created a PR #290 for this without checking whether the issue was assigned, apologies. Will reassign to myself for clarity

BNAndras commented 1 month ago

No worries