Collate-conjecture exercise

Would it be ok to submit a PR to update the exercise to use tables like most of the other exercises. So

local Collatz = {}
function Collatz.collatz(n)
end
return Collatz

instead of

return function(n)
end

And how would you change the spec file to match it?

By my count, there are 37 exercises that simply return function(...)

As far as the spec file I would just follow suit with the others, or attempt to. I guess my thought process was too standardize but that my not be appropriate. I am new to Lua so not really sure if either way is more idiomatic?

I can’t really speak to what is idiomatic, but if you want to structure the code a bit more cleanly, you could always write something like

local collatz = function(n)
  -- implementation
end

return collatz

If you want to write a recursive solution, you’ll need to do this to give the function a name.

I’m in favour of leaving it as is. It forces the student to read the spec file to see exactly how their solution is being used what is required from their solution.

1 Like