A => leap/README.md +40 -0
@@ 0,0 1,40 @@
+# Leap
+
+Given a year, report if it is a leap year.
+
+The tricky thing here is that a leap year in the Gregorian calendar occurs:
+
+```text
+on every year that is evenly divisible by 4
+ except every year that is evenly divisible by 100
+ unless the year is also evenly divisible by 400
+```
+
+For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap
+year, but 2000 is.
+
+## Notes
+
+Though our exercise adopts some very simple rules, there is more to
+learn!
+
+For a delightful, four minute explanation of the whole leap year
+phenomenon, go watch [this youtube video][video].
+
+[video]: http://www.youtube.com/watch?v=xX96xng7sAE
+
+## Running the tests
+
+To run the tests, run the command `busted` from within the exercise directory.
+
+## Further information
+
+For more detailed information about the Lua track, including how to get help if
+you're having trouble, please visit the exercism.io [Lua language page](http://exercism.io/tracks/lua/about).
+
+## Source
+
+JavaRanch Cattle Drive, exercise 3 [http://www.javaranch.com/leap.jsp](http://www.javaranch.com/leap.jsp)
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
A => leap/leap.lua +3 -0
@@ 0,0 1,3 @@
+return function(year)
+ return year % 4 == 0 and year % 100 ~= 0 or year % 400 == 0
+end
A => leap/leap_spec.lua +19 -0
@@ 0,0 1,19 @@
+local is_leap_year = require('leap')
+
+describe('leap', function()
+ it('a known leap year', function()
+ assert.is_true(is_leap_year(1996))
+ end)
+
+ it('any old year', function()
+ assert.is_false(is_leap_year(1997))
+ end)
+
+ it('turn of the 20th century', function()
+ assert.is_false(is_leap_year(1900))
+ end)
+
+ it('turn of the 21st century', function()
+ assert.is_true(is_leap_year(2400))
+ end)
+end)
A => robot-name/README.md +32 -0
@@ 0,0 1,32 @@
+# Robot Name
+
+Manage robot factory settings.
+
+When robots come off the factory floor, they have no name.
+
+The first time you boot them up, a random name is generated in the format
+of two uppercase letters followed by three digits, such as RX837 or BC811.
+
+Every once in a while we need to reset a robot to its factory settings,
+which means that their name gets wiped. The next time you ask, it will
+respond with a new random name.
+
+The names must be random: they should not follow a predictable sequence.
+Random names means a risk of collisions. Your solution must ensure that
+every existing robot has a unique name.
+
+## Running the tests
+
+To run the tests, run the command `busted` from within the exercise directory.
+
+## Further information
+
+For more detailed information about the Lua track, including how to get help if
+you're having trouble, please visit the exercism.io [Lua language page](http://exercism.io/tracks/lua/about).
+
+## Source
+
+A debugging session with Paul Blackwell at gSchool. [http://gschool.it](http://gschool.it)
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
A => robot-name/robot-name.lua +28 -0
@@ 0,0 1,28 @@
+local Robot = {}
+local genNames = {}
+
+local function generate_name()
+ local name = ""
+ for _=1,2 do
+ name = name .. string.char(math.random(65,90))
+ end
+ name = name .. string.format('%03d', math.random(0,999))
+ if genNames[name] then
+ return generate_name()
+ end
+ genNames[name] = true
+ return name
+end
+
+local function reset(self)
+ self.name = generate_name()
+end
+
+function Robot:new()
+ return {
+ name = generate_name(),
+ reset = reset
+ }
+end
+
+return Robot
A => robot-name/robot-name_spec.lua +27 -0
@@ 0,0 1,27 @@
+local Robot = require('robot-name')
+
+describe('robot-name', function()
+ it('has a name', function()
+ local robot = Robot:new()
+ -- lua does not support fixed patterns like %w{2}%d{3}
+ assert.are.equal(string.match(robot.name, '^%a%a%d%d%d$'), robot.name)
+ end)
+
+ it('name is the same each time', function()
+ local robot = Robot:new()
+ assert.are.equal(robot.name, robot.name)
+ end)
+
+ it('different robots have different names', function()
+ local robotOne = Robot:new()
+ local robotTwo = Robot:new()
+ assert.are_not.equal(robotOne.name, robotTwo.name)
+ end)
+
+ it('is able to reset the name', function()
+ local robot = Robot:new()
+ local originalName = robot.name
+ robot:reset()
+ assert.are_not.equal(originalName, robot.name)
+ end)
+end)