-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
return { | ||
default = { | ||
ROOT = { '.' } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"authors": [ | ||
"aarti" | ||
], | ||
"contributors": [ | ||
"etandel", | ||
"kytrinyx", | ||
"ryanplusplus" | ||
], | ||
"files": { | ||
"solution": [ | ||
"space-age.lua" | ||
], | ||
"test": [ | ||
"space-age_spec.lua" | ||
], | ||
"example": [ | ||
".meta/example.lua" | ||
] | ||
}, | ||
"blurb": "Given an age in seconds, calculate how old someone is in terms of a given planet's solar years.", | ||
"source": "Partially inspired by Chapter 1 in Chris Pine's online Learn to Program tutorial.", | ||
"source_url": "https://pine.fm/LearnToProgram/?Chapter=01" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"track":"lua","exercise":"space-age","id":"f36b747a9a3a4cda932c2b3576e0d5ef","url":"https://exercism.org/tracks/lua/exercises/space-age","handle":"vpayno","is_requester":true,"auto_approve":false} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Help | ||
|
||
## Running the tests | ||
|
||
To run the tests, run the command `busted` from within the exercise directory. | ||
|
||
Refer to the [Installing Lua locally][install] documentation to get Lua and busted installed correctly. | ||
|
||
[install]: https://exercism.org/docs/tracks/lua/installation | ||
|
||
## Submitting your solution | ||
|
||
You can submit your solution using the `exercism submit space-age.lua` command. | ||
This command will upload your solution to the Exercism website and print the solution page's URL. | ||
|
||
It's possible to submit an incomplete solution which allows you to: | ||
|
||
- See how others have completed the exercise | ||
- Request help from a mentor | ||
|
||
## Need to get help? | ||
|
||
If you'd like help solving the exercise, check the following pages: | ||
|
||
- The [Lua track's documentation](https://exercism.org/docs/tracks/lua) | ||
- The [Lua track's programming category on the forum](https://forum.exercism.org/c/programming/lua) | ||
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) | ||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) | ||
|
||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. | ||
|
||
There are many great free online resources for Lua including: | ||
|
||
1. [lua.org][8] | ||
2. A highly recommended detailed and authoritative introduction to all aspects of Lua programming by Lua's chief architect: [Programming in Lua, by Roberto Ierusalimschy][6]. Note that the first edition (covering Lua 5.0) is [freely available online][9]. | ||
3. For an official definition of the Lua language, consult the [Lua 5.4 Reference Manual][7], by R. Ierusalimschy, L. H. de Figueiredo, W. Celes. | ||
4. [Lua Style Guide][4] | ||
5. [Learn Lua in 15 minutes][5] | ||
6. Some options for linting | ||
- [Lua Lint][10] | ||
- [Lua Inspect][11] | ||
- [luacheck][12] | ||
- [Detecting Undefined Variables][13] | ||
|
||
[4]: https://github.com/Olivine-Labs/lua-style-guide | ||
[5]: http://tylerneylon.com/a/learn-lua/ | ||
[6]: http://www.lua.org/pil/ | ||
[7]: http://www.lua.org/manual/5.4/ | ||
[8]: http://www.lua.org | ||
[9]: http://www.lua.org/pil/contents.html | ||
[10]: http://lua-users.org/wiki/LuaLint | ||
[11]: http://lua-users.org/wiki/LuaInspect | ||
[12]: https://github.com/luarocks/luacheck | ||
[13]: http://lua-users.org/wiki/DetectingUndefinedVariables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Space Age | ||
|
||
Welcome to Space Age on Exercism's Lua Track. | ||
If you need help running the tests or submitting your code, check out `HELP.md`. | ||
|
||
## Instructions | ||
|
||
Given an age in seconds, calculate how old someone would be on: | ||
|
||
- Mercury: orbital period 0.2408467 Earth years | ||
- Venus: orbital period 0.61519726 Earth years | ||
- Earth: orbital period 1.0 Earth years, 365.25 Earth days, or 31557600 seconds | ||
- 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][pluto-video]. | ||
|
||
Note: The actual length of one complete orbit of the Earth around the sun is closer to 365.256 days (1 sidereal year). | ||
The Gregorian calendar has, on average, 365.2425 days. | ||
While not entirely accurate, 365.25 is the value used in this exercise. | ||
See [Year on Wikipedia][year] for more ways to measure a year. | ||
|
||
[pluto-video]: https://www.youtube.com/watch?v=Z_2gbGXzFbs | ||
[year]: https://en.wikipedia.org/wiki/Year#Summary | ||
|
||
## Source | ||
|
||
### Created by | ||
|
||
- @aarti | ||
|
||
### Contributed to by | ||
|
||
- @etandel | ||
- @kytrinyx | ||
- @ryanplusplus | ||
|
||
### Based on | ||
|
||
Partially inspired by Chapter 1 in Chris Pine's online Learn to Program tutorial. - https://pine.fm/LearnToProgram/?Chapter=01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
local SpaceAge = {} | ||
|
||
return SpaceAge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
local SpaceAge = require('space-age') | ||
|
||
describe('space-age', function() | ||
it('age in seconds', function() | ||
local age = SpaceAge:new(1000000) | ||
assert.are.equal(1000000, age.seconds) | ||
end) | ||
|
||
it('age in Earth years', function() | ||
local age = SpaceAge:new(1000000000) | ||
assert.are.equal(31.69, age.on_earth()) | ||
end) | ||
|
||
it('age in Mercury years', function() | ||
local age = SpaceAge:new(2134835688) | ||
assert.are.equal(67.65, age.on_earth()) | ||
assert.are.equal(280.88, age.on_mercury()) | ||
end) | ||
|
||
it('age in Venus years', function() | ||
local age = SpaceAge:new(189839836) | ||
assert.are.equal(6.02, age.on_earth()) | ||
assert.are.equal(9.78, age.on_venus()) | ||
end) | ||
|
||
it('age in Mars years', function() | ||
local age = SpaceAge:new(2329871239) | ||
assert.are.equal(73.83, age.on_earth()) | ||
assert.are.equal(39.25, age.on_mars()) | ||
end) | ||
|
||
it('age in Jupiter years', function() | ||
local age = SpaceAge:new(901876382) | ||
assert.are.equal(28.58, age.on_earth()) | ||
assert.are.equal(2.41, age.on_jupiter()) | ||
end) | ||
|
||
it('age in Saturn years', function() | ||
local age = SpaceAge:new(3000000000) | ||
assert.are.equal(95.06, age.on_earth()) | ||
assert.are.equal(3.23, age.on_saturn()) | ||
end) | ||
|
||
it('age in Uranus years', function() | ||
local age = SpaceAge:new(3210123456) | ||
assert.are.equal(101.72, age.on_earth()) | ||
assert.are.equal(1.21, age.on_uranus()) | ||
end) | ||
|
||
it('age in Neptune year', function() | ||
local age = SpaceAge:new(8210123456) | ||
assert.are.equal(260.16, age.on_earth()) | ||
assert.are.equal(1.58, age.on_neptune()) | ||
end) | ||
end) |