diff --git a/config.json b/config.json index 00d3c8a..0a0b244 100644 --- a/config.json +++ b/config.json @@ -90,6 +90,14 @@ "prerequisites": [], "difficulty": 2 }, + { + "slug": "gigasecond", + "name": "Gigasecond", + "uuid": "349cb8e8-06e8-486f-9e18-16172edfe205", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "hamming", "name": "Hamming", diff --git a/exercises/practice/gigasecond/.busted b/exercises/practice/gigasecond/.busted new file mode 100644 index 0000000..86b84e7 --- /dev/null +++ b/exercises/practice/gigasecond/.busted @@ -0,0 +1,5 @@ +return { + default = { + ROOT = { '.' } + } +} diff --git a/exercises/practice/gigasecond/.docs/instructions.md b/exercises/practice/gigasecond/.docs/instructions.md new file mode 100644 index 0000000..1e20f00 --- /dev/null +++ b/exercises/practice/gigasecond/.docs/instructions.md @@ -0,0 +1,8 @@ +# Instructions + +Your task is to determine the date and time one gigasecond after a certain date. + +A gigasecond is one thousand million seconds. +That is a one with nine zeros after it. + +If you were born on _January 24th, 2015 at 22:00 (10:00:00pm)_, then you would be a gigasecond old on _October 2nd, 2046 at 23:46:40 (11:46:40pm)_. diff --git a/exercises/practice/gigasecond/.docs/introduction.md b/exercises/practice/gigasecond/.docs/introduction.md new file mode 100644 index 0000000..18a3dc2 --- /dev/null +++ b/exercises/practice/gigasecond/.docs/introduction.md @@ -0,0 +1,24 @@ +# Introduction + +The way we measure time is kind of messy. +We have 60 seconds in a minute, and 60 minutes in an hour. +This comes from ancient Babylon, where they used 60 as the basis for their number system. +We have 24 hours in a day, 7 days in a week, and how many days in a month? +Well, for days in a month it depends not only on which month it is, but also on what type of calendar is used in the country you live in. + +What if, instead, we only use seconds to express time intervals? +Then we can use metric system prefixes for writing large numbers of seconds in more easily comprehensible quantities. + +- A food recipe might explain that you need to let the brownies cook in the oven for two kiloseconds (that's two thousand seconds). +- Perhaps you and your family would travel to somewhere exotic for two megaseconds (that's two million seconds). +- And if you and your spouse were married for _a thousand million_ seconds, you would celebrate your one gigasecond anniversary. + +~~~~exercism/note +If we ever colonize Mars or some other planet, measuring time is going to get even messier. +If someone says "year" do they mean a year on Earth or a year on Mars? + +The idea for this exercise came from the science fiction novel ["A Deepness in the Sky"][vinge-novel] by author Vernor Vinge. +In it the author uses the metric system as the basis for time measurements. + +[vinge-novel]: https://www.tor.com/2017/08/03/science-fiction-with-something-for-everyone-a-deepness-in-the-sky-by-vernor-vinge/ +~~~~ diff --git a/exercises/practice/gigasecond/.meta/config.json b/exercises/practice/gigasecond/.meta/config.json new file mode 100644 index 0000000..2d9fa94 --- /dev/null +++ b/exercises/practice/gigasecond/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "gigasecond.moon" + ], + "test": [ + "gigasecond_spec.moon" + ], + "example": [ + ".meta/example.moon" + ] + }, + "blurb": "Given a moment, determine the moment that would be after a gigasecond has passed.", + "source": "Chapter 9 in Chris Pine's online Learn to Program tutorial.", + "source_url": "https://pine.fm/LearnToProgram/chap_09.html" +} diff --git a/exercises/practice/gigasecond/.meta/example.moon b/exercises/practice/gigasecond/.meta/example.moon new file mode 100644 index 0000000..c44cf7d --- /dev/null +++ b/exercises/practice/gigasecond/.meta/example.moon @@ -0,0 +1,3 @@ +{ + add: (moment) -> moment + 10^9 +} diff --git a/exercises/practice/gigasecond/.meta/spec_generator.moon b/exercises/practice/gigasecond/.meta/spec_generator.moon new file mode 100644 index 0000000..9f25647 --- /dev/null +++ b/exercises/practice/gigasecond/.meta/spec_generator.moon @@ -0,0 +1,22 @@ +components = (moment) -> moment\match "(%d%d%d%d)%-(%d%d)%-(%d%d)T?(%d*):?(%d*):?(%d*)" +to_num = (str) -> str != '' and tonumber(str) or 0 + +{ + module_name: 'Gigasecond', + + generate_test: (case, level) -> + lines = {} + + year, month, day, hour, min, sec = unpack [to_num v for v in *{components case.input.moment}] + table.insert lines, "momentA = os.time {year: #{year}, month: #{month}, day: #{day}, hour: #{hour}, min: #{min}, sec: #{sec}}" + + e_year, e_month, e_day, e_hour, e_min, e_sec = unpack [to_num v for v in *{components case.expected}] + table.insert lines, "momentB = os.time {year: #{e_year}, month: #{e_month}, day: #{e_day}, hour: #{e_hour}, min: #{e_min}, sec: #{e_sec}}" + + table.insert lines, "result = os.date '!%x', Gigasecond.add momentA" + table.insert lines, "expected = os.date '!%x', momentB" + table.insert lines, "assert.are.equals expected, result" + + + table.concat [indent line, level for line in *lines], '\n' +} diff --git a/exercises/practice/gigasecond/.meta/tests.toml b/exercises/practice/gigasecond/.meta/tests.toml new file mode 100644 index 0000000..7f75cf5 --- /dev/null +++ b/exercises/practice/gigasecond/.meta/tests.toml @@ -0,0 +1,29 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[92fbe71c-ea52-4fac-bd77-be38023cacf7] +description = "date only specification of time" + +[6d86dd16-6f7a-47be-9e58-bb9fb2ae1433] +description = "second test for date only specification of time" + +[77eb8502-2bca-4d92-89d9-7b39ace28dd5] +description = "third test for date only specification of time" + +[c9d89a7d-06f8-4e28-a305-64f1b2abc693] +description = "full time specified" + +[09d4e30e-728a-4b52-9005-be44a58d9eba] +description = "full time with day roll-over" + +[fcec307c-7529-49ab-b0fe-20309197618a] +description = "does not mutate the input" +include = false diff --git a/exercises/practice/gigasecond/gigasecond.moon b/exercises/practice/gigasecond/gigasecond.moon new file mode 100644 index 0000000..ddf2936 --- /dev/null +++ b/exercises/practice/gigasecond/gigasecond.moon @@ -0,0 +1,4 @@ +{ + add: (moment) -> + error 'Implement me' +} diff --git a/exercises/practice/gigasecond/gigasecond_spec.moon b/exercises/practice/gigasecond/gigasecond_spec.moon new file mode 100644 index 0000000..a375d11 --- /dev/null +++ b/exercises/practice/gigasecond/gigasecond_spec.moon @@ -0,0 +1,37 @@ +Gigasecond = require 'gigasecond' + +describe 'gigasecond', -> + it 'date only specification of time', -> + momentA = os.time {year: 2011, month: 4, day: 25, hour: 0, min: 0, sec: 0} + momentB = os.time {year: 2043, month: 1, day: 1, hour: 1, min: 46, sec: 40} + result = os.date '!%x', Gigasecond.add momentA + expected = os.date '!%x', momentB + assert.are.equals expected, result + + pending 'second test for date only specification of time', -> + momentA = os.time {year: 1977, month: 6, day: 13, hour: 0, min: 0, sec: 0} + momentB = os.time {year: 2009, month: 2, day: 19, hour: 1, min: 46, sec: 40} + result = os.date '!%x', Gigasecond.add momentA + expected = os.date '!%x', momentB + assert.are.equals expected, result + + pending 'third test for date only specification of time', -> + momentA = os.time {year: 1959, month: 7, day: 19, hour: 0, min: 0, sec: 0} + momentB = os.time {year: 1991, month: 3, day: 27, hour: 1, min: 46, sec: 40} + result = os.date '!%x', Gigasecond.add momentA + expected = os.date '!%x', momentB + assert.are.equals expected, result + + pending 'full time specified', -> + momentA = os.time {year: 2015, month: 1, day: 24, hour: 22, min: 0, sec: 0} + momentB = os.time {year: 2046, month: 10, day: 2, hour: 23, min: 46, sec: 40} + result = os.date '!%x', Gigasecond.add momentA + expected = os.date '!%x', momentB + assert.are.equals expected, result + + pending 'full time with day roll-over', -> + momentA = os.time {year: 2015, month: 1, day: 24, hour: 23, min: 59, sec: 59} + momentB = os.time {year: 2046, month: 10, day: 3, hour: 1, min: 46, sec: 39} + result = os.date '!%x', Gigasecond.add momentA + expected = os.date '!%x', momentB + assert.are.equals expected, result